ThresholdUnitRoot

Incremental, causal technical analysis documentation

Enders–Granger demeaned TAR joint unit-root test with finite-sample Monte Carlo calibration.

Center levels within the window. Regress Δyₜ on min(yₜ₋₁−ȳ,0) and max(yₜ₋₁−ȳ,0) without an intercept. This is the fixed-zero threshold TAR joint Φ test, with no augmenting lags. F = ((ΣΔy²−RSS)/2)/(RSS/(w−3)). The null sets both slopes to zero. The alternative allows asymmetric adjustment; inspect both slopes before interpreting mean reversion. At construction simulate B length-w Gaussian random walks starting at zero, refitting exactly the same demeaned test. The scale and starting level cancel. Conditional on estimability, p=(1+number of simulated F≥observed F)/(B+1). Quantiles use nearest ranks for 99%, 95%, 90%. This finite-sample calibration assumes iid Gaussian increments with zero drift. Serial correlation, drift and heteroskedasticity require a different null calibration. No standard F or ADF distribution is used. C++ mt19937_64 seed is configurable; normal variate transforms can differ by standard library. Setup O(Bw+B log B), ingestion O(1), read O(w+log B), storage O(w+B). Tested against direct NumPy joint-F regression.

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.ThresholdUnitRoot(window=64, simulations=999, seed=42)
for i in range(64):
    value = rng.gauss(0, 1)
    result = model.update(value)
print(result.statistic)

Reference

Enders and Granger (1998), Unit-Root Tests and Asymmetric Adjustment With an Example Using the Term Structure of Interest Rates, Journal of Business & Economic Statistics 16, 304–311.