Class AlphaValidation

java.lang.Object
com.quantfinlib.alpha.AlphaValidation

public final class AlphaValidation extends Object
Validation for alpha factors, run before any capital-weighted conclusion:
  • Walk-forward: pick the best candidate on a training window by in-sample IC, measure it on the next unseen window, roll forward. Folds are weighted by their number of IC observations, the stitched out-of-sample IC series gets a Newey-West t-stat, and the in-sample winner is haircut by the expected maximum of N null candidates.
  • Blocked cross-validation: the IC recomputed on k contiguous time blocks; a factor that only works in one block is a regime story.
  • Permutation nulls (AlphaValidation.NullModel): the cross-sectional label permutation tests predictive power; the circular block shift keeps every autocorrelation; the date permutation is a diagnostic for whether the ranking varies over time.
  • Parameter sensitivity: mean IC across an ordered sweep and the drop from the best value to its worse neighbour.
  • Method Details

    • walkForward

      public static AlphaValidation.WalkForwardResult walkForward(AlphaContext ctx, List<AlphaFactor> candidates, int horizon, int startIndex, int trainBars, int testBars)
      Rolls a train/test split across the sample: each fold picks the candidate with the best training-window mean IC and scores it on the next testBars bars.

      Evaluation dates lie on one grid (startIndex, stepping by the horizon) shared by every fold, and the IC matrix is computed once. A date contributes to a window only when its whole forward window fits inside it, so training ICs never see test-window returns.

      Selection bias: with N candidates whose training mean ICs are independent draws from N(0, se²) under the null, the expected maximum is se·((1−γ)Φ⁻¹(1−1/N) + γΦ⁻¹(1−1/(Ne))) (Bailey and López de Prado 2014, J. Portfolio Management 40(5), eq. 6), with se the standard error of the winner's training mean IC. Neighbouring parameter values are correlated, so the effective N is smaller and this haircut is an upper bound.

      Parameters:
      candidates - the competing variants (for example one factor across a lookback grid)
    • crossValidate

      public static AlphaValidation.CrossValidationResult crossValidate(AlphaContext ctx, AlphaFactor factor, int horizon, int startIndex, int k)
      Splits the evaluation range into k contiguous blocks and recomputes the mean IC inside each. Stateless factors have nothing to fit, so this is a consistency check rather than a fit/test split.
    • monteCarloRobustness

      public static AlphaValidation.RobustnessResult monteCarloRobustness(AlphaContext ctx, AlphaFactor factor, int horizon, int startIndex, int trials, long seed)
    • monteCarloRobustness

      public static AlphaValidation.RobustnessResult monteCarloRobustness(AlphaContext ctx, AlphaFactor factor, int horizon, int startIndex, int trials, long seed, AlphaValidation.NullModel model)
      Permutation test of the mean rank IC on the non-overlapping grid (startIndex, stepping by horizon). The p-value is the add-one smoothed fraction of null draws whose |mean IC| reaches the observed |mean IC| (two-sided; Phipson and Smyth 2010, Stat. Appl. Genet. Mol. Biol. 9(1)).

      The cross-sectional null treats symbols as exchangeable within a date; strongly correlated names (one sector driving a small panel) make the null slightly too narrow.

      Parameters:
      trials - random draws, at least 10 (ignored by the exact circular shift)
    • parameterSensitivity

      public static AlphaValidation.SensitivityResult parameterSensitivity(AlphaContext ctx, List<AlphaFactor> sweep, int horizon, int startIndex)
      Evaluates each candidate of an ordered sweep (neighbours in the list are neighbours in parameter space) and reports how far the IC falls when the chosen parameter moves one step. Small drop = plateau; large drop = the chosen value is a spike.