Member-only story
Creating and Back-Testing a Pairs Trading Strategy in Python.
Creating a Systematic Equity Pairs Trading Strategy in Python.
Pairs trading is one of the many mean-reversion strategies. It is considered non-directional and relative as it aims to trade on both related stocks with similar statistical and economical properties. It first identifies a historical relationship that has been recently broken and then buys the implied undervalued security while shorting the overvalued security in attempt to revert to the original relationship. We must first understand the difference between correlation and cointegration. Correlation (ρ) measures the degree of the linear relationship between variables, it has the following features:
- ρ = -1, means a perfectly negative relationship. They move in the opposite direction.
- ρ = 0, means there is no linear relationship between the two.
- ρ = 1, means a perfect linear relationship between the datasets. They move hand in hand.
I have just published a new book after the success of New Technical Indicators in Python. It features a more complete description and addition of complex trading strategies with a Github page dedicated to the continuously updated code. If you feel that this interests you, feel free to visit the below link, or if you prefer to buy the PDF version, you could contact me on Linkedin.