@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 calculateProfitWithShortPositions() {
        MockBarSeries series = new MockBarSeries(numFunction, 95, 100, 70, 80, 85, 100);
        TradingRecord tradingRecord = new BaseTradingRecord(Trade.sellAt(0, series), Trade.buyAt(1, series),
                Trade.sellAt(2, series), Trade.buyAt(5, series));

        AnalysisCriterion avgLoss = getCriterion();
        assertNumEquals(-17.5, avgLoss.calculate(series, tradingRecord));
    }