@Test public void calculate() { TimeSeries series = new MockTimeSeries(100d, 95d, 102d, 105d, 97d, 113d); TradingRecord tradingRecord = new BaseTradingRecord( Order.buyAt(0), Order.sellAt(1), Order.buyAt(2), Order.sellAt(3), Order.buyAt(4), Order.sellAt(5)); AverageProfitableTradesCriterion average = new AverageProfitableTradesCriterion(); assertEquals(2d/3, average.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET); }
@Override public double calculate(TimeSeries series, Trade trade) { int entryIndex = trade.getEntry().getIndex(); int exitIndex = trade.getExit().getIndex(); Decimal result; if (trade.getEntry().isBuy()) { result = series.getTick(exitIndex).getClosePrice().dividedBy(series.getTick(entryIndex).getClosePrice()); } else { result = series.getTick(entryIndex).getClosePrice().dividedBy(series.getTick(exitIndex).getClosePrice()); } return (result.isGreaterThan(Decimal.ONE)) ? 1d : 0d; }
AverageProfitableTradesCriterion extends AbstractAnalysisCriterion { @Override public double calculate(TimeSeries series, Trade trade) { int entryIndex = trade.getEntry().getIndex(); int exitIndex = trade.getExit().getIndex(); Decimal result; if (trade.getEntry().isBuy()) { result = series.getTick(exitIndex).getClosePrice().dividedBy(series.getTick(entryIndex).getClosePrice()); } else { result = series.getTick(entryIndex).getClosePrice().dividedBy(series.getTick(exitIndex).getClosePrice()); } return (result.isGreaterThan(Decimal.ONE)) ? 1d : 0d; } }
AverageProfitableTradesCriterion extends AbstractAnalysisCriterion { @Override public double calculate(TimeSeries series, Trade trade) { int entryIndex = trade.getEntry().getIndex(); int exitIndex = trade.getExit().getIndex(); Decimal result; if (trade.getEntry().isBuy()) { result = series.getTick(exitIndex).getClosePrice().dividedBy(series.getTick(entryIndex).getClosePrice()); } else { result = series.getTick(entryIndex).getClosePrice().dividedBy(series.getTick(exitIndex).getClosePrice()); } return (result.isGreaterThan(Decimal.ONE)) ? 1d : 0d; }  }
AverageProfitableTradesCriterion extends AbstractAnalysisCriterion { @Override public double calculate(TimeSeries series, Trade trade) { int entryIndex = trade.getEntry().getIndex(); int exitIndex = trade.getExit().getIndex(); Decimal result; if (trade.getEntry().isBuy()) { result = series.getTick(exitIndex).getClosePrice().dividedBy(series.getTick(entryIndex).getClosePrice()); } else { result = series.getTick(entryIndex).getClosePrice().dividedBy(series.getTick(exitIndex).getClosePrice()); } return (result.isGreaterThan(Decimal.ONE)) ? 1d : 0d; }  @Override double calculate(TimeSeries series, Trade trade); @Override double calculate(TimeSeries series, TradingRecord tradingRecord); @Override boolean betterThan(double criterionValue1, double criterionValue2); }
AverageProfitableTradesCriterion extends AbstractAnalysisCriterion { @Override public double calculate(TimeSeries series, Trade trade) { int entryIndex = trade.getEntry().getIndex(); int exitIndex = trade.getExit().getIndex(); Decimal result; if (trade.getEntry().isBuy()) { result = series.getTick(exitIndex).getClosePrice().dividedBy(series.getTick(entryIndex).getClosePrice()); } else { result = series.getTick(entryIndex).getClosePrice().dividedBy(series.getTick(exitIndex).getClosePrice()); } return (result.isGreaterThan(Decimal.ONE)) ? 1d : 0d; }  @Override double calculate(TimeSeries series, Trade trade); @Override double calculate(TimeSeries series, TradingRecord tradingRecord); @Override boolean betterThan(double criterionValue1, double criterionValue2);  }