Class AlphaReport

java.lang.Object
com.quantfinlib.alpha.AlphaReport

public final class AlphaReport extends Object
Alpha reporting: the diagnostics that explain a factor's P&L rather than just totalling it.
  • Alpha decay (lagIcProfile(AlphaContext, AlphaFactor, int, int)): IC of the scores at t against the single-bar return over (t+h−1, t+h], for h = 1..H, with an exponential fit IC(h) = IC₀·exp(−(h−1)/τ). This is the curve that says how fast the information is used up and so bounds the rebalance cadence. The signal's own rank autocorrelation at each lag is reported beside it (turnover is roughly 1 − autocorrelation).
  • Holding-period IC (decayProfile(AlphaContext, AlphaFactor, int, int[])): IC against the cumulative return (t, t+h]. For a slow signal this usually rises and plateaus, so it is not a decay curve; it answers "what is the IC if I hold for h bars".
  • Factor attribution (attribute(double[], double[][], List)): OLS of portfolio returns on factor return streams with classical and Newey-West standard errors; FactorReturns builds the streams from the library's own factors.
  • Curves and ratios: cumulative return, drawdown series, and the ratio set reused from backtest.PerformanceAnalytics.
  • Rolling metrics: the windowed Sharpe.
  • Method Details

    • decayProfile

      public static AlphaReport.Decay decayProfile(AlphaContext ctx, AlphaFactor factor, int startIndex, int[] horizons)
      Mean IC against cumulative forward returns (t, t+h] at each horizon (non-overlapping grid per horizon). halfLifeBars is the first horizon, linearly interpolated, where the IC drops below half its shortest-horizon value, +∞ if it never does. For a decay curve use lagIcProfile(AlphaContext, AlphaFactor, int, int).
      Parameters:
      horizons - ascending forward horizons in bars
    • lagIcProfile

      public static AlphaReport.LagDecay lagIcProfile(AlphaContext ctx, AlphaFactor factor, int startIndex, int maxLag)
      IC of the scores at t against the one-bar return over (t+h−1, t+h] for h = 1..maxLag, averaged over every bar t from startIndex with the whole window in sample, then fitted by least squares to IC(h) = IC₀·exp(−(h−1)/τ) (for fixed τ the optimal IC₀ is closed-form; τ is found by golden-section search on log τ over [0.05, 10⁵] bars, and reported as +∞ when the best fit sits at the upper bound).
    • attribute

      public static AlphaReport.Attribution attribute(double[] portfolioReturns, double[][] factorReturns, List<String> factorNames)
      attribute(double[], double[][], List, int) with the Andrews (1991) automatic lag picked on the portfolio returns.
    • attribute

      public static AlphaReport.Attribution attribute(double[] portfolioReturns, double[][] factorReturns, List<String> factorNames, int hacLag)
      Regresses portfolio returns on factor return streams with an intercept, r_p = α + Σ βᵢ·fᵢ + ε, by Householder QR (Ols). The intercept is the residual alpha.
      Parameters:
      portfolioReturns - per-bar portfolio returns
      factorReturns - one per-bar return stream per factor, aligned
      hacLag - Bartlett lag for the Newey-West errors
    • icTable

      public static double[][] icTable(AlphaContext ctx, List<AlphaFactor> factors, int startIndex, int[] horizons)
      Mean IC of each factor at each forward horizon ([factor][horizon]), the same statistic as decayProfile(AlphaContext, AlphaFactor, int, int[]) for one factor.
    • formatIcTable

      public static String formatIcTable(AlphaContext ctx, List<AlphaFactor> factors, int startIndex, int[] horizons)
      icTable(AlphaContext, List, int, int[]) as plain text, one row per factor.
    • costBreakdown

      public static String costBreakdown(AlphaBacktester.Result r)
      Cost decomposition of a backtest: each drag as a fraction of equity and as a share of the total, with mean turnover and tracking gap.
    • exposureSummary

      public static double[] exposureSummary(AlphaBacktester.Traced traced)
      Mean book exposure over a traced run, per bar: [gross Σ|w|, net Σw, long Σw⁺, short Σw⁻, names held].
    • returnsOf

      public static double[] returnsOf(double[] equity)
      Per-bar simple returns of an equity curve — the input to attribution/rolling.
    • drawdownCurve

      public static double[] drawdownCurve(double[] equity)
      Drawdown series: fraction below the running peak (0 at new highs). Guards peak > 0 exactly like risk.RiskMetrics.maxDrawdown so min(drawdownCurve) and the headline max-drawdown metric can never disagree on a curve that touches zero.
    • rollingSharpe

      public static double[] rollingSharpe(double[] returns, int window, int periodsPerYear)
      Rolling annualized Sharpe over a trailing window of per-bar returns; NaN until the window fills. The steadiness plot: a flat positive line is a strategy, a single spike is an anecdote.

      Uses the sample standard deviation (n−1), the same definition as risk.RiskMetrics.sharpeRatio behind summarize(double[], int). A full-sample rolling window therefore reproduces the headline Sharpe exactly rather than differing by √(n/(n−1)).

    • summarize

      public static PerformanceMetrics summarize(double[] equity, int periodsPerYear)
      The full ratio set on an equity curve (Sharpe, Sortino, Calmar, CAGR, max drawdown), computed by the same engine the backtesters use, so definitions never fork between research and backtest reports.