@Override
    public Num calculate(BarSeries series, Position position) {
        int beginIndex = position.getEntry().getIndex();
        int endIndex = series.getEndIndex();
        return criterion.calculate(series, createEnterAndHoldTrade(series, beginIndex, endIndex));
    }
@Test
    public void calculateOnlyWithGainPositions() {
        MockBarSeries series = new MockBarSeries(numFunction, 100, 105, 110, 100, 95, 105);
        TradingRecord tradingRecord = new BaseTradingRecord(Trade.buyAt(0, series), Trade.sellAt(2, series),
                Trade.buyAt(3, series), Trade.sellAt(5, series));

        // buy and hold of ReturnCriterion
        AnalysisCriterion buyAndHoldReturn = getCriterion(new ReturnCriterion());
        assertNumEquals(1.05, buyAndHoldReturn.calculate(series, tradingRecord));

        // sell and hold of ReturnCriterion
        AnalysisCriterion sellAndHoldReturn = getCriterion(TradeType.SELL, new ReturnCriterion());
        assertNumEquals(0.95, sellAndHoldReturn.calculate(series, tradingRecord));

        // buy and hold of ProfitLossPercentageCriterion
        AnalysisCriterion buyAndHoldPnlPercentage = getCriterion(new ProfitLossPercentageCriterion());
        assertNumEquals(5, buyAndHoldPnlPercentage.calculate(series, tradingRecord));

        // sell and hold of ProfitLossPercentageCriterion
        AnalysisCriterion sellAndHoldPnlPercentage = getCriterion(TradeType.SELL, new ProfitLossPercentageCriterion());
        assertNumEquals(-5, sellAndHoldPnlPercentage.calculate(series, tradingRecord));
    }