Johansen Restriction Test

Calculate the Johansen restriction tests per ticker: whether a ticker is part of the long-run relations of the group (exclusion) and whether it adjusts to them or leads (weak exogeneity).

Once get_johansen_cointegration finds r long-run relations among the prices, the VECM \(\Delta Y_{t} = \alpha \cdot \beta' \cdot Y_{t - 1} + \sum (i = 1 \ldots k) \Gamma_{i} \cdot \Delta Y_{t - i} + \mu + \epsilon_{t}\) splits them into \(\beta\), the relations themselves, and \(\alpha\), the speed at which each price corrects a deviation. A ticker whose row of \(\beta\) is zero does not belong in any relation and can be dropped. A ticker whose row of \(\alpha\) is zero does not correct: the others move towards it, so it leads price discovery and in a pairs trade it is the leg that does not revert.

The formula is as follows:

\[S_{i,j} = \frac{\sum_{t=1}^{T} R_{i,t} \cdot R'_{j,t}}{T}\] \[\text{Det}\left(\lambda_{U} \cdot S_{1,1} - S_{1,0} \cdot S_{0,0}^{-1} \cdot S_{0,1}\right) = 0\] \[\text{Det}\left(\lambda_{R} \cdot H' \cdot S_{1,1} \cdot H - H' \cdot S_{1,0} \cdot S_{0,0}^{-1} \cdot S_{0,1} \cdot H\right) = 0\] \[\text{LR} = T \cdot \sum_{j=1}^{r} \ln\left(\frac{1 - \lambda_{R,j}}{1 - \lambda_{U,j}}\right)\]

with \(R_{0 , t}\) and \(R_{1 , t}\) the residuals of Delta \(Y_{t}\) and Y(t-1) on Delta Y(t-1), …, Delta Y(t-k) and the deterministic terms, Y the column levels (Adj Close by default), k = lags and Det the determinant. The unrestricted eigenvalues \(\lambda_{U , 1} \geq \ldots \geq \lambda_{U , N}\) solve the first problem; the third line is the exclusion of ticker i (beta = H * phi, H the identity without column i). For the weak exogeneity of ticker i (alpha = A * psi, A the identity without column i), the restricted eigenvalues \(\lambda_{R}\) solve the same problem with \(S_{0 , 0}\), \(S_{0 , 1}\) and \(S_{1 , 1}\) corrected for \(R_{0 , t}\) of ticker i, and \(S_{0 , 0}\) and \(S_{0 , 1}\) reduced to the other tickers. LR is chi-squared with r degrees of freedom under the restriction, with r = rank, or the rank of the Johansen trace test at 5% by default.

Also known as: weak exogeneity test, exclusion test, alpha restriction, beta restriction, Johansen restriction test, long-run exclusion, price leadership.

Example · KO, PEP · 2021 to 2025

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

from financetoolkit import Toolkit

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

restrictions = toolkit.econometrics.get_johansen_restriction_test(rank=1)

restrictions[["Exclusion Statistic", "Exclusion P-Value", "Weak Exogeneity Statistic", "Weak Exogeneity P-Value"]]

Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:

With one cointegrating relation between the share prices of Coca-Cola and PepsiCo from 2021 to 2025, can either be left out of it, and is either weakly exogenous, by Johansen's restriction tests?

Which returns:

Using Your Own Data

get_johansen_restriction_test 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_johansen_restriction_test()

Parameters

get_johansen_restriction_test accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”."weekly"
columnstrThe historical data column to use. Defaults to “Adj Close”."Return"
rankintThe cointegration rank r, between 1 and the number of tickers minus one. Defaults to None, the rank of the Johansen trace test at 5%.None, the rank of the Johansen trace test at 5%
det_orderintWhich deterministic term to include: -1 (none), 0 (an unrestricted constant) or 1 (an unrestricted constant and trend). Defaults to 0.1
lagsintThe number of lagged first differences k. Defaults to 1.2
include_benchmarkboolWhether to include “Benchmark” among the tickers tested jointly. Defaults to False.True
roundingint | NoneThe number of decimals to round the results to. Defaults to None.2
show_columnsstr | list[str] | NoneThe columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column.None, which keeps every column

References

  • Paper Johansen, S. and Juselius, K. (1990). “Maximum Likelihood Estimation and Inference on Cointegration - With Applications to the Demand for Money.” Oxford Bulletin of Economics and Statistics, 52(2), 169-210.
  • Paper Johansen, S. (1991). “Estimation and Hypothesis Testing of Cointegration Vectors in Gaussian Vector Autoregressive Models.” Econometrica, 59(6), 1551-1580.
Share