◄ WORLD V · SONNY 5DART 313 · a helldive at the net

SIMPLE MOVING AVERAGE the last k, averaged — a bounded window that slides

The simple moving average keeps a fixed window of the last k values and averages them, sliding the window forward one step at a time. Unlike the EMA it forgets sharply: a sample counts fully until it falls off the back of the window, then not at all. Its memory is exactly k — bounded, and independent of how long the stream runs. Maintained cleverly it costs O(1) per step (add the new, subtract the one that left). It is the boxcar filter of signal processing and the moving line on every price chart: a running summary whose cost never grows with the data, only with the window you chose.

THE TECHNIQUE mean of the last k; add the new, drop the departed

A stream and a window of 3. The demo reports the average of the last three — bounded memory, sliding forward: live demo


HISTORY & CREDIT the boxcar / rolling mean · time-series classic

“A longer stream needs more memory to average recently.” — the SMA's memory is the window k, fixed forever; the stream can be endless and the cost per step never moves. cited

classical · the rolling / moving average of time-series analysis (Yule, Kendall); the boxcar (rectangular) filter in signal processing.
O(1) trick · keep a running sum: on each step add the entrant, subtract the leaver.
now · SMA lines on charts, smoothing kernels, the simplest FIR filter.

A window of fixed width, dragged along the stream; what leaves the back is subtracted, what enters the front is added. Memory that never grows. boxcar filter

RECOMMEND FOR I-13 the last-3 average, bounded window, on the compiler

On the canonical compiler, the window-3 average over the tail of [1,2,3,4,5] is (3+4+5)/3 = 4 — only the window is summarized:

$ i13 run op_sma.i13 # mean of the last 3 RUN OK · 71 step(s) · peak stack 6 · call depth 4 sma3 = 4 -- average of the last window [3,4,5], memory bounded to k=3
Recommend: the SMA is the honest bounded window — memory exactly k, forever. i13 averages the last three to 4. The supplement to correctness: a correct cumulative average keeps growing in weight-of-history; the SMA holds a fixed window and drops the departed sample exactly. Paired with the EMA (soft forgetting) and Welford (no forgetting, full-stream summary), it maps the three ways a streaming average can bound its memory. Not a keeper (a bounded window is a resource choice, not a mechanism a correct alternative structurally lacks) — but a clean corner of the theme.