Skip to content
All library documents

Building a Mean-Reverting Portfolio with Engle–Granger Cointegration

Code Stratmill research code

Summary

The module implements the two-step Engle–Granger approach to constructing a portfolio intended to be mean reverting. It uses ordinary least squares to regress a chosen dependent asset’s price on the other price series, defaulting to the first input column as the dependent variable. The estimated coefficients form hedge ratios, and the difference between observed and fitted prices becomes the residual series.

The residuals are then checked with an augmented Dickey–Fuller test, with the test statistic and critical values stored for inspection. The fitting option can include a regression constant. The code describes a workflow for estimating a candidate cointegrating relationship; it does not provide example assets, data, trading entry or exit rules, transaction costs, or backtest results. The residual test is a diagnostic, and the document does not establish that any fitted portfolio will remain stable or be profitable.

Key ideas

  • The two-step method estimates a linear relationship between asset prices and tests its residuals for a unit root.
  • The first price column is used as the dependent variable by default.
  • OLS coefficients are used to construct hedge ratios, while regression residuals represent deviations from the fitted relationship.
  • An augmented Dickey–Fuller test reports a statistic and critical values for the residual series.
  • The implementation optionally includes a constant but supplies no trading rules or performance evaluation.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.