Pairs Trading Strategy with Pairs Selection Pipeline

This tutorial demonstrates a research pipeline for identifying and backtesting ETF or stock pairs using Moonshot. From a starting universe of stocks or ETFs, all pair combinations are tested for cointegration using the Johansen test. In-sample backtests are run on all cointegrating pairs. A portfolio of the 5 best performing pairs is then selected and backtested out-of-sample.

The pairs trading strategy re-calculates daily hedge ratios using the Johansen test and times entries and exits using Bollinger Bands, as outlined in Ernie Chan's book Algorithmic Trading: Winning Strategies and Their Rationale, Wiley, 2013, chapter 4.

The use of a pairs selection pipeline is aimed at mitigating the tendency of cointegrating pairs to eventually cease cointegrating. The tutorial runs on the universe of US ETFs but is designed to be easily adaptable to other universes of stocks or ETFs.