How to Do a Real Backtest?

Before you start, you may be wondering why a consistent trading strategy and what exactly this means. One of the biggest problems as you will know when trading is that you don’t know what will happen tomorrow. We have a lot of data on what has happened so far but every day the markets behave differently.

So you need a plan that adapts to a changing landscape. This is why doing things well requires applying a strategy. A strategy that is capable of being consistent when the market changes. Be careful, I do not mean by this that you will always win no matter what happens in the market. With consistent I mean that it exploits the inefficiency of the market for which it has been created and is a winner over time (not always).

1. The importance of backtesting when trading

As I was saying, what you have in your hand are past data to measure how good your strategies are. We do this through what is called a backtest. In this article I talk about it in depth, but basically it is about extracting the statistics of our strategies and evaluating how they have behaved.

2. The big mistake doing backtesting: over-optimization

The problem is when we use that data to create and measure strategies at the same time. This brings us to a overoptimization.

To understand it better I give you an example. Imagine that I tell you that if I create a winning strategy I’ll give you a million euros but you don’t have much idea of ​​trading. Surely you take a couple of indicators and see how they have worked and say the typical “if I had entered here and left there…” and present me with an incredible strategy on paper. A strategy that during that time seems infallible. And it is that during that time frame it surely will be.

Very possibly if I apply this strategy I will not get anywhere near the results that I could expect doing backtest. Why?

Mainly because I’ve been playing with the marked cards. I have sought a good result without taking into account the strategy. I’ll explain it to you below.

3. How to do a good backtest

So, surely you are wondering if it is possible and how we can measure the performance of our trading system without falling into this bias. The answer is dividing the time frame or data.

Let’s go with another example to understand it better. We are backtesting our strategy from 2013 to 2022. What we are going to do is use 70% of our data to build the strategy and 30% to measure its performance. This is something like seeing what would have happened if I had really applied this strategy in that 30% of the time horizon. Actually this is what interests us, to observe how it would have worked.

3.1 In Sample (IS)

70% of the data in the previous example is what we call sample or within the sample. I remind you that it is what we used to build our system. In our example it corresponds to the period from January 2013 to September 2022

3.2 Out of Sample (OOS)

On the other hand, 30% is what is known as out of sample or out of the sample. The data that we will use to measure your performance. In this system, this period is the one from September 2022 to September 2022 (painted with a green stripe on the balance graph).

4. The important thing about the backtest

We might think that what is really important when we observe a backtest is that the out-of-sample period presents favorable statistics. But in addition to this, the ideal is that the periods sample Y out of sample have a similar behavior.

This tells us that the strategy behaves in the same way in both periods and shows us a clear sign of robustness. Look in our case how we can see that in both, the performance is very similar. We are facing a strategy that is a candidate to become real.

5. More advanced techniques

There are more advanced techniques to evaluate trading systems in this way, one of the best known is walk forward test. In a few words, it is how to do this division in the data but in different sections in time. It is about doing this division (in sample and out of sample) in a segmented way to go one step further. I’ll explain it to you visually: look at the blue (IS) and green (OOS) sections.

It is a way of seeing all this but dynamically over time.

6. What to do now

My advice is that yes or yes you measure the performance of your strategies with a backtest and that you do it with an out-of-sample period. Good 20%, 30% or 40% but do it. So you will avoid biases and errors that make us see very beautiful profit curves that are not real. And this translates into avoiding wasting money, time and frustration. This is just one more step towards objectivity.

 

Remember to leave me your comment! ?

Leave a Comment