The Standard Engine.
MathematicsFinanceHealthPhysicsEngineeringBrowse all

Mathematics · Probability & Statistics · Descriptive Statistics

Moving Average Calculator

Computes the simple moving average (SMA) for a dataset over a specified period window, smoothing time-series data to reveal underlying trends.

Calculator

Advertisement

Formula

SMA_t is the simple moving average at time period t. x_{t-i} represents the data value i periods before time t. n is the window size — the number of consecutive data points included in each average. The calculation slides the window forward one period at a time across the full dataset, computing a fresh average at each position. The result is a smoothed series with (n - 1) fewer points than the original dataset.

Source: Chatfield, C. (2004). The Analysis of Time Series: An Introduction. 6th ed. Chapman & Hall/CRC. pp. 10–14.

How it works

A simple moving average works by replacing each data point in a series with the arithmetic mean of itself and the (n − 1) preceding values, where n is the chosen window size. By doing this across the entire series, random fluctuations — sometimes called white noise — are dampened, and the underlying signal or trend becomes more visible. The larger the window, the smoother the resulting curve, but the more lag it introduces and the more leading data points are lost.

The formula is straightforward: at any time t, SMA_t equals the sum of the n most recent observations divided by n. For a window of 3 applied to the series [10, 20, 30, 25, 15], the first SMA value is (10 + 20 + 30) / 3 = 20, the second is (20 + 30 + 25) / 3 = 25, and so on. The result is a new series with (n − 1) fewer points than the original. This trade-off between smoothness and data loss is central to choosing the right window size for your application.

In financial markets, the 50-day and 200-day SMAs are canonical benchmarks — crossovers between them generate widely followed buy and sell signals. In manufacturing, control charts use moving averages to detect process drift. In meteorology, 30-year climate normals are effectively a long-window moving average over annual data. The technique is domain-agnostic: wherever ordered numerical data contains both signal and noise, moving averages provide a first line of exploratory and predictive analysis.

Worked example

Suppose a retail analyst tracks weekly sales figures (in thousands of dollars) over eight weeks: 12, 15, 14, 18, 20, 17, 22, 25. They want to apply a 3-week moving average to smooth out week-to-week variability.

Step 1 — Identify n: Window size n = 3. The SMA series will have 8 − 3 + 1 = 6 values.

Step 2 — Compute each SMA value:

SMA₁ = (12 + 15 + 14) / 3 = 41 / 3 = 13.67

SMA₂ = (15 + 14 + 18) / 3 = 47 / 3 = 15.67

SMA₃ = (14 + 18 + 20) / 3 = 52 / 3 = 17.33

SMA₄ = (18 + 20 + 17) / 3 = 55 / 3 = 18.33

SMA₅ = (20 + 17 + 22) / 3 = 59 / 3 = 19.67

SMA₆ = (17 + 22 + 25) / 3 = 64 / 3 = 21.33

Step 3 — Interpret: The smoothed series rises from 13.67 to 21.33, confirming a clear upward sales trend that was partially obscured by the dip in week 6 (from 20 down to 17). The SMA successfully filtered that short-term fluctuation and revealed the dominant growth pattern.

Limitations & notes

The simple moving average treats all n observations within the window as equally important, giving each a weight of 1/n. In many real-world scenarios — particularly finance — more recent data is more relevant. For such cases, the Exponential Moving Average (EMA) or Weighted Moving Average (WMA) are preferable because they assign exponentially or linearly decreasing weights to older observations. The SMA also introduces lag proportional to its window size: a 20-period SMA will trail the current data by roughly 10 periods. This makes it a poor tool for real-time reaction but an excellent tool for trend confirmation. Additionally, this calculator requires the data series to be entered manually and computes only the first and last SMA values — it does not yet display the full intermediate SMA series. For datasets with missing values, outliers, or irregular sampling intervals, the standard SMA formula may produce misleading results and should be used alongside data cleaning and validation steps. Finally, moving averages are purely descriptive — they do not constitute a forecasting model and should not be extrapolated beyond the data without a proper time-series model such as ARIMA or Holt-Winters.

Frequently asked questions

What is the difference between a simple moving average and an exponential moving average?

A simple moving average (SMA) assigns equal weight (1/n) to each of the n observations in the window. An exponential moving average (EMA) assigns exponentially decreasing weights to older observations, making it more responsive to recent changes. For a 10-period window, the most recent observation receives roughly 18% weight in an EMA versus exactly 10% in an SMA. EMAs are preferred in trading; SMAs are preferred in trend analysis and economic reporting.

How do I choose the right window size for a moving average?

Window size selection depends on your goal. A small window (e.g., 3–5 periods) captures short-term trends with minimal lag but retains more noise. A large window (e.g., 50–200 periods) produces a very smooth curve but introduces significant lag and loses more data points at the start of the series. In practice, window size is often chosen empirically by testing different values and selecting the one that best balances smoothness with responsiveness for the specific dataset and decision context.

Why does the moving average produce fewer values than the original dataset?

Each SMA value requires exactly n data points — the current observation and the preceding (n − 1) observations. For the first SMA value to exist, you need at least n points in the series. This means the first (n − 1) positions in the original series cannot produce an SMA value, resulting in a smoothed series that is (n − 1) points shorter. For example, applying a 5-period SMA to a 20-point series produces 20 − 5 + 1 = 16 SMA values.

Can a moving average be used for forecasting future values?

The SMA is primarily a smoothing and trend-identification tool, not a standalone forecasting model. Naively, the last SMA value is sometimes used as a one-step-ahead forecast (i.e., next period's value is predicted to equal the average of the last n periods), but this approach ignores trends, seasonality, and autocorrelation structure. For serious forecasting, techniques such as ARIMA, Holt-Winters exponential smoothing, or machine-learning time-series models should be used instead.

What does it mean when a short-term moving average crosses above a long-term moving average?

This is called a 'golden cross' in financial analysis. When a short-term SMA (e.g., 50-day) crosses above a long-term SMA (e.g., 200-day), it is interpreted as a bullish signal — suggesting that recent momentum is stronger than the long-run trend and that prices may continue rising. The opposite (short-term crossing below long-term) is called a 'death cross' and is considered bearish. While widely cited, these signals are lagging indicators and should be used in conjunction with other analysis tools.

Last updated: 2025-01-15 · Formula verified against primary sources.