Class TradeAnalytics

java.lang.Object
com.quantfinlib.backtest.TradeAnalytics

public final class TradeAnalytics extends Object
Trade-level analytics — the numbers a discretionary reviewer asks for that a Sharpe ratio hides. Two strategies with the same Sharpe can have completely different trade signatures: one wins small and often with a few large losses (a hidden short-gamma profile that blows up), the other loses small and often with rare large wins (trend following, hard to hold). These statistics expose the difference.
  • expectancy — the average P&L per trade, winRate*avgWin - lossRate*avgLoss: the single number that says whether the edge survives being averaged over every trade;
  • payoff ratio: avgWin / avgLoss. Paired with win rate it is the strategy's character. A 40% win rate needs a payoff above 1.5 to have positive expectancy, the arithmetic that kills most "high win rate" systems whose few losses are huge;
  • streaks — the longest run of consecutive losers (and winners): the number that decides whether you can psychologically and financially sit through the strategy. A positive-expectancy system with an 11-trade losing streak gets turned off by its owner at trade 8;
  • Kelly fraction: the fraction f ∈ [0, 1] of equity to commit per trade that maximises the empirical log growth Σ log(1 + f·rᵢ) over the trades' Trade.returnPct() (Kelly 1956; Thorp 2006, Handbook of Asset and Liability Management, §2). The fixed-odds formula W − (1−W)/R on currency P&L is not a sizing number for all-in trades of a compounding book, whose P&L scale depends on equity at the time. A Kelly above ~0.25 usually means the sample is too small or the wins too lucky;
  • hold times — average bars held for winners vs losers: when losers are held far longer than winners, that is the disposition effect showing up in the tape.

Statistics other than Kelly are on realised Trade P&L; a strategy with no losing trades reports an infinite payoff ratio and a Kelly of 1 (bet everything, which is the over-fit warning you want); a record with no positive mean return reports Kelly 0. Static, deterministic, research lane. Complements PerformanceAnalytics (equity-curve metrics) and validation.MonteCarloTradeShuffle (is the sequence luck?).

  • Method Details

    • analyze

      public static TradeAnalytics.Result analyze(List<Trade> trades)
      Computes trade-level statistics.
      Parameters:
      trades - completed trades, non-empty