Skip to content

How to Run Walk-Forward Optimisation Without Peeking

Original question

Can you explain how to use walk-forward optimisation to test whether a trading strategy generalises to unseen market data?

Choose parameters using only data available by a historical decision date, then trade the selected rule on the next contiguous block. Advance the decision date and repeat. Stitch together the untouched trading blocks to evaluate the entire recalibration process as it would have operated over time.

The inner window chooses, the outer window measures

Specify the candidate grid, cost assumptions, training length, validation score, tie-break and rebalancing calendar before evaluating the outer trading blocks. For each outer cutoff, use one or more inner forward splits to score the candidates. Take the winner, refit anything that needs fitting on eligible history, and hold the rule for the next block.

If the rule learns from forward returns, check the label's end time. A five-session forward return observed on the training row at Friday's close is only complete five sessions later. Exclude that row from a model fitted on Friday. An indicator that needs 60 prior bars can warm up on historical prices preceding the test start, provided its calculation stays causal.

When moving from one test block to the next, carry positions and cash across the boundary. If the new parameter choice flips a position, execute the rebalance and apply its turnover cost. Performance computed by restarting from cash each month answers a different question.
At each cutoff, identify the last label whose payoff is fully known. A feature row dated before the cutoff can still be unusable if its forward return finishes after it. Once a rule is selected, carry the actual ending positions from the preceding outer block into the new block. Resetting to cash for every fold can erase turnover and change the portfolio the procedure would really have held. The final return series should be what one investor would experience by following the entire schedule.

Walk one cutoff through the calendar

You compare mean-reversion entry thresholds of 1.5, 2.0 and 2.5 rolling standard deviations. Use two years of rolling history at each cutoff and three successive forward validation blocks inside it. Choose the median net Sharpe across those blocks, subject to a minimum trade count.

At the December cutoff, the three scores are 0.5, 0.9 and 0.7, so January trades threshold 2.0. At the January cutoff, scores are 0.4, 0.6 and 0.8, so February trades threshold 2.5. January's realised −1.2% and February's +0.7% produce a combined return of

(1−0.012)(1+0.007)−1=−0.5084%.(1-0.012)(1+0.007)-1=-0.5084\%.

It would be misleading to replace January's threshold with the February winner after seeing January. Compare the stitched rule with a fixed-threshold baseline over the same blocks and the same cost schedule. This isolates whether the recalibration process earned its complexity.

References and next steps