Backtest Quantitative Trading Strategies
A key difference between a traditional investment management process and a quantitative investment process is the possibility of backtesting a quantitative investment strategy to see how it would have performed in the past. Even if you found a strategy described in complete detail with all the historical performance data available, you would still need to backtest it yourself. This exercise serves several purposes. If nothing else, this replication of the research will ensure that you have understood the strategy completely and have reproduced it exactly for implementation as a trading system. Just as in any medical or scientific research, replicating others’ results also ensures that the original research did not commit any of the common errors plaguing this process. But more than just performing due diligence, doing the backtest yourself allows you to experiment with variations of the original strategy, thereby refining and improving the strategy.
In this chapter, I will describe the common platforms that can be used for backtesting, various sources of historical data useful for backtesting, a minimal set of standard performance measures that a backtest should provide, common pitfalls to avoid, and simple refinements and improvements to strategies.
A few fully developed backtesting examples will also be presented to illustrate the principles and techniques described.
Common Backtesting Platforms:
There are numerous commercial platforms that are designed for backtesting, some of them costing tens of thousands of dollars. In keeping with the focus on start-ups in this Blog, I start with those with which I am familiar and that can be purchased economically and are widely used.
1.) Excel
This is the most basic and most common tool for traders, whether retail or institutional. You can enhance its power further if you can write Visual Basic macros. The beauty of Excel is “What you see is what you get” (or WYSIWYG in computing parlance). Data and program are all in one place so that nothing is hidden. Also, a common backtesting pitfall called “look-ahead bias,” which will be explained later, is unlikely to occur in Excel (unless you use macros, which renders it no longer WYSIWYG) because you can easily align the dates with the various data columns and signals on a spreadsheet. Another advantage of Excel is that often backtesting and live trade generation can be done from the same spreadsheet, eliminating any duplication of programming efforts. The major disadvantage of Excel is that it can be used to backtest only fairly simple models. But, as I explained in the previous chapter, simple models are often the best!
2.) MATLAB
MATLABR (www.mathworks.com) is one of the most common backtesting platforms used by quantitative analysts and traders in large institutions. It is ideal for testing strategies that involve a large portfolio of stocks. (Imagine backtesting a strategy involving 1,500 symbols on Excel it is possible, but quite painful.). It has numerous advanced statistical and mathematical modules built in, so traders do not have to reinvent the wheel if their trading algorithms involve some sophisticated but common mathematical concepts. (A good example is principal component analysis often used in factor models in statistical arbitrage trading, and a hassle to implement in other programming languages. See in next blog Example) There is also a large number of third-party freeware available for download from the Internet, many of them very useful for quantitative trading purposes (an example is the cointegration package used in next blog Example). Finally, MATLAB is very useful in retrieving web pages with financial information and parsing it into a useful form (so-called web scraping). Example shows how this can be done.
Despite the seeming sophistication of the platform, it is actually very easy to learn (at least for basic usage) and it is very quick to write a complete backtest program using this language. The main drawback of MATLAB is that it is relatively expensive: it costs over $1,000 to acquire a license. However, there are several clones of MATLAB on the market where you can write and use codes that are very similar to MATLAB:
- O-Matrix (www.omatrix.com)
- Octave (www.gnu.org/software/octave)
- Scilab (www.scilab.org)
These clones may cost only several hundred dollars, or may be entirely free. Not surprisingly, the more expensive the clone is, the more compatible it is with programs written in MATLAB. (Of course, if you intend to write all the programs yourself and not use any third party’s codes, compatibility is not an issue. But then you would be forfeiting one of the main benefits of using this language.) The other drawback of MATLAB is that it is very useful for backtesting but clumsy to use as an execution platform. So, often, you will need to build a separate execution system in another language once you have backtested your strategy. Despite these drawbacks, MATLAB has found widespread use within the quantitative trading community. I will include MATLAB codes for all the backtesting examples in this blog as well as provide a quick survey of the MATLAB language itself in the appendix.
Read Also; Quantitative Trading: Exploring Promising Strategies and Their Hidden Risks