Class GridSearchOptimizer
java.lang.Object
com.quantfinlib.backtest.validation.GridSearchOptimizer
Exhaustive strategy parameter search: backtests every grid combination and
ranks by an objective (e.g.
PerformanceMetrics::sharpeRatio).
Non-finite objectives rank last. Feed the resulting in-sample winners into
WalkForwardAnalyzer — never trust them raw.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classOne grid point: its parameters, metrics, objective and equity curve. -
Method Summary
Modifier and TypeMethodDescriptionbest(ParameterGrid grid, StrategyFactory factory, BarSeries series, BacktestConfig config, ToDoubleFunction<PerformanceMetrics> objective) The winning parameter set only.static doubledeflatedSharpeOfWinner(List<GridSearchOptimizer.Candidate> ranked, double[] winnerReturns, int periodsPerYear) The multiple-testing haircut for the grid's winner: the probability that the top-ranked candidate's Sharpe beats what the best ofeffectiveTrials(List)zero-skill trials would have scored anyway (the deflated Sharpe ofSharpeValidation.probabilisticSharpe(double, double, int, double, double)againstE[max]with N̂ in place of the raw grid size).static doubleEffective number of independent trials in a search,N̂ = ρ̄ + (1 − ρ̄)·Mfor M trials whose per-bar return streams have mean pairwise correlationρ̄(clamped to [0, 1]); the average-correlation approximation in Bailey and López de Prado (2014, J.static List<GridSearchOptimizer.Candidate> search(ParameterGrid grid, StrategyFactory factory, BarSeries series, BacktestConfig config, ToDoubleFunction<PerformanceMetrics> objective)
-
Method Details
-
search
public static List<GridSearchOptimizer.Candidate> search(ParameterGrid grid, StrategyFactory factory, BarSeries series, BacktestConfig config, ToDoubleFunction<PerformanceMetrics> objective) -
best
public static GridSearchOptimizer.Candidate best(ParameterGrid grid, StrategyFactory factory, BarSeries series, BacktestConfig config, ToDoubleFunction<PerformanceMetrics> objective) The winning parameter set only. -
effectiveTrials
Effective number of independent trials in a search,N̂ = ρ̄ + (1 − ρ̄)·Mfor M trials whose per-bar return streams have mean pairwise correlationρ̄(clamped to [0, 1]); the average-correlation approximation in Bailey and López de Prado (2014, J. Portfolio Management 40(5), §3, following the effective number of tests of Bailey, Borwein, López de Prado and Zhu). Adjacent grid points (fast 10/slow 50 vs fast 10/slow 55) trade almost the same book; counting them as independent overstates the expected maximum. -
deflatedSharpeOfWinner
public static double deflatedSharpeOfWinner(List<GridSearchOptimizer.Candidate> ranked, double[] winnerReturns, int periodsPerYear) The multiple-testing haircut for the grid's winner: the probability that the top-ranked candidate's Sharpe beats what the best ofeffectiveTrials(List)zero-skill trials would have scored anyway (the deflated Sharpe ofSharpeValidation.probabilisticSharpe(double, double, int, double, double)againstE[max]with N̂ in place of the raw grid size). A grid search computes a Sharpe for every trial and then quietly reports only the maximum — this is the number that accounts for that selection. Values near 1 mean the winner survives its own search; below ~0.95 the "best" parameter set is indistinguishable from picking the luckiest of N random ones.- Parameters:
ranked- result ofsearch(ParameterGrid, StrategyFactory, BarSeries, BacktestConfig, ToDoubleFunction)(uses every trial's Sharpe as the null distribution), ≥ 2 trialswinnerReturns- the winner's per-period returns (derive from its equity curve), ≥ 4 observationsperiodsPerYear- the annualization used by the backtest metrics
-