Cointegration and Z-Score Rules for Pairs Trading in Quantstrat
Summary
This project describes a mean-reversion pairs strategy implemented and backtested with quantstrat. It uses a stock pair from the same sector as its example and also introduces a separate example involving commodity futures on different exchanges. The strategy calculates a rolling standardized price ratio and enters when that ratio crosses configured thresholds. A rolling Augmented Dickey-Fuller test supplies a stationarity filter; trades are taken only when both the deviation and test conditions qualify. Positions buy the relatively weaker leg and sell the stronger one, then exit as the ratio moves back toward its mean.
The write-up reports an in-sample period and an out-of-sample evaluation, noting that out-of-sample performance was weaker while still positive by its stated measures. It also reports lower maximum drawdown in that later period. These results are specific to the chosen pair, sample, parameters, and implementation. The article does not establish robustness across pairs or market regimes, and the excerpts include code and parameter choices that readers should scrutinize for implementation and validation issues before relying on the findings.
Key ideas
- The strategy trades deviations in a pair’s price ratio on the assumption that the ratio will revert toward its mean.
- A rolling Z-score measures the size and direction of the ratio’s deviation from its moving average.
- A rolling Augmented Dickey-Fuller p-value is used as a filter for whether the ratio appears stationary.
- The project compares in-sample and out-of-sample backtests, with weaker reported performance out of sample.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.