Projects

Mean reversion

Pairs trading within the S&P 500

A mean-reversion strategy developed in Python. It uses the S&P 500 as a base universe, testing for correlated and cointegrated pairs, and is designed to capitalise on price divergence between two historically correlated assets.

  • Python
  • Cointegration testing
  • Market neutral
View on GitHub
Pairs trading within the S&P 500

Universe

Based on the S&P 500 index, selected using the latest list from Wikipedia, webscraping practice as much as anything.

The algorithm tests each possible pair for correlation and cointegration. The top 20 unique pairs are then traded for the month and monitored individually within the strategy.

Trading logic

The underlying logic is that the prices of historically correlated assets mean revert over time. To capitalise on that, the strategy opens a long position on the underperforming stock and a short on the outperformer, anticipating a return to the historical average.

Positions close when the spread normalises, locking in the profit. The strategy aims to be market-neutral, targeting returns regardless of market direction.

Once pairs are identified, they are traded until the next rebalancing period. Rebalancing occurs on the first day of every month.

Risk management

A relatively simple stop loss per trade, with one important caveat: each trade is treated as a pair. If one leg is stopped out, both are.

Performance

Backtesting indicates the strategy performs consistently well in periods of high volatility or sector-specific dislocation, where price relationships between pairs temporarily break down.

Its market-neutral construction helps reduce exposure to market-wide trends, aiming for steadier returns in both bull and bear markets. Historically it has shown lower drawdowns and volatility than directional strategies.