Categories
Forex Basic Strategies

Walk Forward: Optimise Your Trading System to Boost Your Earnings

Before you start talking about optimizing a trading system, it’s important to know what these systems are based on or why you should work with them. In this article, we’ll talk about one of the most popular trading tests that exist today. It is the walk-forward test.

What Is the Optimization of a Trading System?

We have all asked ourselves the question of what optimisation is. The optimization of a trading system is based on the study of history of past premises or events. This is done in order to get a number of values to render our system cost-effective. In other words, it is based on carrying out a relevant study about the best results that have occurred in the past, this seeking to obtain a range of possible positive results for the market in which one is working.

Since optimization is based on finding possible numbers or values that approximate or resemble possible current values, it is necessary to take into account that you must have prior market information or valid premises. When you want to perform an optimization of a trading system, it is necessary to take into account the type of objective function you are working with. This is because, for each type of objective function, its values are different.

The objective function with which you are working can be framed in any of the ratios to evaluate systems. All these ratios are based on different ways of working, from here arises the difference between the values that can be given. For example, an objective function may be for the system to have the maximum net gain possible or the minimum possible loss. Depending on this, the parameters of our system can be different.

Ratios for Evaluating Systems

The ratios for evaluating systems are based on the ways you can look for a gain. These give you an assessment of the risk there may be, how profitable it may be, the duration and profitability of profits, among others. To optimize a trading system, you need to be clear about the ratio to maximize or the one you want to prioritize. Thus, when performing the optimization you will look for the results obtained in previous periods and guide you in the possible values to which you can decline.

There are several types of ratios to evaluate the system, I explain three in this article:

Net Profit Ratio

This is one of the most elementary proportions, you can understand it simply as the profitability of the system. This profit is calculated in relation to the initial investment. It’s one of the simplest ways to calculate. However, it is necessary to assess certain circumstances to see whether this system is profitable in the market being operated. In some cases, this system only works within a limited time. Later, you start to generate higher losses, which compared to profits can be disposable.

You should also evaluate the number of trades you can make a profit on, as there may also be a limited number of trades in which you will receive a profit (minimum 150 trades in my case but it varies depending on the type of system). After this, you can only generate losses from your capital.

Ratio through the Drawdown

Many people use Drawdown to opt-out of a trading system. Drawdown is based on the number of consecutive losses in your trading strategy. That is, it is evaluated from the highest point that could be obtained previously, to the lowest point obtained before generating another high point. It is important to note that optimization, in these cases, should have a good margin of error and not fall into over-optimization.

R Squared

The use of R2 or the coefficient of determination for statistical models whose main objective is the prediction of future results based on other related information. The R2 value is a number between 0 and 1 and describes how well a regression line fits a data set. When the value of R2 is close to 1, this indicates that the regression line fits the data very well, while a value of R2 close to 0 is an indication that the regression line is not adjustable in any way to the data. The higher the value of R2, the better the capital curve of the trading system. A very high R2 value should result in a profitable trading system with little drawdown.

The Backtest

This word is very important when performing the optimization of a trading system, since its result will depend on the study of optimization trading. Simply put, doing a backtest is performing and evaluating a history of operations. With this, you get a percentage of hits, the amount of drawdown or net profit, among others. These data are used as results to enter future parameters, seeking to obtain a benefit. The backtest needs to be done with certain variants. The more variants that emerge, the more backtest you’ll have to do until you hit a closed result, but be very careful with over-optimisation.

What is Over-Optimisation?

In the optimization of a trading system, we look for the possible values that can be generated in the future. This is done by evaluating an earlier historical and a number of previous variants. The over optimization is to play with the marked cards. It is to set the parameters for the best past results. When many backtests are performed, the result gets closer to a point of non-existent perfection. That is, a point where there are no faults or margins of error. When this happens, it is because of a saturation of the variants.

This saturation is called over-optimization. It is one of the factors to which one must be very careful when optimizing a trading system. Because when you over-optimize a system, the perfect result, it’s just a big value error. To prevent you from entering an over-optimized, it is advisable to do an optimization with few parameters to optimize. By entering many parameters, you can fall into over optimization. In my case, in fact, I try not to optimize anything.

What is Walk Forward Optimization?

This is one of the most robust optimization systems available today. This is because it performs a complete optimization, but a little late and complex. Thanks to its system being a bit complex, if you have a considerable historical, your results can become numerous. In other words, the more historical you have, the more results you can get.

What makes the Walk Forward so good, if it gives numerous results? The Walk Forward is considered to be one of the most robust optimizers as it optimizes through historical intervals. This amount of results can be reduced. However, be careful not to over-optimize. The optimization using the Walk forward system is performed by analyzing short intervals in the history of market operations. That is to say, when you have a history of 10 years, for example, you take the first three years (1, 2, and 3) of history, they are optimized and you get the backtest.

After this, it is taken from the last year of the first optimization, until the subsequent two years, including the first backtest. In other words, in the second optimization the years 3, 4, and 5 would be taken, together with the first backtest. This will be done with all the following years until the last backtest. Which will be the result of continuous optimization throughout the history. This constant and repetitive optimization is what is considered as the Walk Forward and, thanks to its level of complexity, is considered as one of the most robust. However, it usually gives very accurate results, within the margin of error.

For what purpose is optimization with walk forward used in trading systems? The function with which this type of optimization is performed is based on the verification of the system for the future. In the same way, you can implement it to obtain possible values that generate a profit. All this is done with a series of premises. That is, you must do it with a history of operations. By doing so, you can get an idea about the market in the future. In this way, you will be able to observe if it can be productive to apply the trading strategy that you are evaluating. In certain cases, you will check that the profitability of the system or ratio is only temporary.

A Correct Optimization

As you know, you should avoid over-optimization, as this does not generate more than losses. One of the points you should look at when performing an optimization of a trading system is to avoid single or isolated values. Imagine creating a strategy based on an average of 20 periods that works perfectly. But when you look at their results with an average of 19 or 21, it’s a complete disaster. Doesn’t sound very reliable, does it?

I don’t mean that your trading strategy works well with any parameter you use. But what we’re looking for are robust systems, and if any sensitive change causes results to be altered abruptly, what we have is not a robust system. Keep in mind that the market can make drastic and abrupt changes. Therefore, it is recommended that you make several optimizations at considerable intervals of time. This ensures that the values obtained the first time, remain constant. If not, the market may make a change, and you should engage with that change.

How to Use the Walk-Forward Test?

In my case, I don’t use it to optimize my trading systems. I use it as a test to evaluate its robustness since when we apply it we are seeing different periods outside the sample. In this way, we obtain more information on how it can behave in the future and on the consistency of the strategy. In the end, as you can see, it’s about having the possibilities in our favor with winning strategies, and this test is throwing information about our strategies. As I always say, don’t look for perfect strategies, look for real strategies.

My recommendation is that you study the test and if it is useful incorporate it into your methodology. For me, it is one of those tests that is worth it along with that of Monte Carlo.

Categories
Forex System Design

Introduction to Walk-Forward Analysis – Part 2

Introduction

In the previous part, we introduced the walk-forward analysis concept, its objectives, and its advantages. This educational article will continue discovering the benefits of using the WFA and how to set it up.

Walk-Forward Analysis and Market Impacts

The walk-forward analysis provides information about the impact of changes in trends, volatility, and market liquidity on the performance of the trading strategy or system. Generally,  when these changes occur, they arrive at a fast pace, heavily degrading the trading performance.

The WFA may extend its study in a wide range of time; however, analyses and evaluates the trading performance by separate windows. The broad range of results obtained by the study could provide the developer with a piece of useful information about the market changes impact the trading strategy performance.

Parameters Selection

As a robust optimization system, the WFA can provide the most appropriate parameters for real-time trading.

Simultaneously, the walk-forward analysis provides the strategy developer with the duration of the optimal period of time in which the set of parameters will consistently produce real-time benefits before the deterioration in trading system performance occurs.

Statistical Rigor in the Walk-Forward Analysis

As mentioned above, a large amount of data provides greater confidence in any phenomenon’s statistical study. This concept is also valid in the walk-forward analysis.

In this context, the walk-forward analysis must be large enough to produce several trades such that a large amount of data can be generated for the study. According to Pardo, in his work, he says that a WFA must be as long as possible, usually at least 10 to 20 years, whenever possible. Finally, he adds that these multiple walk-forwards combined performance will often be sufficient to produce the statistical rigor required in the analysis.

As a result, WFA’s multiple optimization windows will be able to give the developer a better idea of how the trading strategy will behave in the face of market changes.

Developing the Walk-Forward Analysis

A walk-forward analysis consists of two stages. In the first section, traditional backtest optimization is developed. The parameters of the trading strategy are analyzed using a sample established according to the developer’s objectives.

The second stage, which is the one that characterizes a walk-forward analysis, evaluates the performance of the parameters using an additional sample that was not used during the previous optimization stage.

The walk-forward analysis process requires the following elements to be set:

  1. Scan range for variables to optimize. The developer must define the time frame in which the trading strategy’s optimization should be performed. The developer should consider that the scan range uses a computational resources level that it will use to evaluate and weight the parameter to be optimized. In this regard, an exploration in a small number of historical simulations will consume less computational resources than a more extensive optimization.
  2. Identify a target or a search function. The developer must define what the purpose of the optimization study is.  A usual target can be a mix of the normalized average trade return (the reward/risk factor), the standard deviation of this figure, and the percentage of winning trades. These three factors will define the quality of any trading system. A fourth key factor is the number of monthly trades delivered by the system.
  3. Size of the optimization window. Generally, this optimization range can vary from 3 to 6 years. This duration depends on different factors such as, for example, the market, the type of trading strategy, the confidence level required by the developer in the optimization results, among other factors determined by the developer.
  4. Size of the walk-forward out-of-sample window. This period is defined based on the optimization window. In most cases, this window can be between 25% and 35% of the optimization time.

The length of the optimization window is determined by:

  1. Availability of data. Depending on the type of market and accessibility of the data to perform the analysis, the developer might find a restriction on the amount of historical data needed to perform strategy optimization.
  2. Trading strategy style. A short-term trading strategy should require a smaller optimization window than a long-term strategy.
  3. The pace of trading strategy. The pace of strategy is highly variable and tends to vary from strategy to strategy. For example, a long-term strategy, such as swing trading, will slower than a short-term trading strategy, which will require less time to produce the same number of trades.
  4. The relevance of data. The relevant data depends on a large number of factors that could empirically be determined. However, Pardo proposes a basic guideline stating that a short-term strategy can be tested using one or two years of data, whereas an intermediate-term strategy would require two to four years, and a long-term strategy four to eight years of data.
  5. The validity of the strategy’s parameters. The developer expects the parameters employed will generate benefits in the historical simulation. Furthermore, it also requires a trading strategy to produce profits in real-time market trading.

Finally, the walk-forward analysis is a post-optimization method, highly effective and revealing when it comes to discriminating a trading system’s robustness. Regarding that, the market is dynamic and changes periodically; the trading system should be re-optimized with a certain periodicity.

For example, a properly optimized short-term strategy could be re-optimized between three and six months of real-time trading. While the long-term between one and two years.

Conclusions

In this second and final part, we reviewed the basics of walk-forward analysis, characterized by providing the trading system developer with a powerful tool for testing, validation, and measuring trading strategy. Among the benefits that this stage of the development of a trading system provides we can mention:

  1. Measurement of robustness.
  2. Reduction of overfitting.
  3. Assessment of market changes in the trading strategy.
  4. Selection of optimal parameters for the strategy.
  5. Statistical reliability, when correctly applied.

Finally, despite the benefits provided by this analysis methodology, the strategy developer should consider that the trading system may need to be re-optimized with a certain periodicity.

Suggested Readings

  • Jaekle, U., Tomasini, E.; Trading Systems: A New Approach to System Development and Portfolio Optimisation; Harriman House Ltd.; 1st Edition (2009).
  • Pardo, R.; The Evaluation and Optimization of Trading Strategies; John Wiley & Sons; 2nd Edition (2008).