@Override
    public Num calculate(BarSeries series, Position position) {
        Num numberOfLosingPositions = numberOfLosingPositionsCriterion.calculate(series, position);
        if (numberOfLosingPositions.isZero()) {
            return series.zero();
        }
        Num grossLoss = grossLossCriterion.calculate(series, position);
        if (grossLoss.isZero()) {
            return series.zero();
        }
        return grossLoss.dividedBy(numberOfLosingPositions);
    }
@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 avgLoss = getCriterion();
        assertNumEquals(0, avgLoss.calculate(series, tradingRecord));
    }