DurbinWatson

Incremental, causal technical analysis documentation

Squared adjacent residual differences divided by residual energy.

Supply residuals e in time order. DW = Σ(eₜ−eₜ₋₁)²/Σeₜ². Zero residual energy gives None. A positive constant gives zero. This diagnostic has no universal p-value. Formal bounds depend on the design. Window zero accumulates both sums from stream start. A rolling queue combines the incoming and outgoing sums with their single surviving boundary difference. Each rotation reconstructs suffix sums, excluding edges incident to expired observations. Cumulative updates take O(1) time and storage. Rolling updates take O(1) amortized time, O(w) on rotation and O(w) storage. Tests compare with direct NumPy sums through one million updates.

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

Reference

Durbin and Watson (1950), Testing for Serial Correlation in Least Squares Regression I.