Cointegration Pair Trading with Stationarity-Based Model Selection
Summary
This strategy compares a charted asset with a user-selected ticker to estimate a cointegrating relationship. It fits linear regressions across several rolling lookback lengths, tests changes in the residual series for stationarity with a Dickey–Fuller procedure, and selects the first length that passes. The chosen model and its standard-error bands are plotted as the expected value range, with correlation and test statistics shown for reference.
The strategy enters long when price crosses above the lower band and exits when it crosses the model centerline; it enters short below the upper band and exits below the centerline. The description illustrates the method with Boeing and US oil and says some pairs or timeframes may not yield a stationary relationship. It provides no quantified performance evidence, and the code requests comparison prices with lookahead enabled, a setting that can introduce future information into historical calculations. The stationarity and regression checks are also model-selection aids, not a guarantee that a pair relationship will persist or that trading costs and execution are favorable.
Key ideas
- The script tests multiple rolling regression lengths and chooses the first residual series that passes its stationarity check.
- The fitted relationship and error bands define a reference range for comparing the charted asset with a selected ticker.
- Long entries occur on a move above the lower band, while short entries occur below the upper band.
- Both trade directions close when price crosses the fitted centerline in the corresponding direction.
- The author notes that a usable relationship may not be found for every ticker and timeframe.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.