@Override
    public Num calculate(BarSeries series, Position position) {
        if (position.isClosed()) {
            Num profit = excludeCosts ? position.getGrossProfit() : position.getProfit();
            return profit.isPositive() ? profit : series.zero();
        }
        return series.zero();
    }
@Test
    public void calculateOnlyWithProfitPositions2() {
        MockBarSeries series = new MockBarSeries(numFunction, 100, 105, 100, 80, 85, 120);
        TradingRecord tradingRecord = new BaseTradingRecord(Trade.buyAt(0, series), Trade.sellAt(1, series),
                Trade.buyAt(2, series), Trade.sellAt(5, series));

        AnalysisCriterion profit = getCriterion(false);
        assertNumEquals(25, profit.calculate(series, tradingRecord));
    }