How to Perform Backtesting in Python
A step-by-step guide to test alpha performance of a quant algorithmic trading model
I described a basic alpha research process in the previous post — How to Build Quant Algorithmic Trading Model in Python — and this is the extension to cover the backtesting piece.
In this backtesting phase, we perform the following steps on each date for the backtest period:
- Update universe and clean the data
- Calculate factor values and risk model
- Optimise the holdings to maximise the returns while minimise the risks and transaction costs
- Calculate metrics
- Move to the next trading day and repeat from step 1
This is just one basic way and the model described in this post is just a sample and should not be (or even consider to!) used in production.
1. Clean Factor Data
Data Understanding
Factor Returns, Exposures and Covariances can be calculated from daily price data as explained in the previous post; for example, by ingesting data from Quandl. Here, a famous commercial factor model of MSCI Barra is used instead. There are 26 style factors and 55 industry factors for…