MOVING AVERAGE CALCULATOR

Moving average calculator

Paste a series, pick simple, weighted or exponential, and see the averages and the next-period forecast.

Separate values with commas, spaces or new lines; in the labelled format the number goes last on each line, such as 2025-01-31, 120.5. Use a point for decimals and no thousands separators.

What is a moving average and how is it calculated?

A moving average replaces each value with the average of the values in a window that slides along the series, which smooths out random ups and downs. The simple moving average (SMA) of order n is Mt = (Xt + Xt−1 + … + Xt−n+1) ÷ n. The NIST/SEMATECH handbook uses the amounts delivered by 12 suppliers, 9, 8, 9, 12, 9, 12, 11, 7, 13, 9, 11, 10, with a window of 3: the first average is (9 + 8 + 9) ÷ 3 = 8.667, then 9.667, 10.000, 11.000, 10.667, 10.000, 10.333, 9.667, 11.000 and 10.000. There is no average for the first n − 1 periods because the window is not yet full.

What is the difference between simple, weighted and exponential moving averages?

The simple average gives every value in the window the same weight. A weighted moving average (WMA) multiplies the values by weights and divides by their sum; in finance the linear WMA of n periods gives the newest value weight n, the one before it n − 1, and so on down to 1, so its denominator is n(n + 1) ÷ 2. You can also type your own weights, from oldest to newest. The exponential moving average (EMA) uses every earlier value with weights that shrink geometrically: EMAt = α × Xt + (1 − α) × EMAt−1. You set the factor α directly, or through a “span” N, where α = 2 ÷ (N + 1) (the pandas convention): a span of 9 means α = 0.2.

Which starting value does the exponential average use?

The calculator offers three conventions, because the first values depend on them and the average forgets its start only gradually. “First value” sets the first average equal to the first data point; this is the textbook form (Roberts, 1959) and what pandas calls ewm(adjust=False). The NIST handbook (6.4.3.1) works the same way but numbers the smoothed values one period later, as forecasts: its S2 = y1, S3 = α·y2 + (1 − α)·S2. With α = 0.1 and the NIST series 71, 70, 69, 68, 64, 65, 72, 78, 75, 75, 75, 70 the averages are 71, 70.9, 70.71, 70.44, 69.80, 69.32, 69.58, 70.43, 70.88, 71.29, 71.67 and 71.50. “Weights divided by their sum” is the pandas default (adjust=True): for 0, 1, 2 with α = 2/3 it gives 0, 0.75, 1.615 where the first-value form gives 0, 0.667, 1.556. “Average of the first N” starts the series with a simple average, as in many charting packages, for example StockCharts, whose first EMA value is the SMA of the period.

How does the next-period forecast work, and how good is it?

The forecast is the latest average, so it is a naive forecast: a flat line that assumes the series will carry on at its recent level. For the NIST series above with α = 0.1 the forecast for period 13 is 71.50. The calculator also scores the method on your own data by treating each average as the forecast for the next value; for the NIST series and α = 0.1 the mean squared error of those one-step forecasts is 19.0, the figure the handbook reports (the handbook rounds each smoothed value to two decimals; unrounded it is 18.98). Compare different windows or α values by that error, but remember that a moving average cannot follow a steady trend: it stays behind it. The NIST handbook describes double moving averages as a variation that handles a linear trend better, and also covers double and triple exponential smoothing.

How much does a moving average lag behind the data?

Along a straight-line trend a moving average trails the data by the average age of its weights. For the simple average of n values that is (n − 1) ÷ 2 periods; for the linear weighted average it is (n − 1) ÷ 3; for an exponential average it is (1 − α) ÷ α, which pandas calls the centre of mass. A 5-period simple average runs 2 periods behind, a 5-period linear WMA 1.33, and an exponential average with a span of 5 (α = 1/3) also 2. A shorter window or a larger α reacts faster but smooths less, and there is no universally best setting.

What is a centred moving average?

A centred average puts the window around each point instead of behind it, so it has no lag, but it needs values on both sides and so cannot reach the last periods or be used to forecast. Hyndman and Athanasopoulos (Forecasting: Principles and Practice, 3rd ed., section 3.3) use it to estimate the trend: the centred 5-point average of Australia’s exports (as a percentage of GDP) for 1962 is (12.99 + 12.40 + 13.94 + 13.01 + 14.94) ÷ 5 = 13.46. With an even window the centre falls between two periods, so two neighbouring averages are averaged again, a 2 × m moving average. For the quarterly beer production data in the book, the 4-point averages 451.25 and 448.75 give 450.00 for 1992 Q3. The NIST handbook shows the same step for its supplier series with M = 4: 9.5, 10.0 and 10.75.

Sources: NIST/SEMATECH e-Handbook of Statistical Methods, sections 6.4.2 (moving average or smoothing techniques) and 6.4.3 (exponential smoothing); R. J. Hyndman and G. Athanasopoulos, Forecasting: Principles and Practice, 3rd ed. (OTexts), section 3.3 “Moving averages”; documentation of pandas (DataFrame.ewm); StockCharts ChartSchool, “Moving Averages”; Wikipedia, “Moving average”. Not investment or business advice. Related: average calculator, weighted average calculator and standard deviation calculator.