@Test public void calculateWithNoTrades() { MockTimeSeries series = new MockTimeSeries(100, 95, 100, 80, 85, 70); AnalysisCriterion buyAndHold = new VersusBuyAndHoldCriterion(new TotalProfitCriterion()); assertEquals(1 / 0.7, buyAndHold.calculate(series, new BaseTradingRecord()), TATestsUtils.TA_OFFSET); }
@Override public double calculate(TimeSeries series, TradingRecord tradingRecord) { TradingRecord fakeRecord = new BaseTradingRecord(); fakeRecord.enter(series.getBeginIndex()); fakeRecord.exit(series.getEndIndex()); return criterion.calculate(series, tradingRecord) / criterion.calculate(series, fakeRecord); }
VersusBuyAndHoldCriterion extends AbstractAnalysisCriterion { @Override public double calculate(TimeSeries series, TradingRecord tradingRecord) { TradingRecord fakeRecord = new BaseTradingRecord(); fakeRecord.enter(series.getBeginIndex()); fakeRecord.exit(series.getEndIndex()); return criterion.calculate(series, tradingRecord) / criterion.calculate(series, fakeRecord); } }
VersusBuyAndHoldCriterion extends AbstractAnalysisCriterion { @Override public double calculate(TimeSeries series, TradingRecord tradingRecord) { TradingRecord fakeRecord = new BaseTradingRecord(); fakeRecord.enter(series.getBeginIndex()); fakeRecord.exit(series.getEndIndex()); return criterion.calculate(series, tradingRecord) / criterion.calculate(series, fakeRecord); } VersusBuyAndHoldCriterion(AnalysisCriterion criterion); }
VersusBuyAndHoldCriterion extends AbstractAnalysisCriterion { @Override public double calculate(TimeSeries series, TradingRecord tradingRecord) { TradingRecord fakeRecord = new BaseTradingRecord(); fakeRecord.enter(series.getBeginIndex()); fakeRecord.exit(series.getEndIndex()); return criterion.calculate(series, tradingRecord) / criterion.calculate(series, fakeRecord); } VersusBuyAndHoldCriterion(AnalysisCriterion criterion); @Override double calculate(TimeSeries series, TradingRecord tradingRecord); @Override double calculate(TimeSeries series, Trade trade); @Override boolean betterThan(double criterionValue1, double criterionValue2); @Override String toString(); }
VersusBuyAndHoldCriterion extends AbstractAnalysisCriterion { @Override public double calculate(TimeSeries series, TradingRecord tradingRecord) { TradingRecord fakeRecord = new BaseTradingRecord(); fakeRecord.enter(series.getBeginIndex()); fakeRecord.exit(series.getEndIndex()); return criterion.calculate(series, tradingRecord) / criterion.calculate(series, fakeRecord); } VersusBuyAndHoldCriterion(AnalysisCriterion criterion); @Override double calculate(TimeSeries series, TradingRecord tradingRecord); @Override double calculate(TimeSeries series, Trade trade); @Override boolean betterThan(double criterionValue1, double criterionValue2); @Override String toString();  }