@Test public void calculateOnlyWithLossTrades() { MockBarSeries 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 buyAndHold = getCriterion(new TotalProfitCriterion()); assertNumEquals(0.95 * 0.7 / 0.7, buyAndHold.calculate(series, tradingRecord)); }
@Override public Num calculate(BarSeries series, TradingRecord tradingRecord) { TradingRecord fakeRecord = new BaseTradingRecord(); fakeRecord.enter(series.getBeginIndex()); fakeRecord.exit(series.getEndIndex()); return criterion.calculate(series, tradingRecord).dividedBy(criterion.calculate(series, fakeRecord)); }
VersusBuyAndHoldCriterion extends AbstractAnalysisCriterion { @Override public Num calculate(BarSeries series, TradingRecord tradingRecord) { TradingRecord fakeRecord = new BaseTradingRecord(); fakeRecord.enter(series.getBeginIndex()); fakeRecord.exit(series.getEndIndex()); return criterion.calculate(series, tradingRecord).dividedBy(criterion.calculate(series, fakeRecord)); } }
VersusBuyAndHoldCriterion extends AbstractAnalysisCriterion { @Override public Num calculate(BarSeries series, TradingRecord tradingRecord) { TradingRecord fakeRecord = new BaseTradingRecord(); fakeRecord.enter(series.getBeginIndex()); fakeRecord.exit(series.getEndIndex()); return criterion.calculate(series, tradingRecord).dividedBy(criterion.calculate(series, fakeRecord)); } VersusBuyAndHoldCriterion(AnalysisCriterion criterion); }
VersusBuyAndHoldCriterion extends AbstractAnalysisCriterion { @Override public Num calculate(BarSeries series, TradingRecord tradingRecord) { TradingRecord fakeRecord = new BaseTradingRecord(); fakeRecord.enter(series.getBeginIndex()); fakeRecord.exit(series.getEndIndex()); return criterion.calculate(series, tradingRecord).dividedBy(criterion.calculate(series, fakeRecord)); } VersusBuyAndHoldCriterion(AnalysisCriterion criterion); @Override Num calculate(BarSeries series, TradingRecord tradingRecord); @Override Num calculate(BarSeries series, Trade trade); @Override boolean betterThan(Num criterionValue1, Num criterionValue2); }
VersusBuyAndHoldCriterion extends AbstractAnalysisCriterion { @Override public Num calculate(BarSeries series, TradingRecord tradingRecord) { TradingRecord fakeRecord = new BaseTradingRecord(); fakeRecord.enter(series.getBeginIndex()); fakeRecord.exit(series.getEndIndex()); return criterion.calculate(series, tradingRecord).dividedBy(criterion.calculate(series, fakeRecord)); } VersusBuyAndHoldCriterion(AnalysisCriterion criterion); @Override Num calculate(BarSeries series, TradingRecord tradingRecord); @Override Num calculate(BarSeries series, Trade trade); @Override boolean betterThan(Num criterionValue1, Num criterionValue2);  }