Moving Average: Seeing the Signal Through the Noise
Imagine you're tracking the daily temperature in your city. One day it's 35°C, the next it's 28°C, then 32°C, then a sudden 40°C. The numbers jump around wildly. Is the weather getting hotter? Hard to tell from individual readings — each day's number is just a snapshot, full of random ups and downs.
What you really want is the trend: is the general temperature rising or falling? That's exactly what a moving average does. It smooths out the daily jitter so you can see the underlying pattern.
The Core Intuition
A moving average replaces each data point with the average of itself and its neighbours. Instead of asking "what was the value on Tuesday?", you ask "what was the typical value around Tuesday?" By averaging a small window of consecutive points, you cancel out the random noise and reveal the smoother, more meaningful shape of the data.
The "moving" part means the window slides forward one step at a time. You compute an average for day 1–3, then day 2–4, then day 3–5, and so on — the window "moves" across the data.
The Precise Definition
Given a sequence of numbers x1,x2,x3,…,xn, a simple moving average of window size k (where k is a positive integer) produces a new sequence yt defined as:
yt=kxt+xt−1+xt−2+⋯+xt−k+1
for t=k,k+1,…,n.
Each yt is the arithmetic mean of the k most recent observations ending at time t. The first k−1 terms of the original sequence don't have enough predecessors to form a full window, so they are usually omitted from the smoothed output.
SMAt=k1∑i=0k−1xt−i
A Concrete Example
Take the temperature data: 35, 28, 32, 40, 36, 31 (in °C). Let's use a window of size k=3.
- For t=3: y3=335+28+32=395≈31.7
- For t=4: y4=328+32+40=3100≈33.3
- For t=5: y5=332+40+36=3108=36.0
- For t=6: y6=340+36+31=3107≈35.7
The smoothed sequence is 31.7, 33.3, 36.0, 35.7. Notice how the wild 40°C spike is now part of a gentler rise and fall — the moving average has done its job.
Why It Matters
Moving averages are everywhere in exams and real life: …