Last week we reviewed the different steps needed to become an algorithm developer. This week, we’ll focus on the next step, testing your strategy. Let’s get started!
What is backtesting?
By now you know that the hardest part is not learning to code but actually creating a strategy. Once you have an idea that might work, that’s when backtesting comes into play.
As the name implies, backtesting is going back in time and checking how your algorithm would have behaved on historical market data. Of course, this does not guarantee that your strategy will still work in the future, but it is a good start.
Let’s start directly with what not to do! It is very easy to make a strategy, itself, simple and optimize it so much that on your historical data set, it will perform. Unfortunately, this couldn’t be further from the truth!
This phenomenon is called overfitting, and as said above, it consists in over optimizing your parameters on a fixed data set. The classic output of this kind of practice is that once in contact with the real market, your strategy does not work at all.
This is a bit of an overfit as well, but slightly different. Let’s say you want to create a strategy that works on BTC, it will be more complicated to do so on shorter timeframes, because the movements are more erratic. They are less predictable and only a well developed and robust algorithm will be able to cope.
If you decide to create a trend following strategy based on daily bitcoin data on the other hand, even if you separate your training and testing periods, the results will most likely be good because you know in advance that since its inception, BTC has been in an overall uptrend. This is the look-ahead bias.
Now let’s get on with what needs to be done! The first thing to do is to choose which pair or trading assets you want to test, as the results of one trading strategy are not necessarily applicable to another. Next, choose your reference timeframe and it’s supposed to stay put from there.
In and Out of sample
Now, and this is what will allow us to avoid overfitting, we will separate our historical data set into two parts. If we have 4 years of data for a strategy, we will separate it in this way: 3 years of data, which will form the In sample, and one year for the Out sample.
We will then optimize all our parameters based on the first 3 years, trying to maximize the potential profit, the success rate and minimize the maximum drawdown.
When we have reached a satisfactory result, it is time to validate this on the out sample, to see if the behavior of the strategy is similar. If it is, there is a good chance that your algorithm is able to extract money from the market. The next step is to test your strategy in real market conditions with a small amount and then scale up.
Now you know how to avoid getting into a bad situation in the markets with backtesting.
Next week, we will discuss some successful algorithm types.
Do you already have a trading algorithm working, or even know someone having a good one? Do you want to earn passive income by renting it to one of the best trading communities and be sure to get what you deserve? If you answer yes to this, we invite you to contact us: [email protected]
You can also check more details HERE