@Test public void calculateOnlyWithLossTrades() { series = new MockBarSeries(numFunction, 100, 95, 100, 80, 85, 70); TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, series), Order.sellAt(1, series), Order.buyAt(2, series), Order.sellAt(5, series)); AnalysisCriterion averageProfit = getCriterion(); assertNumEquals(numOf(95d / 100 * 70d / 100).pow(numOf(1d / 6)), averageProfit.calculate(series, tradingRecord)); }
@Override public Num calculate(BarSeries series, TradingRecord tradingRecord) { Num bars = numberOfBars.calculate(series, tradingRecord); if (bars.isEqual(series.numOf(0))) { return series.numOf(1); } return totalProfit.calculate(series, tradingRecord).pow(series.numOf(1).dividedBy(bars)); }
AverageProfitCriterion extends AbstractAnalysisCriterion { @Override public Num calculate(BarSeries series, TradingRecord tradingRecord) { Num bars = numberOfBars.calculate(series, tradingRecord); if (bars.isEqual(series.numOf(0))) { return series.numOf(1); } return totalProfit.calculate(series, tradingRecord).pow(series.numOf(1).dividedBy(bars)); } }
AverageProfitCriterion extends AbstractAnalysisCriterion { @Override public Num calculate(BarSeries series, TradingRecord tradingRecord) { Num bars = numberOfBars.calculate(series, tradingRecord); if (bars.isEqual(series.numOf(0))) { return series.numOf(1); } return totalProfit.calculate(series, tradingRecord).pow(series.numOf(1).dividedBy(bars)); }  }
AverageProfitCriterion extends AbstractAnalysisCriterion { @Override public Num calculate(BarSeries series, TradingRecord tradingRecord) { Num bars = numberOfBars.calculate(series, tradingRecord); if (bars.isEqual(series.numOf(0))) { return series.numOf(1); } return totalProfit.calculate(series, tradingRecord).pow(series.numOf(1).dividedBy(bars)); }  @Override Num calculate(BarSeries series, TradingRecord tradingRecord); @Override Num calculate(BarSeries series, Trade trade); @Override boolean betterThan(Num criterionValue1, Num criterionValue2); }
AverageProfitCriterion extends AbstractAnalysisCriterion { @Override public Num calculate(BarSeries series, TradingRecord tradingRecord) { Num bars = numberOfBars.calculate(series, tradingRecord); if (bars.isEqual(series.numOf(0))) { return series.numOf(1); } return totalProfit.calculate(series, tradingRecord).pow(series.numOf(1).dividedBy(bars)); }  @Override Num calculate(BarSeries series, TradingRecord tradingRecord); @Override Num calculate(BarSeries series, Trade trade); @Override boolean betterThan(Num criterionValue1, Num criterionValue2);  }