KPSS

Incremental, causal technical analysis documentation

Level- or trend-stationarity test using integrated residuals.

Remove a constant or constant plus linear trend from w levels. For residuals e and Sₜ = Σᵢ≤ₜ eᵢ, η = ΣSₜ²/(w²λ²). λ² uses the Bartlett kernel with explicit integer bandwidth 0 ≤ b < w. Reject stationarity in the right tail. A numerically exact deterministic fit leaves the statistic undefined. Returns tabulated critical values and λ²; no interpolated p-value. Maintains cross-products of level, time and lagged terms, plus integrated cross-products for the prefix sum energy. Projection on orthogonal constant and centered time yields the deterministic fit. Accumulators are rebased every window; cancellation triggers direct detrending and Bartlett sums. O(b+1) amortized ingest, O(1) normal read, O(w(b+1)) rebuild/fallback, O(w) memory. Compared with statsmodels kpss with matching nlags and 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.KPSS(window=64, bandwidth=4)
for i in range(64):
    value = rng.gauss(0, 1)
    result = model.update(value)
print(result.statistic)

Reference

Kwiatkowski, Phillips, Schmidt and Shin (1992), Testing the null hypothesis of stationarity against the alternative of a unit root, Table 1.