@Test public void returnsWithSellAndBuyOrders() { BarSeries sampleBarSeries = new MockBarSeries(numFunction, 2, 1, 3, 5, 6, 3, 20); TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, sampleBarSeries), Order.sellAt(1, sampleBarSeries), Order.buyAt(3, sampleBarSeries), Order.sellAt(4, sampleBarSeries), Order.sellAt(5, sampleBarSeries), Order.buyAt(6, sampleBarSeries)); Returns strategyReturns = new Returns(sampleBarSeries, tradingRecord, Returns.ReturnType.ARITHMETIC); assertNumEquals(NaN.NaN, strategyReturns.getValue(0)); assertNumEquals(-0.5, strategyReturns.getValue(1)); assertNumEquals(0, strategyReturns.getValue(2)); assertNumEquals(0, strategyReturns.getValue(3)); assertNumEquals(1d / 5, strategyReturns.getValue(4)); assertNumEquals(0, strategyReturns.getValue(5)); assertNumEquals(1 - (20d / 3), strategyReturns.getValue(6)); }
@Override public Num getValue(int index) { return values.get(index); }
Returns implements Indicator<Num> { @Override public Num getValue(int index) { return values.get(index); } }
Returns implements Indicator<Num> { @Override public Num getValue(int index) { return values.get(index); } Returns(BarSeries barSeries, Trade trade, ReturnType type);  Returns(BarSeries barSeries, TradingRecord tradingRecord, ReturnType type); }
Returns implements Indicator<Num> { @Override public Num getValue(int index) { return values.get(index); } Returns(BarSeries barSeries, Trade trade, ReturnType type);  Returns(BarSeries barSeries, TradingRecord tradingRecord, ReturnType type); List<Num> getValues(); @Override Num getValue(int index); @Override BarSeries getBarSeries(); @Override Num numOf(Number number); int getSize(); void calculate(Trade trade); void calculate(Trade trade, int finalIndex); }
Returns implements Indicator<Num> { @Override public Num getValue(int index) { return values.get(index); } Returns(BarSeries barSeries, Trade trade, ReturnType type);  Returns(BarSeries barSeries, TradingRecord tradingRecord, ReturnType type); List<Num> getValues(); @Override Num getValue(int index); @Override BarSeries getBarSeries(); @Override Num numOf(Number number); int getSize(); void calculate(Trade trade); void calculate(Trade trade, int finalIndex);  }