Walk Forward Analysis: The Smart Way to Test Your Trading Strategy
Ting Jing Yuan, CFA, CQF
Co-founder & COO at TED Optimus | Quant Strategist & Algo Trader
Imagine this: In high school, your exam questions are exactly the same as your homework questions. Sure, you might score 100%, but does it really show how well you understand the material? Not really—you’re just repeating what you’ve already seen. This is similar to what happens in traditional backtesting of trading strategies. The model simply memorizes past data, rather than truly being tested. That’s where Walk Forward Analysis (WFA) comes in.
Walk Forward Analysis splits your data into two sets: training and testing. The training data is like your homework—you learn and refine your strategy there. The testing data, however, is like your exam—a real-world scenario that evaluates how well your strategy performs on unseen data. By separating these two, WFA ensures that your trading strategy is robust and realistic. It’s like taking an exam with questions you’ve never seen before—only then can we properly judge the effectiveness of your approach.
What is Walk Forward Analysis?
Walk Forward Analysis is a technique to evaluate trading strategies using out-of-sample data—data that the model hasn’t seen during optimization. This method tests how well a strategy performs in real-time market conditions. A trading system that performs well in WFA demonstrates robustness and the ability to generate profits consistently, not just on past data.
Why Use Walk Forward Analysis?
Walk Forward Analysis addresses key questions and challenges that traditional backtesting often cannot solve:
1. Is the trading strategy robust?
A robust strategy works well in different market conditions. WFA reveals whether your strategy can adapt to varying trends, volatility, and liquidity, rather than being overfitted to historical data. It ensures your strategy isn’t just a one-hit wonder but a reliable performer in real trading.
2. The cure for overfitting
Overfitting happens when your model learns patterns that are specific to historical data but irrelevant to real-world trading. It’s like memorizing past exam answers instead of understanding the concepts. WFA forces your strategy to adapt to unseen data, reducing the risk of overfitting.
3. A more reliable measure of risk and return
Backtesting often underestimates risks and overestimates returns. WFA provides a realistic assessment by testing your strategy across different timeframes, giving you a clearer picture of potential risks and rewards.
4. Assessing the impact of market changes
Markets evolve over time. Changes in trends, volatility, and liquidity can significantly impact performance. WFA helps gauge how well your strategy handles these shifts, ensuring it remains effective in dynamic market conditions.
5. The best parameter set for trading
WFA identifies the optimal parameters for your strategy, balancing maximum profit with minimum risk. It evaluates different combinations, testing them in out-of-sample periods to find the sweet spot.
Components of Walk Forward Analysis
To perform WFA effectively, you need these essential components:
A. Scan ranges for variables to optimize
B. Objective Function
C. Stages
D. Optimization Window
E. Out-of-Sample Window
A. Scan ranges for variables to optimize
Define the parameters to test. For example, in a 3 Moving Average (MA) strategy (short, medium, long), you might:
Your parameters would include the lengths of the short, medium, and long MAs. WFA tests different combinations within specified ranges to find the best-performing set.
Start by defining the parameters you want to optimize. For instance, in a 3-Moving-Average strategy consists of the following range:
I aim to determine the optimal lengths for my strategy using Walk Forward Analysis.
B. Objective Function
The objective function determines what you optimize. Common choices include:
For example, if you choose net profit, WFA will search for the parameter set that delivers the highest profit across your dataset.
领英推荐
My algorithm will explore every possible combination of parameters within the specified ranges to identify the one that delivers the highest net profit. This approach represents the typical backtesting method most traders are familiar with.
However, for Walk Forward Analysis backtesting, we require a more advanced setup, such as the example shown below:
C. Stages
Each stage in WFA includes:
For instance, if your dataset covers 700 trading days, you could split it into four stages. Each stage consists of one Optimization Window and one Out-of-Sample Window.
D. Optimization Window
This is the period used to refine your strategy. The length depends on:
E. Out-of-Sample Window
This is the period used to evaluate your strategy. Typically, it’s 20-25% of the optimization window. For example, if your optimization window is 300 days, the out-of-sample window might be 100 days.
Example: A Complete WFA Setup
Suppose
The Walk Forward Analysis for my dataset will be structured as follows:
The final step is a pre-live optimization (performed only if the strategy has proven profitable), where you use the most recent periods (e.g., days 401-700) to find the best parameters for future trading. This ensures your strategy reflects the current market environment.
Why Avoid Using All Data for Training?
Using the entire dataset for training defeats the purpose of WFA. Using the entire dataset for training can lead to overfitting and reliance on outdated data. WFA avoids this by focusing on recent, relevant data and testing on unseen periods. It’s like preparing for a new exam format instead of revising old question papers.
Food for Thought
Walk Forward Analysis is a game-changer for traders who want to develop robust, real-world strategies. It goes beyond traditional backtesting by ensuring your strategy performs well on unseen data, adapts to market changes, and avoids overfitting.
Whether you're a beginner or an experienced trader, incorporating WFA into your workflow will help you make smarter, more confident decisions in the dynamic world of trading. If you'd like to get my 'WFA SPREADSHEET', leave a comment below — happy trading!
Distributor Manager
2 个月Fantastic Ting Jing Yuan, CFA, CQF