Understanding Walk Forward Validation in Trading - Avoid overfitting in your trading strategy
My journey to Learning Quant Trading
Understanding Walk Forward Validation in Trading: A Simple Guide
When developing trading strategies, one of the biggest challenges trader’s faces is overfitting — making a strategy that works great on historical data but fails miserably in the real world. One of the most effective techniques to avoid this problem is Walk Forward Validation. (Note: this is what data scientist call cross fold validation with overlap)
I’m about to show you a second level thinking when backtesting your strategy. Normally backtests a strategy and looks at the Profit and loss statement. A second level thinking backtests for “statistical significance”.
In this post, I’ll explain what walk forward validation is, why it’s crucial for backtesting, and how you can use it to improve the reliability of your trading strategies.
What is Walk Forward Validation?
Walk forward validation is a method used to test a trading strategy on historical data in a way that mimics real-world trading. The key idea is to train the strategy on a part of the data, then test it on new, unseen data. This process is repeated, moving forward through the dataset, hence the term "walk forward."
Why You Should Use It
The goal of any backtest is to see if your trading strategy can perform well in the future, not just in the past. Without proper testing, it’s easy to create strategies that are highly optimized for past market conditions but fail when the market changes. Walk forward validation helps you reduce the risk of overfitting, allowing you to build more reliable, robust strategies.
How Walk Forward Validation Works
Here’s a step-by-step breakdown of how walk forward validation works:
1. Split Your Data
First, divide your historical data into multiple chunks or "splits." Typically, you use around 75% of the data for training and the remaining 25% for testing.
For example, let’s say you have 10 years of historical stock data. You might use the first 7 years for training your strategy and the 8th year for testing.
2. Optimize Your Strategy
In the training phase, you tweak and adjust your strategy’s parameters (such as moving averages, stop-loss rules, or risk-reward ratios) to find the settings that would have worked best for that specific period.
This is where you experiment with different settings to maximize performance on the training data.
3. Test on Unseen Data
Once you’ve optimized your strategy using the training data, you then apply it to the unseen test data — the next 25% of your dataset.
The key point here is that the test data wasn’t used during the optimization phase. This gives you a realistic idea of how the strategy would perform on data it hasn’t “seen” before, just like how it would act in a real trading environment.
4. Move Forward
Next, you repeat the process, moving forward through the data. For instance, after testing on year 8, you would move your training window forward — train on years 2 to 8, and then test on year 9. This "rolling" approach ensures that you’re always training and testing on different time periods.
This process continues until you’ve covered all the data, testing your strategy over multiple periods.
Example of Walk Forward Validation
Let’s break it down with an example:
Years 1-7 (Training): You optimize the strategy on this data.
Year 8 (Testing): You apply the strategy (with the optimized settings) on this year’s data to see how it performs.
Years 2-8 (Training): Move forward and optimize the strategy again on this new data range.
Year 9 (Testing): Apply the strategy to year 9’s data.
The process repeats as you walk forward through the data, testing and refining along the way.
5. Evaluate the Results
By the end of the process, you’ll have a series of test results from different time periods. If the strategy performs consistently well across these different periods, it’s a good indication that your strategy is robust and generalizes well to new market conditions.
The Benefits of Walk Forward Validation
Avoids Overfitting: By testing your strategy on unseen data, you avoid the trap of optimizing for specific past conditions that won’t necessarily be repeated in the future.
Realistic Simulation: The process closely mimics how you would use the strategy in real-time trading, giving you a more realistic view of its potential.
Multiple Market Conditions: Markets go through cycles — bull markets, bear markets, high volatility, low volatility. Walk forward validation allows you to test your strategy across various market environments, ensuring it can handle different conditions.