@Test public void calculateScoreSimpleHistogramFailsNoHistogramTo() { bal.setConstraint(bal.getConstraint().toBuilder() .marketSellTo(new FullCrossMarketOpportunity.Histogram[] { new FullCrossMarketOpportunity.Histogram(6700, 6800, 0.0), new FullCrossMarketOpportunity.Histogram(6600, 6700, 0.0994727), }) .build() ); HardSoftLongScore score = balanceScore.calculateScore(bal); assertThat(score.isFeasible()).isFalse(); assertThat(score.getHardScore()).isEqualTo(-1L); assertThat(score.getSoftScore()).isEqualTo(2648212L); }
@Override public HardSoftLongScore calculateScore(XoTradeBalance bal) { Coeffs coef = coeffs.computeIfAbsent(bal.getConstraint(), trade -> new Coeffs( trade, bal.getConstraint().getMarketBuyFrom(), bal.getConstraint().getMarketSellTo(), bal.getIntegrator()) ); long profit = calculateProfit(bal, coef); long noLoss = calculateNoLoss(bal, coef); long profitPositive = calculateHasProfit(profit); long hasSellAmount = histogramHasAmount( bal.getTrade().getSellPriceFrom(), bal.getTrade().getSellAmountFrom() * coef.getAmountSafetyFromCoef(), coef.getSellFrom()); long hasBuyAmount = histogramHasAmount( bal.getTrade().getBuyPriceTo(), bal.getTrade().getBuyAmountTo() * coef.getAmountSafetyToCoef(), coef.getBuyTo()); long hasMaxSellPrice = hasCorrectMaxSellPrice( bal.getTrade().getSellPriceFrom(), bal.getConstraint().getMaxFromSellPrice().getVal() ); long hasMinBuyPrice = hasCorrectMinBuyPrice( bal.getTrade().getBuyPriceTo(), bal.getConstraint().getMinToBuyPrice().getVal() ); return HardSoftLongScore.valueOf( noLoss + profitPositive + hasSellAmount + hasBuyAmount + hasMaxSellPrice + hasMinBuyPrice, profit ); }
XoBalanceScore implements EasyScoreCalculator<XoTradeBalance> { @Override public HardSoftLongScore calculateScore(XoTradeBalance bal) { Coeffs coef = coeffs.computeIfAbsent(bal.getConstraint(), trade -> new Coeffs( trade, bal.getConstraint().getMarketBuyFrom(), bal.getConstraint().getMarketSellTo(), bal.getIntegrator()) ); long profit = calculateProfit(bal, coef); long noLoss = calculateNoLoss(bal, coef); long profitPositive = calculateHasProfit(profit); long hasSellAmount = histogramHasAmount( bal.getTrade().getSellPriceFrom(), bal.getTrade().getSellAmountFrom() * coef.getAmountSafetyFromCoef(), coef.getSellFrom()); long hasBuyAmount = histogramHasAmount( bal.getTrade().getBuyPriceTo(), bal.getTrade().getBuyAmountTo() * coef.getAmountSafetyToCoef(), coef.getBuyTo()); long hasMaxSellPrice = hasCorrectMaxSellPrice( bal.getTrade().getSellPriceFrom(), bal.getConstraint().getMaxFromSellPrice().getVal() ); long hasMinBuyPrice = hasCorrectMinBuyPrice( bal.getTrade().getBuyPriceTo(), bal.getConstraint().getMinToBuyPrice().getVal() ); return HardSoftLongScore.valueOf( noLoss + profitPositive + hasSellAmount + hasBuyAmount + hasMaxSellPrice + hasMinBuyPrice, profit ); } }
XoBalanceScore implements EasyScoreCalculator<XoTradeBalance> { @Override public HardSoftLongScore calculateScore(XoTradeBalance bal) { Coeffs coef = coeffs.computeIfAbsent(bal.getConstraint(), trade -> new Coeffs( trade, bal.getConstraint().getMarketBuyFrom(), bal.getConstraint().getMarketSellTo(), bal.getIntegrator()) ); long profit = calculateProfit(bal, coef); long noLoss = calculateNoLoss(bal, coef); long profitPositive = calculateHasProfit(profit); long hasSellAmount = histogramHasAmount( bal.getTrade().getSellPriceFrom(), bal.getTrade().getSellAmountFrom() * coef.getAmountSafetyFromCoef(), coef.getSellFrom()); long hasBuyAmount = histogramHasAmount( bal.getTrade().getBuyPriceTo(), bal.getTrade().getBuyAmountTo() * coef.getAmountSafetyToCoef(), coef.getBuyTo()); long hasMaxSellPrice = hasCorrectMaxSellPrice( bal.getTrade().getSellPriceFrom(), bal.getConstraint().getMaxFromSellPrice().getVal() ); long hasMinBuyPrice = hasCorrectMinBuyPrice( bal.getTrade().getBuyPriceTo(), bal.getConstraint().getMinToBuyPrice().getVal() ); return HardSoftLongScore.valueOf( noLoss + profitPositive + hasSellAmount + hasBuyAmount + hasMaxSellPrice + hasMinBuyPrice, profit ); }  }
XoBalanceScore implements EasyScoreCalculator<XoTradeBalance> { @Override public HardSoftLongScore calculateScore(XoTradeBalance bal) { Coeffs coef = coeffs.computeIfAbsent(bal.getConstraint(), trade -> new Coeffs( trade, bal.getConstraint().getMarketBuyFrom(), bal.getConstraint().getMarketSellTo(), bal.getIntegrator()) ); long profit = calculateProfit(bal, coef); long noLoss = calculateNoLoss(bal, coef); long profitPositive = calculateHasProfit(profit); long hasSellAmount = histogramHasAmount( bal.getTrade().getSellPriceFrom(), bal.getTrade().getSellAmountFrom() * coef.getAmountSafetyFromCoef(), coef.getSellFrom()); long hasBuyAmount = histogramHasAmount( bal.getTrade().getBuyPriceTo(), bal.getTrade().getBuyAmountTo() * coef.getAmountSafetyToCoef(), coef.getBuyTo()); long hasMaxSellPrice = hasCorrectMaxSellPrice( bal.getTrade().getSellPriceFrom(), bal.getConstraint().getMaxFromSellPrice().getVal() ); long hasMinBuyPrice = hasCorrectMinBuyPrice( bal.getTrade().getBuyPriceTo(), bal.getConstraint().getMinToBuyPrice().getVal() ); return HardSoftLongScore.valueOf( noLoss + profitPositive + hasSellAmount + hasBuyAmount + hasMaxSellPrice + hasMinBuyPrice, profit ); }  @Override HardSoftLongScore calculateScore(XoTradeBalance bal); }
XoBalanceScore implements EasyScoreCalculator<XoTradeBalance> { @Override public HardSoftLongScore calculateScore(XoTradeBalance bal) { Coeffs coef = coeffs.computeIfAbsent(bal.getConstraint(), trade -> new Coeffs( trade, bal.getConstraint().getMarketBuyFrom(), bal.getConstraint().getMarketSellTo(), bal.getIntegrator()) ); long profit = calculateProfit(bal, coef); long noLoss = calculateNoLoss(bal, coef); long profitPositive = calculateHasProfit(profit); long hasSellAmount = histogramHasAmount( bal.getTrade().getSellPriceFrom(), bal.getTrade().getSellAmountFrom() * coef.getAmountSafetyFromCoef(), coef.getSellFrom()); long hasBuyAmount = histogramHasAmount( bal.getTrade().getBuyPriceTo(), bal.getTrade().getBuyAmountTo() * coef.getAmountSafetyToCoef(), coef.getBuyTo()); long hasMaxSellPrice = hasCorrectMaxSellPrice( bal.getTrade().getSellPriceFrom(), bal.getConstraint().getMaxFromSellPrice().getVal() ); long hasMinBuyPrice = hasCorrectMinBuyPrice( bal.getTrade().getBuyPriceTo(), bal.getConstraint().getMinToBuyPrice().getVal() ); return HardSoftLongScore.valueOf( noLoss + profitPositive + hasSellAmount + hasBuyAmount + hasMaxSellPrice + hasMinBuyPrice, profit ); }  @Override HardSoftLongScore calculateScore(XoTradeBalance bal);  }