Gregory-Hansen Test

The Gregory-Hansen Test is the residual-based test of Gregory and Hansen (1996) that allows the long-run relation to shift once at an unknown date. A pair whose level or hedge ratio changed, through a merger, a change in index weights or a new regime, looks not cointegrated to the Engle-Granger Test, while it is cointegrated before and after the shift. The test searches every candidate date for the break that makes the residuals most stationary.

The formula for the Gregory-Hansen Test defines, for a break date \(T_{B}\), a dummy \(\phi_{t}\) that switches on from the break:

\[\phi_{t} = 1 \quad \text{if } t \geq T_{B}\] \[\phi_{t} = 0 \quad \text{if } t < T_{B}\]

It fits one of three regressions by OLS, a level shift, a level shift with a trend or a regime shift of both the level and the hedge ratio:

\[A_{t} = \mu_{1} + \mu_{2} \cdot \phi_{t} + \alpha \cdot B_{t} + e_{t}\] \[A_{t} = \mu_{1} + \mu_{2} \cdot \phi_{t} + \beta \cdot t + \alpha \cdot B_{t} + e_{t}\] \[A_{t} = \mu_{1} + \mu_{2} \cdot \phi_{t} + \alpha_{1} \cdot B_{t} + \alpha_{2} \cdot B_{t} \cdot \phi_{t} + e_{t}\]

For every break date it computes the ADF statistic and the Phillips-Ouliaris \(Z_{t}\) and \(Z_{\alpha}\) of the residuals \(e_{t}\) and keeps the smallest of each:

\[\text{ADF}_{\text{star}} = \min\left(\text{ADF}(T_{B})\right)\] \[Z_{t,\text{star}} = \min\left(Z_{t}(T_{B})\right)\] \[Z_{\alpha,\text{star}} = \min\left(Z_{\alpha}(T_{B})\right)\]

Where \(A_{t}\) and \(B_{t}\) are the two prices, \(\mu_{1}\) the level before the break and \(\mu_{2}\) its shift, alpha the hedge ratio (\(\alpha_{1}\) before and \(\alpha_{1} + \alpha_{2}\) after the break in the regime shift), beta * t the trend and \(e_{t}\) the residual. The minimum runs over every break date outside the first and last 15% of the sample. \(\text{ADF}_{\text{star}}\), \(Z_{t , \text{star}}\) and \(Z_{\alpha , \text{star}}\) (ADF, Zt and Z alpha*) reject no cointegration below the critical values of Gregory and Hansen (1996), and the date of the minimum estimates the break. Only critical values are published, so there are no p-values. A rejection does not by itself show that a break occurred: the test also rejects for a pair that is cointegrated without a break, where the Engle-Granger Test suffices.

Two individually non-stationary series, such as two stock prices that each follow a random walk, are cointegrated if some linear combination of them is stationary: they share a long-run equilibrium even though each wanders on its own in the short run. This is the statistical foundation of pairs trading. If two assets are cointegrated, the spread between them reverts to its equilibrium level, so the spread itself can be traded, with the slope of the regression of one price on the other as the hedge ratio. A residual-based test of cointegration asks whether the residual of that regression, the spread, has a unit root (no cointegration, the null hypothesis) or is stationary (cointegration, the alternative). The result depends on which ticker is the dependent one, so the two orderings of a pair can disagree; the Johansen test treats the pair without that choice. Cointegration found in one window often breaks down in the next, so a relation is usually tested again on a later sample before it is relied on.

Also known as: GH test, cointegration with a structural break, regime shift cointegration.

In the Finance Toolkit this is get_engle_granger_cointegration with method="gregory_hansen", the same function as Engle-Granger Cointegration.

Example · KO, PEP · 2021 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_engle_granger_cointegration:

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["KO", "PEP"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

cointegration = toolkit.econometrics.get_engle_granger_cointegration(method="gregory_hansen")

cointegration[["Gregory-Hansen ADF Statistic", "Break Date", "Critical Value 5%", "Cointegrated (5%)"]]

Which returns:

Using Your Own Data

get_engle_granger_cointegration runs on any data, not only prices: ratios, economic indicators, yield curves or your own dataset. Pass a DataFrame, a Series or a dictionary of them to Econometrics as data, with the dates in the rows or the columns, and set changes to how its changes are calculated: "percentage", "log", "difference" for rates and ratios, or None when the data are changes already. For example, for the monthly unemployment rates of the United States and Germany:

from financetoolkit import Economics, Econometrics

economics = Economics(start_date="2000-01-01")

unemployment = economics.get_unemployment_rate(
    countries=["United States", "Germany"], period="monthly"
)

econometrics = Econometrics(data=unemployment, changes="difference")

econometrics.get_engle_granger_cointegration()

References

  • Paper Gregory, A.W. and Hansen, B.E. (1996). “Residual-Based Tests for Cointegration in Models with Regime Shifts.” Journal of Econometrics, 70(1), 99-126.
Share