ThresholdAutoregression

Incremental, causal technical analysis documentation

Least-squares SETAR with a searched partition of the delay variable.

Within each regime fit yₜ = aⱼ + Σᵢ bⱼᵢyₜ₋ᵢ + eₜ. Sort n=w−max(order,delay) usable rows by yₜ₋delay. Choose r−1 ordered breaks minimizing total RSS; equal delay values always stay together. Each threshold is the largest value assigned to the lower regime. Every regime requires full rank and max(min_regime,p+2) observations. Results contain thresholds, per-regime OLS fits, RSS, AIC and BIC. No admissible partition gives empty regimes. IC uses n log(RSS/n) plus 2k or k log n with k=r(p+1)+(r−1)+1 including thresholds and common variance; the shared Gaussian constant is omitted. Compare IC across models fitted to identical usable rows. For two regimes, sorted prefix and suffix QR sweeps cost O(n log n+np²+p³). For more regimes, dynamic programming costs O(n log n+rn²p²+rp³), temporary storage O(n(p+r)+p²). Ingest O(1). Compared with enumeration of admissible three-regime splits and NumPy least squares.

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.ThresholdAutoregression(window=64, order=2, delay=1, regimes=2)
for i in range(64):
    value = rng.gauss(0, 1)
    result = model.update(value)
print(result.thresholds)

Reference

Tong and Lim (1980), Threshold autoregression, limit cycles and cyclical data. Chan (1993), Consistency and limiting distribution of the least squares estimator of a threshold autoregressive model.