Exact two-step residual-based cointegration test.
Supply dependent y followed by x. With the default single predictor, x can be a scalar. Set predictors=p and supply a sequence of length p for a multivariate levels regression. Refit yₜ = Dₜ + βxₜ + eₜ on all w observations. Recompute every residual with this fit and perform a no-constant ADF on those residuals with L fixed lagged differences. The auxiliary sample has w−1−L rows. Return both fits. The null is no cointegration; reject in the left tail. Use the (p+1)-series MacKinnon surface with the first-stage deterministic specification and w−1 for critical-value polynomials, following statsmodels coint. An exactly or numerically perfect first stage leaves residual inference unidentified. P-value surfaces cover at most six stochastic series. Critical-value surfaces cover at most twelve with deterministic terms; the no-constant EG case has no finite-sample critical values. The estimator still reports a statistic outside these calibration ranges. Ring ingestion takes O(p), reading costs O(wk²+k³) time and O(wk+k²) temporary space with k the larger of the two regression dimensions. Tested against statsmodels coint on cointegrated and independent walks.
The econometric conventions specify input validation, warm-up, reset, result fields, numerical rank and critical-value order.
Python example
import random
import rtta
rng = random.Random(42)
model = rtta.EngleGranger(window=64, lags=2)
for i in range(64):
value = rng.gauss(0, 1)
predictor = rng.gauss(0, 1)
result = model.update(value, predictor)
print(result.statistic)
Reference
Engle and Granger (1987), Co-integration and Error Correction. MacKinnon (1994, 2010).
