RandomWalkIndex

Incremental, causal technical analysis documentation

Summary

RandomWalkIndex is RTTA's streaming Random Walk Index (RWI). For every lag from 1 through window, it compares directional price travel with average true range times the square root of that lag, then returns the largest high-side and low-side readings.

Update API

result = rtta.RandomWalkIndex(window=14, fillna=True).update(close, high, low)
# result.high, result.low

Theory Of Operation

Under a simple diffusion model, expected travel grows approximately with \(\sigma\sqrt{k}\). RWI uses average true range as the volatility scale and asks whether an observed move over any horizon \(k\le n\) is unusually large. Taking the maximum over every horizon is fundamental to RWI: using one window-wide extreme and a single ATR is a different statistic.

Recurrence

Let \(n\) denote window, and define true range in the usual way:

\[TR_t=\max(H_t-L_t,|H_t-C_{t-1}|,|L_t-C_{t-1}|).\]

For each \(k=1,\ldots,n\), use the \(k\) true ranges ending one bar before the current observation:

\[A_{t,k}=\frac1k\sum_{j=1}^{k}TR_{t-j}.\]

Then

\[RWIHigh_t=\max_{1\le k\le n} \frac{H_t-L_{t-k}}{A_{t,k}\sqrt{k}},\]
\[RWILow_t=\max_{1\le k\le n} \frac{H_{t-k}-L_t}{A_{t,k}\sqrt{k}}.\]

Division uses RTTA's safe divide. Result field high is RWIHigh; field low is RWILow.

The complete calculation needs window prior bars plus the current bar. With fillna=False, the first window updates return NaN; update window + 1 returns the first complete result. With fillna=True, startup maximizes over the lags currently available, and the first observation returns zero for both sides.

Implementation Notes

The recurrence is implemented in src/rtta/indicator.cpp in class RandomWalkIndex. Rolling high, low, and true-range buffers allow each candidate horizon to be evaluated without recomputing input history.

Reference