Class WalkForwardAnalyzer
java.lang.Object
com.quantfinlib.backtest.validation.WalkForwardAnalyzer
Walk-forward analysis — the standard defense against overfit backtests.
The series is split into rolling train/test windows; on each fold the
parameter grid is optimized only on the train window and the winner
is evaluated on the unseen test window. Out-of-sample test segments are
stitched into one continuous equity curve (capital carries across folds),
giving honest out-of-sample metrics and the walk-forward efficiency ratio
(OOS / IS objective — near 1 is robust, near 0 is curve-fitting).
Each test window is evaluated WARM: the backtest sees the preceding
train bars for indicator warm-up but only trades from the test boundary
(Backtester.run(com.quantfinlib.backtest.TradingStrategy, BarSeries, BacktestConfig, int)). Evaluating a bare test slice would re-compute
every indicator cold and force HOLD through each fold's first lookback
bars — systematically understating out-of-sample activity.
The efficiency ratio is only meaningful when the in-sample objective
sum is positive; when it is zero or negative (the optimizer could not
find anything that even backtests well in-sample) efficiency is
NaN — a ratio of two losses saying "0.5" would read as robust
when both sides are failing.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordstatic final record -
Method Summary
Modifier and TypeMethodDescriptionanalyze(BarSeries series, ParameterGrid grid, StrategyFactory factory, BacktestConfig config, int trainBars, int testBars, ToDoubleFunction<PerformanceMetrics> objective)
-
Method Details
-
analyze
public static WalkForwardAnalyzer.WalkForwardResult analyze(BarSeries series, ParameterGrid grid, StrategyFactory factory, BacktestConfig config, int trainBars, int testBars, ToDoubleFunction<PerformanceMetrics> objective) - Parameters:
trainBars- bars in each optimization windowtestBars- bars in each out-of-sample window; the window rolls forward by this amount per fold
-