@Override
    public Num calculate(BarSeries series, Position position) {
        Num bars = numberOfBars.calculate(series, position);
        // If a simple division was used (grossreturn/bars), compounding would not be
        // considered, leading to inaccuracies in the calculation.
        // Therefore we need to use "pow" to accurately capture the compounding effect.
        return bars.isZero() ? series.one() : grossReturn.calculate(series, position).pow(series.one().dividedBy(bars));
    }
@Test
    public void calculateWithASimplePosition() {
        series = new MockBarSeries(numFunction, 100d, 105d, 110d, 100d, 95d, 105d);
        TradingRecord tradingRecord = new BaseTradingRecord(Trade.buyAt(0, series), Trade.sellAt(2, series));
        AnalysisCriterion averageProfit = getCriterion();
        assertNumEquals(numOf(110d / 100).pow(numOf(1d / 3)), averageProfit.calculate(series, tradingRecord));
    }