@Test public void calculateWithOneWinningAndOneLosingTrades() { MockBarSeries series = new MockBarSeries(numFunction, 100, 195, 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 profit = getCriterion(); assertNumEquals(95 + -30, profit.calculate(series, tradingRecord)); }
@Override public Num calculate(BarSeries series, TradingRecord tradingRecord) { return tradingRecord.getTrades().stream().filter(Trade::isClosed).map(trade -> calculate(series, trade)) .reduce(series.numOf(0), Num::plus); }
ProfitLossPercentageCriterion extends AbstractAnalysisCriterion { @Override public Num calculate(BarSeries series, TradingRecord tradingRecord) { return tradingRecord.getTrades().stream().filter(Trade::isClosed).map(trade -> calculate(series, trade)) .reduce(series.numOf(0), Num::plus); } }
ProfitLossPercentageCriterion extends AbstractAnalysisCriterion { @Override public Num calculate(BarSeries series, TradingRecord tradingRecord) { return tradingRecord.getTrades().stream().filter(Trade::isClosed).map(trade -> calculate(series, trade)) .reduce(series.numOf(0), Num::plus); }  }
ProfitLossPercentageCriterion extends AbstractAnalysisCriterion { @Override public Num calculate(BarSeries series, TradingRecord tradingRecord) { return tradingRecord.getTrades().stream().filter(Trade::isClosed).map(trade -> calculate(series, trade)) .reduce(series.numOf(0), Num::plus); }  @Override Num calculate(BarSeries series, TradingRecord tradingRecord); @Override Num calculate(BarSeries series, Trade trade); @Override boolean betterThan(Num criterionValue1, Num criterionValue2); }
ProfitLossPercentageCriterion extends AbstractAnalysisCriterion { @Override public Num calculate(BarSeries series, TradingRecord tradingRecord) { return tradingRecord.getTrades().stream().filter(Trade::isClosed).map(trade -> calculate(series, trade)) .reduce(series.numOf(0), Num::plus); }  @Override Num calculate(BarSeries series, TradingRecord tradingRecord); @Override Num calculate(BarSeries series, Trade trade); @Override boolean betterThan(Num criterionValue1, Num criterionValue2);  }