@Override
    public Num calculate(BarSeries series, Position position) {
        Num numberOfWinningPositions = numberOfWinningPositionsCriterion.calculate(series, position);
        if (numberOfWinningPositions.isZero()) {
            return series.zero();
        }
        Num grossProfit = grossProfitCriterion.calculate(series, position);
        if (grossProfit.isZero()) {
            return series.zero();
        }
        return grossProfit.dividedBy(numberOfWinningPositions);
    }
@Test
    public void calculateOnlyWithProfitPositions() {
        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));

        AnalysisCriterion avgProfit = getCriterion();
        assertNumEquals(7.5, avgProfit.calculate(series, tradingRecord));
    }