The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +772K…

Follow publication

Member-only story

How to Perform Backtesting in Python

Yuki Takahashi
The Startup
Published in
7 min readJan 14, 2021

--

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…

--

--

The Startup
The Startup

Published in The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +772K followers.

Yuki Takahashi
Yuki Takahashi

Responses (2)

Write a response