To introduce Walk Forward testing, let's return to the sample2.rts script used in Tutorial 2.
Open that script again and click on .
Now make all of the following selections in the Optimizer dialog:
-number-1.png)
|
Parameters
|
Check both parameters.
|
-number-2.png)
|
Mode
|
Set to "Combinatorial"
|
-number-3.png)
|
Iterations
|
Set to 1.
|
-number-4.png)
|
Score
|
Set to NetProfit, or any other Results Window item (statistical formula) you want to optimize for. This is your "Fitness Function".
|
-number-5.png)
|
Clear Results
|
Check this so any prior tests will be deleted, and/or open a new results window.
|
-number-6.png)
|
Sort After Each Test
|
Check this whenever generating a Walk-Forward test.
|
-number-7.png)
|
Keep Best
|
Set to 1 for Walk-Forward.
|
-number-8.png)
|
By Date
|
Check this (it will become enabled after the next step if it isn't already).
|
-number-9.png)
|
Daily Interval
|
Set Time Unit to Days (or a longer unit if desired).
|
-number-10.png)
|
Test Length
|
Specifies how many days (since that's the Time Unit) to include in each backtest (252 days is one year).
|
-number-11.png)
|
Test Inverval
|
Specifies how often to re-optimize (63 days is one quarter).
|
-number-12.png)
|
Walk-Forward
|
Check this.
|
-number-13.png)
|
Test Count
|
This will show how many tests need to be run.
|
Now you are ready to press and let RealTest generate your walk-forward model.
Though there are more than 10,000 tests to run, it will probably take less than one minute to finish, depending on the speed of your computer.
As the tests run, you will see the Results window being updated continually. To help the process finish faster, minimize the Results window until all tests are finished, then restore it again.
Here is what is going on under the hood:
for each 63-bar interval of your overall date range
for each of the 110 possible combinations of your two parameters
run a 252-bar test and keep the result if it is better than the prior best result
record the start date and parameter values that produced the best result
Once the above is complete, a new WalkForward section is automatically added to your script. This section contains an item called "Dates", and an item for each of your parameters. These things together serve to define how to run the final Walk-Forward test, in which the best parameters from the previous interval are used for each 63-bar interval. In effect, this becomes a test of the effectiveness of the process of periodic re-optimization.
Here is a snippet of how the results and script windows will look at the end of the run:
.png)
To run the walk-forward test again (without re-generating all the parameter values), simply press the Test button or select Run Test from the Run Menu:
When a script includes a WalkForward section (and it's not commented out), RealTest will always use it when running that script as a single backtest.
Now for (an unfair) comparison, let's do the following:
1. Change the date range in Settings to match the dates of the Walk-Forward row in your results window.
In my case this will be:
.png)
(The start date is 252 bars after the earliest data date, and the end date is 252 bars after the last multiple of 63 bars that would not push it past the last data date.)
2. Add default values for each of the two parameters to select 10 and 70, which were among the best results found in the overall optimization done in Tutorial 2.
.png)
3. Comment out the WalkForward section, so that the test will run with constant parameter values.
4. Run a regular single test by pressing .
5. Look at the new line at the top of the results window:
.png)
(Ignore the parameter values for the Walk-Forward line - they should really be blank or say "various".)
In this case it appears that the walk-forward process produced results that were roughly equivalent to the most optimal overall result.
See also spy_tlt_uis.rts in the Examples folder for an example that uses walk-forward optimization to implement a strategy from an article.
|