Implementing a Simple Mean Reverting Pairs Trading Algorithm in the Quantconnect platform (Part 2)

Learn how to implement and backtest a Mean Reverting strategy from the book “Algorithmic Trading: Winning Strategies and Their Rationale” using the Quantconnect framework.

Maurício Cordeiro
Analytics Vidhya

--

Photo by Austin Distel on Unsplash

Introduction

Hi! Today we will continue to develop the Mean Reverting algorithm introduced in the last post Implementing a Simple Mean Reverting Pairs Trading Algorithm in the Quantconnect platform (Part 1) [1], and hopefully improve its results .

The idea behind the linear mean regression presented in Part 1 is that we can find a ratio (called hedge ratio) between two assets that cointegrate in time and then use this ratio to create a "virtual" portfolio that returns to its mean. If that is the case, this new portfolio will be stationary and we will be able to trade it using some simple strategy, like the Bollinger Bands indicator that we used previously.

This approach has some drawbacks, however. First, there is no guarantee that the cointegration will continue to happen in the future or if the hedge ratio we’ve modeled using historical value swill remain the same. The second difficulty is that it is not usually…

--

--

Maurício Cordeiro
Analytics Vidhya

Ph.D. Geospatial Data Scientist and water specialist at Brazilian National Water and Sanitation Agency. To get in touch: https://www.linkedin.com/in/cordmaur/