@Test public void calculateWithTwoTrades() { MockBarSeries series = new MockBarSeries(numFunction, 100, 105, 110, 100, 95, 105); TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, series), Order.sellAt(2, series), Order.buyAt(3, series), Order.sellAt(5, series)); assertNumEquals(2, getCriterion().calculate(series, tradingRecord)); }
@Override public Num calculate(BarSeries series, TradingRecord tradingRecord) { long numberOfLosingTrades = tradingRecord.getTrades().stream().filter(Trade::isClosed) .filter(trade -> isWinningTrade(series, trade)).count(); return series.numOf(numberOfLosingTrades); }
NumberOfWinningTradesCriterion extends AbstractAnalysisCriterion { @Override public Num calculate(BarSeries series, TradingRecord tradingRecord) { long numberOfLosingTrades = tradingRecord.getTrades().stream().filter(Trade::isClosed) .filter(trade -> isWinningTrade(series, trade)).count(); return series.numOf(numberOfLosingTrades); } }
NumberOfWinningTradesCriterion extends AbstractAnalysisCriterion { @Override public Num calculate(BarSeries series, TradingRecord tradingRecord) { long numberOfLosingTrades = tradingRecord.getTrades().stream().filter(Trade::isClosed) .filter(trade -> isWinningTrade(series, trade)).count(); return series.numOf(numberOfLosingTrades); }  }
NumberOfWinningTradesCriterion extends AbstractAnalysisCriterion { @Override public Num calculate(BarSeries series, TradingRecord tradingRecord) { long numberOfLosingTrades = tradingRecord.getTrades().stream().filter(Trade::isClosed) .filter(trade -> isWinningTrade(series, trade)).count(); return series.numOf(numberOfLosingTrades); }  @Override Num calculate(BarSeries series, TradingRecord tradingRecord); @Override Num calculate(BarSeries series, Trade trade); @Override boolean betterThan(Num criterionValue1, Num criterionValue2); }
NumberOfWinningTradesCriterion extends AbstractAnalysisCriterion { @Override public Num calculate(BarSeries series, TradingRecord tradingRecord) { long numberOfLosingTrades = tradingRecord.getTrades().stream().filter(Trade::isClosed) .filter(trade -> isWinningTrade(series, trade)).count(); return series.numOf(numberOfLosingTrades); }  @Override Num calculate(BarSeries series, TradingRecord tradingRecord); @Override Num calculate(BarSeries series, Trade trade); @Override boolean betterThan(Num criterionValue1, Num criterionValue2);  }