Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.emfxe.test
- import com.bmfn.extensions.scaleUp
- import com.emfxe.model.position.ProfitAndInvested
- import com.emfxe.utils.*
- import org.junit.Test
- import org.junit.Assert
- import java.math.BigDecimal
- class FormulasTests {
- //check maxQTY with cross = 1
- @Test
- fun checkMaxQTYWithIntegerPriceAndIntegerBalanceCrossEqualsOne(){
- Assert.assertEquals(26.toBigDecimal(), (maxQTY(1000.toBigDecimal(), BigDecimal.ONE, 38.toBigDecimal())))
- }
- @Test
- fun checkMaxQTYWithFloatPriceAndIntegerBalanceCrossEqualsOne(){
- Assert.assertEquals(4.toBigDecimal(), (maxQTY(1127.toBigDecimal(), BigDecimal.ONE, 257.365.toBigDecimal())))
- }
- @Test
- fun checkMaxQTYWithFloatBalanceAndFloatPriceCrossEqualsOne(){
- Assert.assertEquals(3.toBigDecimal(), (maxQTY(5803.48.toBigDecimal(), BigDecimal.ONE, 1568.965.toBigDecimal())))
- }
- @Test
- fun checkMaxQTYWithFloatBalanceAndFIntPriceCrossEqualsOne(){
- Assert.assertEquals(796.toBigDecimal(), (maxQTY(51803.48.toBigDecimal(), BigDecimal.ONE, 65.toBigDecimal())))
- }
- //check maxQTY with float cross
- @Test
- fun checkMaxQTYWithIntegerPriceAndIntegerBalanceFloatCross(){
- Assert.assertEquals(45.toBigDecimal(), (maxQTY(1722.toBigDecimal(), 0.9874.toBigDecimal(), 38.toBigDecimal())))
- }
- @Test
- fun checkMaxQTYWithFloatPriceAndIntegerBalanceFloatCross(){
- Assert.assertEquals(6590.toBigDecimal(), (maxQTY(99999.toBigDecimal(), 0.05896.toBigDecimal(), 257.365.toBigDecimal())))
- }
- @Test
- fun checkMaxQTYWithIntegerPriceAndFloatBalanceFloatCross(){
- Assert.assertEquals(399.toBigDecimal(), (maxQTY(7895.36.toBigDecimal(), 1.97525.toBigDecimal(), 10.toBigDecimal())))
- }
- @Test
- fun checkMaxQTYWithFloatPriceAndFloatBalanceFloatCross(){
- Assert.assertEquals(76.toBigDecimal(), (maxQTY(81965.32.toBigDecimal(), 18.6515.toBigDecimal(), 57.36518.toBigDecimal())))
- }
- //check max qty when balance < price
- @Test
- fun checkMaxQTYBalanceLessPriceCrossEqualsOne(){
- Assert.assertEquals(0.toBigDecimal(), (maxQTY(785.toBigDecimal(), BigDecimal.ONE, 1256.toBigDecimal())))
- }
- @Test
- fun checkMaxQtyBalanceLessPriceCrossLessOne(){
- Assert.assertEquals(46.toBigDecimal(), (maxQTY(946.toBigDecimal(), 0.00256.toBigDecimal(), 7895.63.toBigDecimal())))
- }
- @Test
- fun checkMaxQTYBalanceLessPriceCrossMOreThanOne(){
- Assert.assertEquals(0.toBigDecimal(), (maxQTY(1256.toBigDecimal(), 45.23.toBigDecimal(), 11756.toBigDecimal())))
- }
- //check min qty
- @Test
- fun checkMinQTYWithMinAmountEqualsZero(){
- Assert.assertEquals(BigDecimal.ONE, (minQTY(BigDecimal.ZERO, 45.23.toBigDecimal())))
- }
- @Test
- fun checkMinQTYWithMinAmountEqualsOne(){
- Assert.assertEquals(BigDecimal.ONE, (minQTY(BigDecimal.ONE, 1.2356.toBigDecimal())))
- }
- @Test
- fun checkMinQTYWitnMinAmountIntAndIntPrice(){
- Assert.assertEquals(31.toBigDecimal(), (minQTY(17896.toBigDecimal(), 596.toBigDecimal())))
- }
- @Test
- fun checkMinQTYWithIntMinAmountAndFloatPrice(){
- Assert.assertEquals(34.toBigDecimal(), (minQTY(1896.toBigDecimal(), 56.25698.toBigDecimal())))
- }
- @Test
- fun checkMinQTYWithFloatMinAmountAndIntPrice(){
- Assert.assertEquals(723.toBigDecimal(), (minQTY(56321.89.toBigDecimal(), 78.toBigDecimal())))
- }
- @Test
- fun checkMinQTYWithFloatMinAmountAndFloatPrice(){
- Assert.assertEquals(2691.toBigDecimal(), (minQTY(9845.36.toBigDecimal(), 3.6589.toBigDecimal())))
- }
- @Test
- fun checkMinQTYWhenMinAmountDivideByPriceLessOne(){
- Assert.assertEquals(BigDecimal.ONE, (minQTY(7896.toBigDecimal(), 12896.354.toBigDecimal())))
- }
- //check minQTYAccountCurrency
- @Test
- fun checkMinQTYAccountCurrencyWithIntMinAmountAndIntCross(){
- Assert.assertEquals(425.toBigDecimal(), (minQTYAccountCurrency(5.toBigDecimal(), 85.toBigDecimal())))
- }
- @Test
- fun checkMinQTYAccountCurrencyWithIntMinAmountAndFloatCross(){
- Assert.assertEquals(1222.toBigDecimal(), (minQTYAccountCurrency(14.3659.toBigDecimal(), 85.toBigDecimal())))
- }
- @Test
- fun checkMinQTYAccountCurrencyWithFloatMinAmountAndIntCross(){
- Assert.assertEquals(1198.toBigDecimal(), (minQTYAccountCurrency(14.toBigDecimal(), 85.569.toBigDecimal())))
- }
- @Test
- fun checkMinQTYAccountCurrencyWithFloatMinAmountAndFloatCross(){
- Assert.assertEquals(1483.toBigDecimal(), (minQTYAccountCurrency(14.3659.toBigDecimal(), 103.23.toBigDecimal())))
- }
- @Test
- fun checkMinQTYAccountCurrencyWithCrossEqualsOne(){
- Assert.assertEquals(73.toBigDecimal(), (minQTYAccountCurrency(BigDecimal.ONE, 73.toBigDecimal())))
- }
- @Test
- fun checkMinQTYAccountCurrencyWithCrossEqualsNull(){
- Assert.assertEquals(73.toBigDecimal(), (minQTYAccountCurrency(null, 73.toBigDecimal())))
- }
- //check neededAmount
- @Test
- fun checkNeededAmountWithIntBalance(){
- Assert.assertEquals(159307.toBigDecimal(),neededAmount(101256.toBigDecimal(),1589.toBigDecimal(),1.589.toBigDecimal()))
- }
- @Test
- fun checkNeededAmountWithFloatBalance(){
- Assert.assertEquals(15840.toBigDecimal(),neededAmount(10968.toBigDecimal(),1589.45.toBigDecimal(),1.589.toBigDecimal()))
- }
- @Test
- fun checkNeededAmountWhenDifferenceMinQTYAndBalanceLessZero(){
- Assert.assertEquals(BigDecimal.ONE,neededAmount(1000.toBigDecimal(),1588.22.toBigDecimal(),1.589.toBigDecimal()))
- }
- @Test
- fun checkNeededAmountWhenBalanceMoreThenMinQTY(){
- Assert.assertEquals((-7236).toBigDecimal(),neededAmount(10.toBigDecimal(),7252.15.toBigDecimal(),1.589.toBigDecimal()))
- }
- @Test
- fun checkNeededAmountWhenBalanceEqualsMinQTY(){
- Assert.assertEquals(BigDecimal.ZERO,neededAmount(18.toBigDecimal(),67.toBigDecimal(),3.685.toBigDecimal()))
- }
- @Test
- fun checkInvestmentValueWithIntQTYIntNavIntCross(){
- Assert.assertEquals(520200.toBigDecimal(),investmentValue(17.toBigDecimal(), 850.toBigDecimal(), 36.toBigDecimal()))
- }
- @Test
- fun checkInvestmentValueWithIntQTYIntNavFloatCross(){
- Assert.assertEquals(772.0669.toBigDecimal(),investmentValue(17.toBigDecimal(), 53.toBigDecimal(), 0.8569.toBigDecimal()))
- }
- @Test
- fun checkInvestmentValueWithIntQTYFloatNavIntCross(){
- Assert.assertEquals(5830.0956.toBigDecimal(),investmentValue(17.toBigDecimal(), 9.5263.toBigDecimal(), 36.toBigDecimal()))
- }
- @Test
- fun checkInvestmentValueWithIntQTYFloatNavFloatCross(){
- Assert.assertEquals(74.261717488.toBigDecimal(),investmentValue(8.toBigDecimal(), 25.36954.toBigDecimal(), 0.3659.toBigDecimal()))
- }
- @Test
- fun checkInvestmentValueWithFloatQTYIntNavIntCross(){
- Assert.assertEquals(4343.06.toBigDecimal(),investmentValue(58.69.toBigDecimal(), 1.toBigDecimal(), 74.toBigDecimal()))
- }
- @Test
- fun checkInvestmentValueWithFloatQTYIntNavFloatCross(){
- Assert.assertEquals(167.9478608.toBigDecimal(),investmentValue(5.69.toBigDecimal(), 8.toBigDecimal(), 3.68954.toBigDecimal()))
- }
- @Test
- fun checkInvestmentValueWithFloatQTYFloatNavIntCross(){
- Assert.assertEquals(250.64325.toBigDecimal(),investmentValue(3.25.toBigDecimal(), 8.569.toBigDecimal(), 9.toBigDecimal()))
- }
- @Test
- fun checkInvestmentValueWithFloatQTYFloatNavFloatCross(){
- Assert.assertEquals(4.5894486232.toBigDecimal(),investmentValue(2.36.toBigDecimal(), 7.5698.toBigDecimal(), 0.2569.toBigDecimal()))
- }
- @Test
- fun checkInvestmentValueWithCrossEqualsNull(){
- Assert.assertEquals(14450.toBigDecimal(),investmentValue(17.toBigDecimal(), 850.toBigDecimal(), null))
- }
- //check qty
- @Test
- fun checkQTYWithIntInvestIntNavIntCross(){
- Assert.assertEquals(18.toBigDecimal(),qty(1500.toBigDecimal(), 17.toBigDecimal(), 5.toBigDecimal()))
- }
- @Test
- fun checkQTYWithIntInvestIntNavFloatCross(){
- Assert.assertEquals(25.toBigDecimal(),qty(1548.toBigDecimal(), 17.toBigDecimal(), 3.68974.toBigDecimal()))
- }
- @Test
- fun checkQTYWithIntInvestFloatNavIntCross(){
- Assert.assertEquals(261.toBigDecimal(),qty(754.toBigDecimal(), 0.96587.toBigDecimal(), 3.toBigDecimal()))
- }
- @Test
- fun checkQTYWithIntInvestFloatNavFloatCross(){
- Assert.assertEquals(6.toBigDecimal(),qty(65.toBigDecimal(), 1.2569.toBigDecimal(), 9.987456.toBigDecimal()))
- }
- @Test
- fun checkQTYWithFloatInvestIntNavIntCross(){
- Assert.assertEquals(106.toBigDecimal(),qty(8956.65.toBigDecimal(), 17.toBigDecimal(), 5.toBigDecimal()))
- }
- @Test
- fun checkQTYWithFloatInvestIntNavFloatCross(){
- Assert.assertEquals(2.toBigDecimal(),qty(85.36.toBigDecimal(), 8.toBigDecimal(), 9.5682.toBigDecimal()))
- }
- @Test
- fun checkQTYWithFloatInvestFloatNavIntCross(){
- Assert.assertEquals(24.toBigDecimal(),qty(853.26.toBigDecimal(), 7.2156.toBigDecimal(), 5.toBigDecimal()))
- }
- @Test
- fun checkQTYWithFloatInvestFloatNavFloatCross(){
- Assert.assertEquals(2.toBigDecimal(),qty(8753.21.toBigDecimal(), 654.25.toBigDecimal(), 11.6589.toBigDecimal()))
- }
- @Test
- fun checkQTYWithCrossEqualsNull(){
- Assert.assertEquals(59.toBigDecimal(),qty(546.toBigDecimal(), 9.256.toBigDecimal(), null))
- }
- @Test
- fun checkQTYWithResultLessOne(){
- Assert.assertEquals(1.toBigDecimal(),qty(1500.toBigDecimal(), 1726.25.toBigDecimal(), 13.2658.toBigDecimal()))
- }
- //check positionValue
- @Test
- fun checkPositionValueWithIntQtyAndIntNav(){
- Assert.assertEquals(7.toBigDecimal(),positionValue(BigDecimal.ONE, 7.toBigDecimal()))
- }
- @Test
- fun checkPositionValueWithIntQtyAndNavLessOne(){
- Assert.assertEquals(0.02365.toBigDecimal(),positionValue(BigDecimal.ONE, 0.02365.toBigDecimal()))
- }
- @Test
- fun checkPositionValueWithIntQtyAndLargeNav() {
- Assert.assertEquals(BigDecimal("25917741340589.464"),
- positionValue(10111256.toBigDecimal(), 2563256.369.toBigDecimal())
- )
- }
- //check position profit
- @Test
- fun checkPositionProfitWhenCurrentValueEqualsGetInvested(){
- Assert.assertEquals(BigDecimal.ZERO.scaleUp(2), positionProfit(1.7563.toBigDecimal(), 1.7563.toBigDecimal(),17.toBigDecimal(),BigDecimal.ONE, BigDecimal.ONE))
- }
- @Test
- fun checkPositionProfitWhenCurrentValueMoreThenGetInvested(){
- Assert.assertEquals(2238.78.toBigDecimal(), positionProfit(1.7563.toBigDecimal(), 1.1123.toBigDecimal(),99.toBigDecimal(),36.852.toBigDecimal(), 36.215.toBigDecimal()))
- }
- @Test
- fun checkPositionProfitWhenCurrentValueLessGetInvested(){
- Assert.assertEquals((-37.06).toBigDecimal(), positionProfit(11.23659.toBigDecimal(), 11.9863.toBigDecimal(),17.toBigDecimal(),3.852.toBigDecimal(), 3.915.toBigDecimal()))
- }
- //check getInvested
- @Test
- fun checkGetInvestedWithIntOpPriceIntVolumeFloatCross(){
- Assert.assertEquals(691.99.toBigDecimal(),getInvested(10.toBigDecimal(),56.toBigDecimal(),1.23569.toBigDecimal()))
- }
- @Test
- fun checkGetInvestedWithIntOpPriceIntVolumeIntCross(){
- Assert.assertEquals("162.00".toBigDecimal(),getInvested(9.toBigDecimal(),6.toBigDecimal(),3.toBigDecimal()))
- }
- @Test
- fun checkGetInvestedWithIntOpPriceFloatVolumeIntCross(){
- Assert.assertEquals("2721.60".toBigDecimal(),getInvested(10.toBigDecimal(),45.36.toBigDecimal(),6.toBigDecimal()))
- }
- @Test
- fun checkGetInvestedWithIntOpPriceFloatVolumeFloatCross(){
- Assert.assertEquals(69.57.toBigDecimal(),getInvested(10.toBigDecimal(),5.63.toBigDecimal(),1.23569.toBigDecimal()))
- }
- @Test
- fun checkGetInvestedWithFloatOpPriceIntVolumeIntCross(){
- Assert.assertEquals(3934.16.toBigDecimal(),getInvested(17.5632.toBigDecimal(),56.toBigDecimal(),4.toBigDecimal()))
- }
- @Test
- fun checkGetInvestedWithFloatOpPriceIntVolumeFloatCross(){
- Assert.assertEquals(4710.96.toBigDecimal(),getInvested(17.5632.toBigDecimal(),56.toBigDecimal(),4.7898.toBigDecimal()))
- }
- @Test
- fun checkGetInvestedWithFloatOpPriceFloatVolumeIntCross(){
- Assert.assertEquals(349.92.toBigDecimal(),getInvested(1.00125.toBigDecimal(),87.3695.toBigDecimal(),4.toBigDecimal()))
- }
- @Test
- fun checkGetInvestedWithFloatOpPriceFloatVolumeFloatCross(){
- Assert.assertEquals(4.57.toBigDecimal(),getInvested(1.632.toBigDecimal(),7.5632.toBigDecimal(),0.3695.toBigDecimal()))
- }
- @Test
- fun checkGetInvestedWhenResultLessOne(){
- Assert.assertEquals(0.01.toBigDecimal(),getInvested(0.12563.toBigDecimal(),1.toBigDecimal(),0.002563.toBigDecimal()))
- }
- //check currentValue
- @Test
- fun checkCurrentValueWithIntNavIntCross(){
- Assert.assertEquals("5400.00".toBigDecimal(), currentValue(12.toBigDecimal(),6.toBigDecimal(),75.toBigDecimal()))
- }
- @Test
- fun checkCurrentValueWithIntNavFloatCross(){
- Assert.assertEquals(607.35.toBigDecimal(), currentValue(12.toBigDecimal(),6.3265.toBigDecimal(),8.toBigDecimal()))
- }
- @Test
- fun checkCurrentValueWithFloatNavIntCross(){
- Assert.assertEquals(72773.19.toBigDecimal(), currentValue(1732.695.toBigDecimal(),6.toBigDecimal(),7.toBigDecimal()))
- }
- @Test
- fun checkCurrentValueWithFloatNavFloatCross(){
- Assert.assertEquals(341.57.toBigDecimal(), currentValue(32.1695.toBigDecimal(),0.96523.toBigDecimal(),11.toBigDecimal()))
- }
- @Test
- fun checkCurrentValueWithCrossEqualsNull(){
- Assert.assertEquals(12128.87.toBigDecimal(), currentValue(1732.695.toBigDecimal(),null,7.toBigDecimal()))
- }
- @Test
- fun checkCurrentValueWhenResultLessOne(){
- Assert.assertEquals(0.01.toBigDecimal(), currentValue(0.2563.toBigDecimal(),0.02563.toBigDecimal(),1.toBigDecimal()))
- }
- //check redeemCurrentValue
- @Test
- fun checkRedeemCurrentValueWithIntCurrentValueIntQtyIntMaxQty(){
- Assert.assertEquals(2.1875.toBigDecimal(),redeemCurrentValue(15.toBigDecimal(), 14.toBigDecimal(), 96.toBigDecimal()))
- }
- @Test
- fun checkRedeemCurrentValueWithFloatCurrentValueIntQtyIntMaxQty(){
- Assert.assertEquals(5.074520547945205.toBigDecimal(),redeemCurrentValue(7.56.toBigDecimal(), 49.toBigDecimal(), 73.toBigDecimal()))
- }
- @Test
- fun checkRedeemCurrentValueWihenQtyEqualsMaxQty(){
- Assert.assertEquals(3.56.toBigDecimal(),redeemCurrentValue(3.56.toBigDecimal(), 73.toBigDecimal(), 73.toBigDecimal()))
- }
- @Test
- fun checkRedeemCurrentValueWithQtyAndCurrentValueEqualsOne(){
- Assert.assertEquals("0.01369863013698630".toBigDecimal(),redeemCurrentValue(1.toBigDecimal(), 1.toBigDecimal(), 73.toBigDecimal()))
- }
- //check totalCurrentValue
- @Test
- fun checkTotalCurrentValueWithIntInvestedIntProfit(){
- Assert.assertEquals(185.toBigDecimal(),totalCurrentValue(100.toBigDecimal(), 85.toBigDecimal()))
- }
- @Test
- fun checkTotalCurrentValueWithIntInvestedFloatProfit(){
- Assert.assertEquals(113.26.toBigDecimal(),totalCurrentValue(100.toBigDecimal(), 13.26.toBigDecimal()))
- }
- @Test
- fun checkTotalCurrentValueWithFloatInvestedIntProfit(){
- Assert.assertEquals(117.56.toBigDecimal(),totalCurrentValue(100.56.toBigDecimal(), 17.toBigDecimal()))
- }
- @Test
- fun checkTotalCurrentValueWithFloatInvestedFloatProfit(){
- Assert.assertEquals(3385.29.toBigDecimal(),totalCurrentValue(1020.06.toBigDecimal(), 2365.23.toBigDecimal()))
- }
- @Test
- fun checkTotalCurrentValueWithNegativeProfit(){
- Assert.assertEquals(491.71.toBigDecimal(),totalCurrentValue(745.36.toBigDecimal(), (-253.65).toBigDecimal()))
- }
- @Test
- fun checkTotalCurrentValueWithNegativeProfitMoreThenInvested(){
- Assert.assertEquals((-2365.17).toBigDecimal(),totalCurrentValue(7500.06.toBigDecimal(), (-9865.23).toBigDecimal()))
- }
- @Test
- fun checkTotalCurrentValueWithProfitEqualsZero(){
- Assert.assertEquals(500.06.toBigDecimal(),totalCurrentValue(500.06.toBigDecimal(), BigDecimal.ZERO))
- }
- @Test
- fun checkTotalCurrentValueWithInvestedEqualsNullAndProfitEqualsZero(){
- Assert.assertEquals(BigDecimal.ZERO,totalCurrentValue(null, BigDecimal.ZERO))
- }
- @Test
- fun checkTotalCurrentValueWithInvestedEqualsNull(){
- Assert.assertEquals(745.56.toBigDecimal(),totalCurrentValue(null, 745.56.toBigDecimal()))
- }
- //check val
- @Test
- fun checkVal(){
- val firstPair = ProfitAndInvested((-1256).toBigDecimal(), (-98.3).toBigDecimal())
- val secondPair = ProfitAndInvested((-1256).toBigDecimal(), 852.3.toBigDecimal())
- val thirdPair = ProfitAndInvested((-56).toBigDecimal(), BigDecimal.ZERO)
- val forthPair = ProfitAndInvested(1256.toBigDecimal(), 698.39.toBigDecimal())
- val fifthPair = ProfitAndInvested(BigDecimal.ZERO, BigDecimal.ZERO)
- val sixthPair = ProfitAndInvested((156).toBigDecimal(), BigDecimal.ZERO)
- val dataForTest = listOf(firstPair, secondPair, thirdPair, forthPair, fifthPair, sixthPair)
- dataForTest.toTotalProfitWithCurrentValue
- Assert.assertEquals((-859.61).toBigDecimal(), dataForTest.toTotalProfitWithCurrentValue.first + dataForTest.toTotalProfitWithCurrentValue.second)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement