What Is Overfitting in Algorithmic Trading?

The benefits of technology have impacted practically every industry, and finance is no exception. It’s hard to imagine trading without a computer these days (calling a broker? No thanks!), and the tools are only getting better.


Algorithmic trading is just another element of technology in financial markets. It allows traders to automate and execute their strategies, no matter how simple or complicated. Let us delve deeper into this modern way of trading.




What Is Algorithmic Trading (In Simple Terms)?


Let us assume that you are a busy professional and don’t have the time to sit in front of the screens during the entire trading session. Perhaps you have other professional commitments, or maybe you are just managing capital and need to focus on other trades.


Thus, you hire Michael to do the job. You instruct him to purchase 500 stocks of Asset A if its market price drops below the 200-day moving average. 


Now, when you replace Michael with a specially designed trading algorithm to carry out the same trades as per your instructions and criteria, you are trading algorithmically.


Michael, being a human, might miss the opportunity to buy at the lowest possible price, whether because he’s having lunch or the market is just moving too fast. But a computer program—if correctly designed and without bugs—will always be switched on and never miss a beat.


Therefore, algorithmic trading helps to:


  • Execute trades at the best possible prices thanks to a speed advantage
  • Minimize the chances of human errors such as fat fingers, which can rob a trader of a profitable opportunity or even make the transaction a loser
  • Execute traders without emotions and biases


However, programmed trading algorithms don’t come without their own problems. One of the biggest issues to overcome is the data analysis problem of overfitting, also known as curve fitting.




What Is Overfitting / Curve Fitting?


In simple terms, overfitting is when an apparent edge in a trading strategy is due to random market noise, rather than repeatable market behavior. This is especially a problem when using machine learning models to file through data, but it can also occur when manually testing trading hypotheses in a backtest.


You will have likely heard the phrase “past performance is not indicative of future results”, and that is true. But nevertheless, almost all trading strategies are based on historical data, one way or another. The problem of curve fitting occurs when a strategy is overly optimised to recent data, which then proceeds to not work in response to incoming market data—a function of the constantly evolving market.




Why Does Overfitting Occur?

Overfitting usually occurs for one or more of the following reasons:

A) Mistaking Noise for Signal


Financial models developed, especially those using machine learning, are often fed with a lot of noises in training data. This is inevitable in the search for a signal. Such models cannot generalize as:


  • They have a limited data set, and
  • They perform poorly when they are confronted with new data


B) Overly Tweaking Too Many Parameters


Testing slightly different variations of a trading strategy can give false confidence, especially if the tests are conducted on the same dataset. This practice leads to overfitting due to the constant tweaking of several parameters, which might include things such as entry day, holding period, stop loss, and other parameters. 


As a result, the developed financial model ends up perfectly fitting the historical data, but underperforming in the real world with new data.




How To Avoid Overfitting?

As mentioned, too much tinkering with a trading strategy can lead to overfitting, which can lead to false confidence and perhaps even large losses, in an extreme scenario. Hence, it is necessary to avoid curve fitting at all costs, and this could be done using the following methods:


  • Split Data into Training Data and Test Data: 



“Splitting” is one of the most preferred techniques for avoiding overfitting. Generally, the data is split between training data and testing data in a ratio of 80% and 20%, respectively.


The testing data is composed of previously unseen historical or new incoming data that helps the financial model to “see” the bigger oicture and increase its robustness with a greater quantity of high quality information.


  • Testing the Same Data Across Other Assets



When you test your strategy across different assets, you will learn if your edge contains a universal fact of trading behavior. 


If you notice wildly different performance, especially against similar instruments in the same asset class, then perhaps there is an element of overfitting there.


  • Minimize the Number of Strategy Parameters:



 If you have a limited training dataset, but the number of strategy parameters is large, then it is recommended to try narrowing down to only those parameters that are  the most important to the core of the strategy. 


The more parameters you have in general will increase the chance of curve fitting, since there are more combinations of parameters that can lead to unusually skewed results.





Overfitting (or curve fitting) is a common problem that algorithmic traders have to battle with when testing trading systems. If traders are not careful, they could end up with a trading strategy that rhymes perfectly with history, but cannot be applied successfully in the real world.


However, several techniques such as splitting data, testing across various instruments, and a reduction of parameters in the trading strategy can all help the financial model gain the ability to uncover timeless market truths.


Bookmap comes with an API that allows for the testing of trading strategies. Try it out for free today.




Receive updates about new articles

Follow us on social media

New! Bookmap’s DOM Pro includes several special features tailored precisely for the professional DOM trader, for CGQ and Rithmic data only, works with new Execution Pro too! Both included with Global+

#Bookmap #orderflow #trading #scalping

New! Bookmap’s Execution Pro unlocks powerful features allowing traders to execute trades with both speed and precision. Free with Global+

#Bookmap #orderflow #trading #scalping

Algos, support/resistance, and liquidations as explained by @CryptoLifer33


#orderflow #trading