Summary
SMA computes a rolling simple moving average over one scalar stream. RTTA
maintains a circular buffer and a rolling sum, so each update(value) is
constant-time.
Update API
value = rtta.SMA(window=30, fillna=False).update(value)
window is the maximum number of samples in the rolling average.
Theory Of Operation
A simple moving average treats every sample in the active window equally. RTTA updates the sum by subtracting the sample that leaves the circular buffer and adding the new sample.
Recurrence
Let \(x_t\) be the new sample, \(n\) be window, and \(m_t=\min(t+1,n)\). Let
\(x_{t-n}=0\) during the initial warmup before a full expired sample exists.
The returned average is:
With fillna=False, warmup calls return NaN while the circular buffer is not
full, but the rolling sum and buffer are still updated.
Implementation Notes
The recurrence is implemented in src/rtta/indicator.cpp in class SMA.
