How to Perform Backtesting in Python

A step-by-step guide to test alpha performance of a quant algorithmic trading model

Yuki Takahashi
The Startup

--

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:

  1. Update universe and clean the data
  2. Calculate factor values and risk model
  3. Optimise the holdings to maximise the returns while minimise the risks and transaction costs
  4. Calculate metrics
  5. 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…

--

--