@Override
    public Num calculate(BarSeries series, Position position) {
        Num averageProfit = averageProfitCriterion.calculate(series, position);
        if (averageProfit.isZero()) {
            // only loosing positions means a ratio of 0
            return series.zero();
        }
        Num averageLoss = averageLossCriterion.calculate(series, position);
        if (averageLoss.isZero()) {
            // only winning positions means a ratio of 1
            return series.one();
        }
        return averageProfit.dividedBy(averageLoss).abs();
    }
@Test
    public void calculateOnlyWithLossPositions() {
        MockBarSeries series = new MockBarSeries(numFunction, 100, 95, 100, 80, 85, 70);
        TradingRecord tradingRecord = new BaseTradingRecord(Trade.buyAt(0, series), Trade.sellAt(1, series),
                Trade.buyAt(2, series), Trade.sellAt(5, series));

        AnalysisCriterion avtProfit = getCriterion();
        assertNumEquals(0, avtProfit.calculate(series, tradingRecord));
    }