Pairs Trading within the S&P500
Mean reversion based strategy developed in Python. Uses the S&P500 as a base universe, testing for correlated and cointegrated pairs. The strategy is designed to capitalize on price divergence between two historically correlated assets, seeking to profit on the mean-reverting behavior of the asset pairs. View the backtester code on Github.
-
Based on the S&P500 index. Selected using the latest list from Wikipedia as webscraping practice.
The algo then tests each of these possible pairs for correlation and cointegration.
The top 20 unique pairs are then traded for the month, individually monitored within the strategy.
-
The underlying logic behind this strategy is that the prices of historically correlated assets will mean revert over time. To capitalize on this, we open a long position on the "underperforming" stock and a short position on the "outperforming" stock, anticipating a return to the historical average.
Positions are closed when the spread normalizes, locking in the profit. The strategy attempts to be market-neutral, targeting returns regardless of market direction.
After identifying the pairs within the universe, the strategy then trades those pairs for a month until the next rebalancing period. Rebalancing occurs on the first day of every month.
-
For this strategy, I used a relatively simplistic stop loss per trade. An important caveat was treating each trade as a pair. If one leg of the trade was stopped out, both needed to be.
Performance
Backtesting results indicate that this strategy performs consistently well in periods of high volatility or sector specific dislocations. Within these environments price relationships between pairs temporarily breakdown.
The strategy’s market-neutral nture helsp to reduce exposure to market wide trends, aiming to provide steady returns during both bull and bear markets.
Historically, the strategy has exhibited lower drawdowns and volatility compared to directional strategies.