Moving Average Calculator

Enter your data in time order, choose a simple, weighted or exponential moving average and set the window length k. You get the latest moving average with the working, every average in a table, a chart of the values with the moving average through them, and how well each average would have forecast the value that followed it (MAD, MSE, RMSE and MAPE).

For an average that weights values by importance rather than by age, use the weighted mean calculator. To judge a forecast against what actually happened, see the mean squared error calculator; to fit a trend line instead of smoothing, use the linear regression calculator.

Enter numbers separated by commas, spaces or new lines, in time order

How many values go into each average

What a moving average does

A moving average replaces every value of a series with the average of the last k values, the window. When the window moves one step forward, the oldest value drops out and the newest enters, so the average moves along with the data. Because each average blends several values, random ups and downs cancel and the underlying level or trend stands out. That is why moving averages are used to smooth sales, temperatures, web traffic and prices, and as the simplest forecasting method: the average of the latest k values is the forecast for the next one.

The price of smoothing is lag: an average that ends today reflects the middle of its window, not today. The longer the window, the smoother the line and the later it reacts. The first k − 1 periods have no average, because there are not yet k values to average.

Formulas

SMA(t) = (x(t) + x(t − 1) + … + x(t − k + 1)) / k

WMA(t) = (k·x(t) + (k − 1)·x(t − 1) + … + 1·x(t − k + 1)) / (k(k + 1) / 2)

α = 2 / (k + 1)

EMA = SMA of the first k values, then EMA(t) = α·x(t) + (1 − α)·EMA(t − 1)

Forecast for period t + 1 = moving average at period t

MAD = Σ|x(t) − F(t)| / m, MSE = Σ(x(t) − F(t))² / m, MAPE = 100% · Σ(|x(t) − F(t)| / |x(t)|) / m

Here x(t) is the value in period t, F(t) the forecast for it (the moving average one period earlier) and m the number of forecast errors, which is n − k. The weights of the WMA are the whole numbers 1 to k, with the newest value weighted most; they add up to k(k + 1) / 2. The EMA gives the newest value the weight α, which is more than the 1 / k of the SMA, and every older value a weight that shrinks by the factor 1 − α at each step back, so it responds sooner to the newest values although it never forgets the old ones completely.

An exponential average needs a starting value. This calculator uses the convention of StockCharts and most charting platforms: the first EMA is the simple average of the first k values. Some software starts from the first value instead (pandas with adjust=False, Excel's Exponential Smoothing tool), which gives slightly different numbers at the start that fade as the series goes on.

How to read the results

OutputWhat it tells you
Latest Moving AverageThe average of the most recent window. As a forecast, it is the prediction for the next period.
Averages ComputedHow many averages exist: n − k + 1, one for every position where a full window is available.
Smoothing Factor (α)For the EMA only: the weight of the newest value, 2 / (k + 1).
Forecast MADThe average size of the forecast errors when each average is used to predict the next value, in the units of the data.
Forecast MSE and RMSEThe average squared forecast error and its square root; large misses count more.
Forecast MAPEThe average forecast error as a percentage of the actual values. Undefined when an actual value is 0.

Worked example: a 3-period moving average

Eight weekly sales figures: 20, 22, 24, 23, 25, 27, 26, 28. Load example fills in these values with k = 3.

  1. Averages: (20 + 22 + 24) / 3 = 22, (22 + 24 + 23) / 3 = 23, and so on up to (27 + 26 + 28) / 3 = 27. The six averages are 22, 23, 24, 25, 26 and 27; the first two periods have none.
  2. Forecast for week 9: the latest average, 27.
  3. Forecast errors: each average predicts the next week. The averages 22, 23, 24, 25 and 26 predict 23, 25, 27, 26 and 28, so the errors are 1, 2, 3, 1 and 2.
  4. Accuracy: MAD = 9 / 5 = 1.8, MSE = 19 / 5 = 3.8, RMSE = √3.8 = 1.9494 and MAPE = 6.8896%.
  5. Weighted: with weights 1, 2, 3 the latest average is (1 × 27 + 2 × 26 + 3 × 28) / 6 = 27.1667, a little higher because the newest value, 28, counts most.
  6. Exponential: α = 2 / 4 = 0.5 and the first EMA is 22. Then 0.5 × 23 + 0.5 × 22 = 22.5, 0.5 × 25 + 0.5 × 22.5 = 23.75, and so on, ending at 26.8438.

Sales rise by about one unit per week, and the simple average trails the data by one unit: it is centred on the middle of its window. That lag is why a moving average forecast is too low for a rising series.

Simple, weighted or exponential?

  • Simple (SMA) treats every value in the window alike. It is the easiest to explain and check by hand, but every value has the same influence until it suddenly drops out of the window.
  • Weighted (WMA) lets recent values count more with weights that fall in a straight line, so it follows changes sooner than the SMA and forgets old values gradually.
  • Exponential (EMA) weights every earlier value, with weights that shrink by the same factor at each step back. It gives the newest value more weight than the SMA does (2 / (k + 1) against 1 / k), needs only the previous average to update, and is the usual choice for prices.
  • Window length: a short window (3 to 5) follows the data closely and stays noisy; a long window (20 or more) is smooth and late. For data with a repeating pattern, use the length of the pattern: 12 for monthly data with a yearly cycle, 7 for daily data with a weekly one. The average then contains one of each season and the pattern cancels out.

Assumptions and pitfalls

  • Enter the oldest value first. The calculator treats the first value as the earliest period. Data exported newest first must be reversed before use.
  • The periods must be evenly spaced with no gaps. A missing month makes a window span more time than intended.
  • Trending data are forecast too low or too high. A simple moving average trails a steady trend by (k − 1) / 2 periods, and used as a forecast for the next period it is (k + 1) / 2 periods behind. Fit a trend with regression instead when the series rises or falls steadily.
  • One outlier affects k averages. An extreme value stays in every window for k periods, and in an EMA it fades but never completely disappears.
  • Judge a window by its forecast errors, not by how smooth it looks. Compare the MAD or RMSE of several window lengths on the same data and choose the smallest.

Moving average in other software

ToolCommand
Excel / Google Sheets: SMA=AVERAGE(B2:B4) in the third row, filled down for a 3-period average (each row averages its own value and the two before it)
Excel: Data Analysis toolData > Data Analysis > Moving Average, with Interval = k; the first k − 1 rows show #N/A
Excel / Google Sheets: WMA=SUMPRODUCT(B2:B4, {1;2;3}) / 6 for weights 1, 2, 3, the newest value last
Excel / Google Sheets: EMA=AVERAGE(B2:B4) for the first EMA, then =2/(3+1)*B5+(1-2/(3+1))*C4 filled down, with the previous EMA in column C
Python (pandas)s.rolling(3).mean() for the SMA; s.ewm(span=3, adjust=False).mean() for an EMA that starts at the first value
Rstats::filter(x, rep(1/3, 3), sides = 1) or zoo::rollmean(x, 3, fill = NA, align = "right")

All of these use trailing windows, the same as this calculator. Software that centres the window puts each average at the middle of its window instead, which suits describing a past trend but cannot produce a forecast.

Frequently Asked Questions

What is a moving average?

A moving average is a series of averages, each taken over the most recent k values, that moves forward one period at a time. It smooths short-term fluctuations so the underlying level or trend is easier to see, and the average of the latest k values can be used as a one-step-ahead forecast.

How do I calculate a 3-period moving average?

Add three consecutive values and divide by 3, then slide one value forward and repeat. For 20, 22, 24, 23 the first average is (20 + 22 + 24) / 3 = 22 and the second is (22 + 24 + 23) / 3 = 23. The first two periods have no average because three values are not yet available.

What is the difference between SMA, WMA and EMA?

The simple moving average gives every value in the window the same weight. The weighted moving average gives weights 1, 2, ..., k with the newest value weighted most. The exponential moving average weights all earlier values with weights that shrink by the factor 1 - α at every step back, where α = 2 / (k + 1), so it responds quickly to recent changes.

How do I choose the window length?

Trade smoothness against lag: a short window follows the data closely but stays noisy, a long window is smooth but reacts late. If the data repeat every s periods (12 for monthly data with a yearly cycle, 7 for daily data with a weekly one), use s. Otherwise compare the forecast errors of a few window lengths on your own data and pick the one with the lowest error.

Why are the first values blank?

A moving average of length k needs k values, so the first average appears at period k and the first k - 1 periods have none. Some software fills them with an average of the values available so far; this calculator leaves them blank rather than mixing windows of different lengths.

Why does my EMA differ from another calculator or from pandas?

The exponential average needs a starting value and the software does not agree on it. This calculator starts with the simple average of the first k values, as StockCharts and most charting platforms do. pandas with adjust=False and Excel's Exponential Smoothing tool start from the first value, so their early numbers differ and converge to these as the series goes on.

Can a moving average forecast the future?

It gives a one-step-ahead forecast: the latest average predicts the next value. It works for series that fluctuate around a stable level. For a series with a steady trend, a simple moving average forecast is (k + 1) / 2 periods of trend behind, and it cannot predict turning points. The forecast errors shown under the results measure how well the chosen window would have predicted your own data.

What is a centered moving average?

A centered moving average places each average at the middle of its window instead of at the end, so it uses values both before and after the period. It is used to describe past trends and to remove seasonality, but the newest periods have no centered average and it cannot be used for forecasting. This calculator uses trailing windows, as Excel, pandas and charting platforms do by default.

Embed This Calculator

Add this free calculator to your course page or LMS.

Adjust the height value to fit your page.