@Override
    public Num calculate(BarSeries series, Position position) {
        Num stdDevPnl = standardDeviationCriterion.calculate(series, position);
        if (stdDevPnl.isZero()) {
            return series.zero();
        }
        // SQN = (Average (PnL) / StdDev(PnL)) * SquareRoot(NumberOfTrades)
        Num numberOfPositions = numberOfPositionsCriterion.calculate(series, position);
        Num pnl = criterion.calculate(series, position);
        Num avgPnl = pnl.dividedBy(numberOfPositions);
        return avgPnl.dividedBy(stdDevPnl).multipliedBy(numberOfPositions.sqrt());
    }
@Test
    public void calculateWithOneWinningAndOneLosingLongPositions() {
        MockBarSeries series = new MockBarSeries(numFunction, 100, 195, 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 sqnCriterion = getCriterion();
        assertNumEquals(0.7353910524340095, sqnCriterion.calculate(series, tradingRecord));
    }