Moving Average

Averages the data in overlapping windows of a fixed length to smooth out short-term bumps. With a window of 3 it averages items 1 to 3, then 2 to 4, then 3 to 5, and so on.

Daily sales or monthly temperatures bounce around so much that the underlying trend is hard to see. Averaging a fixed number of consecutive values, then sliding that window along one step at a time, damps the bouncing and lets the trend show through. That is a moving average.

Mi=xi+xi+1++xi+w1wM_i = \dfrac{x_i + x_{i+1} + \cdots + x_{i+w-1}}{w}

The number of averages produced is nw+1n - w + 1. The window slides forward until its end reaches the last value, so a longer window yields fewer averages.

Example

Take the default data 12, 15, 18, 20, 25, 22, 28, 30 with a window of 3.

The first window covers 12, 15 and 18, averaging 15. Sliding one step gives 15, 18, 20 averaging about 17.6667, then 18, 20, 25 averaging 21, and so on. The full series is 15, 17.6667, 21, 22.3333, 25, 26.6667 — six values, matching 83+1=68 - 3 + 1 = 6.

In the raw data there is a dip where 25 is followed by 22. The moving average shows no dip at all, running 21, 22.3333, 25 straight upwards. The single low reading is absorbed by its neighbours, leaving the overall climb visible.

Choosing the window

A longer window smooths harder but responds later. Because a moving average blends in older values, it lags behind the moment a change actually happened, by roughly half the window length.

A shorter window reacts quickly but smooths weakly, leaving much of the original noise. The choice depends on what you want removed. Matching the window to the cycle you want gone is the natural approach: 7 days to erase day-of-week effects, 12 months to erase seasonality.

Points to watch

This is the simple moving average, which weighs every value in the window equally. Weighted moving averages give recent values more say, and exponential smoothing lets older values fade gradually; each strikes a different balance between responsiveness and stability.

The window cannot exceed the number of values, or no complete window exists.

The ends of the series have no moving average. With a window of 3, two points are lost in total, so a plotted line stops short at both ends.