@Override
    public Num calculate(BarSeries series, Position position) {
        if (position.isClosed()) {
            Num loss = excludeCosts ? position.getGrossProfit() : position.getProfit();
            return loss.isNegative() ? loss : series.zero();
        }
        return series.zero();

    }
@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 loss = getCriterion(true);
        assertNumEquals(-35, loss.calculate(series, tradingRecord));
    }