BRAGA

02 Writing02-02 Notes02-02-524

Simple Moving Average, SMA

Published 16 Apr 202611 min read
Contents
  1. 01Deep Breakdown
  2. 02Why it is called “moving”
  3. 03Why the smoothing happens Averaging reduces short-term fluctuations. Random spikes and dips tend to cancel each other out, so the resulting series becomes smoother than the original.
  4. 04What the window size does
  5. 05SMA as a forecasting baseline
  6. 06Relation to trend and lag SMA helps reveal trend, but it also introduces lag.
  7. 07Relation to EMA SMA is closely related to the Exponential Moving Average, EMA.
  8. 08DA/DS relevance
  9. 09Flowchart
  10. 10Real-world use
  11. 11The formula, piece by piece
  12. 12The formula in words
  13. 13Critical Concepts
  14. 14Step-by-step calculation (tiny example)
  15. 15Code examples
  16. 16Self-check: mathematical verification
  17. 17Re-derivation from the rolling-average idea
  18. 18Window-size special-case check If w=1w=1, then
  19. 19Three-period expansion check
  20. 20Domain check To compute
  21. 21Unit check
  22. 22Verbal-to-algebra consistency
  23. 23Structural verification
  24. 24Common Pitfalls and Edge Cases
  25. 25References and Standard Results
SMAt=1w∑i=t−w+1txi\mathrm{SMA}_t=\frac{1}{w}\sum_{i=t-w+1}^{t}x_i
(1)

We are working on the Simple Moving Average, SMA, defined by

SMAt=1w∑i=t−w+1txi,\mathrm{SMA}_t=\frac{1}{w}\sum_{i=t-w+1}^{t}x_i,
(2)

where ww is the window length and xix_i are the observed time-series values. This is a time-series smoothing method that averages the most recent ww observations to reduce short-run noise and reveal underlying movement. It is widely used as a baseline tool for trend inspection, demand smoothing, KPI monitoring, and simple forecasting.

Deep Breakdown

A Simple Moving Average is one of the most basic and useful tools in time-series analysis. The core idea is straightforward: > Instead of looking at one raw observation at a time, average the most recent few observations so the series becomes smoother. This helps when a time series is noisy. Many business metrics jump up and down from period to period because of random variation, promotions, reporting quirks, seasonality fragments, or operational noise. The underlying pattern may be hard to see in the raw series. The Simple Moving Average reduces that noise by replacing each point with the average of the most recent ww values.

The formula is:

SMAt=1w∑i=t−w+1txi\mathrm{SMA}_t=\frac{1}{w}\sum_{i=t-w+1}^{t}x_i
(3)

This means:

  • choose a window size ww,
  • take the last ww observed values ending at time tt,
  • add them,
  • divide by ww.

So the SMA at time tt is the average of the most recent ww values.

Why it is called “moving”

It is called a moving average because the averaging window moves forward through time.

For example, if w=3w=3:

  • at time 3, average x1,x2,x3x_1,x_2,x_3,
  • at time 4, average x2,x3,x4x_2,x_3,x_4,
  • at time 5, average x3,x4,x5x_3,x_4,x_5.

So the window keeps sliding forward one period at a time.

Why the smoothing happens Averaging reduces short-term fluctuations. Random spikes and dips tend to cancel each other out, so the resulting series becomes smoother than the original.

This is useful for:

  • visualizing trend,
  • building a simple baseline forecast,
  • reducing short-run volatility in dashboards,
  • monitoring demand or performance over time.

What the window size does

The window size ww controls the tradeoff between:

  • smoothness,
  • responsiveness.

If ww is small:

  • the SMA reacts more quickly to new changes,
  • but it remains noisier.

If ww is large:

  • the SMA becomes smoother,
  • but it reacts more slowly to turning points.

This is one of the main practical decisions when using an SMA.

SMA as a forecasting baseline

A common simple forecast is to use the most recent moving average as the next-period forecast:

x^t+1=SMAt\hat{x}_{t+1}=\mathrm{SMA}_t
(4)

This is often used as a naive but reasonable benchmark, especially when the series is fairly stable and does not have strong trend or seasonality.

Relation to trend and lag SMA helps reveal trend, but it also introduces lag.

Because it averages past values, the SMA reacts after the real series has already moved. This is important in operations and business dashboards. A rapidly changing process may look smoother, but also slower to respond. So SMA is useful for signal extraction, but not perfect for fast-moving environments.

  • SMA gives equal weight to each of the last ww observations.
  • EMA gives more weight to recent observations and less to older ones.

So SMA is simpler and easier to interpret, while EMA is often more responsive.

DA/DS relevance

In DA/DS practice, SMA is used in:

  • demand smoothing,
  • KPI trend tracking,
  • rolling averages in dashboards,
  • baseline forecasting,
  • anomaly context detection,
  • operations monitoring.

For example, a business analyst may compare daily sales to a 7-day SMA to separate real trend from day-to-day noise.

Flowchart

Start withtime-seriesvalues x_1, x_2,..., x_tChoose windowsize wSelect the last wobservationsending at time tSum theselected valuesDivide by wCompute SMA_tUse SMA forsmoothing, trendview, or simpleforecast

Real-world use

Where it is used

SMA is used in time-series dashboards, operations reporting, sales tracking, demand smoothing, traffic monitoring, financial charts, and baseline forecasting.

Problem it solves

It solves the problem that raw time-series data are often noisy and hard to interpret. Single-period values can move up and down in ways that obscure the underlying pattern.

How it solves the problem

It replaces each point with the average of the most recent ww observations. This reduces short-term noise and makes medium-run movement easier to see.

Example in a business

Suppose a retail team tracks daily orders. Raw daily demand is volatile because of weekday effects, promotions, and random fluctuation. A 7-day SMA smooths this noise and helps the analyst see whether demand is broadly rising, stable, or falling. It can also serve as a simple next-day forecast benchmark.

The formula, piece by piece

Symbol Meaning
SMAt\mathrm{SMA}_t Simple Moving Average at time tt
ww Window size, number of recent observations included
xix_i Observed value at time ii
tt Current time index
x^t+1\hat{x}_{t+1} Next-period forecast using the latest SMA

Canonical formula:

SMAt=1w∑i=t−w+1txi\mathrm{SMA}_t=\frac{1}{w}\sum_{i=t-w+1}^{t}x_i
(5)

Expanded example for window w=3w=3:

SMAt=xt−2+xt−1+xt3\mathrm{SMA}_t=\frac{x_{t-2}+x_{t-1}+x_t}{3}
(6)

Forecasting baseline form:

x^t+1=SMAt\hat{x}_{t+1}=\mathrm{SMA}_t
(7)

Domain requirement:

t≥wt \ge w
(8)

because at least ww observations are needed to compute the full windowed average.

The formula in words

Take the most recent ww observations ending at time tt. Add them together. Then divide by ww. That gives the average of the last ww values, which is the Simple Moving Average at time tt. So the SMA is a rolling mean of recent history.

Critical Concepts

  • SMA smooths noise. It helps reveal medium-run movement by averaging recent observations.
  • The window size controls responsiveness. Small windows react faster; large windows smooth more.
  • SMA uses equal weights. Every observation inside the window counts the same.
  • SMA introduces lag. Because it depends only on past values, it responds after the true movement has started.
  • SMA is a baseline, not a full forecasting model. It is useful but limited when strong trend or seasonality exists.
  • You need at least ww observations to compute a full SMA. Early periods may be undefined or handled separately.
  • SMA differs from EMA. EMA puts more weight on recent values, while SMA uses equal weights.

Step-by-step calculation (tiny example)

Suppose a business tracks daily demand:

x1=10,x2=12,x3=14,x4=20,x5=16x_1=10,\quad x_2=12,\quad x_3=14,\quad x_4=20,\quad x_5=16
(9)

Let the window size be:

w=3w=3
(10)

We want to compute the SMA at time:

t=5t=5
(11)

Step 1, identify the last 3 observations ending at time 5 These are

x3=14,x4=20,x5=16x_3=14,\quad x_4=20,\quad x_5=16
(12)

Step 2, add them

14+20+16=5014+20+16=50
(13)

Step 3, divide by the window size

SMA5=503≈16.67\mathrm{SMA}_5=\frac{50}{3}\approx 16.67
(14)

Interpretation The 3-period moving average at time 5 is about 16.67.

Compute the previous SMA too At time 4

SMA4=x2+x3+x43=12+14+203=463≈15.33\mathrm{SMA}_4=\frac{x_2+x_3+x_4}{3}=\frac{12+14+20}{3}=\frac{46}{3}\approx 15.33
(15)

So the smoothed series is rising from 15.33 to 16.67.

Tiny plain-language reading

The raw value at time 5 is 16, but the recent 3-period average is about 16.67, which gives a smoother view of recent demand.

Code examples

Beginner friendly Example [Python])

python
# Simple Moving Average with window size 3
values = [10, 12, 14, 20, 16]
window_size = 3
last_window = values[-window_size:]
sma_t = sum(last_window) / window_size
print("Last window:", last_window)
print("SMA:", sma_t)

Explanation :

  • values[-window_size:] selects the last w observations.
  • sum(...) / window_size computes their average.
  • This is the direct implementation of the SMA formula.

Beginner friendly Example [R])

r
# Simple Moving Average with window size 3
values <- c(10, 12, 14, 20, 16)
window_size <- 3
last_window <- tail(values, window_size)
sma_t <- sum(last_window) / window_size
cat("Last window:", last_window, "\n")
cat("SMA:", sma_t, "\n")

Explanation :

  • tail(values, window_size) extracts the most recent window.
  • Dividing the sum by window_size gives the rolling average.

Final Professional Example [Python])

markdown
from __future__ import annotations from dataclasses import dataclass
from typing import Sequence RANDOM_SEED = 42 @dataclass(frozen=True)
class TimeSeriesWindow: values: Sequence[float] window_size: int def validate(self) -> None: if len(self.values) == 0: raise ValueError("At least one time-series value is required.") if self.window_size <= 0: raise ValueError("window_size must be greater than 0.") if self.window_size > len(self.values): raise ValueError("window_size cannot exceed the number of observed values.") def simple_moving_average(values: Sequence[float], window_size: int) -> list[float]: if len(values) == 0: raise ValueError("At least one time-series value is required.") if window_size <= 0: raise ValueError("window_size must be greater than 0.") if window_size > len(values): raise ValueError("window_size cannot exceed the number of observed values.") sma_values = [] for end_index in range(window_size - 1, len(values)): start_index = end_index - window_size + 1 window = values[start_index:end_index + 1] sma_values.append(sum(window) / window_size) return sma_values def summarize_sma(series: TimeSeriesWindow) -> None: series.validate() sma_values = simple_moving_average(series.values, series.window_size) print("Simple Moving Average summary") print("-" * 72) print(f"Values: {list(series.values)}") print(f"Window size: {series.window_size}") print("-" * 72) for offset, sma_value in enumerate(sma_values, start=series.window_size): print(f"SMA at time t={offset}: {sma_value:.4f}") print("-" * 72) print(f"Latest SMA (baseline next forecast): {sma_values[-1]:.4f}") def main() -> None: # Daily orders example series = TimeSeriesWindow( values=[102, 108, 99, 115, 121, 118, 125, 130, 127, 133], window_size=3, ) summarize_sma(series) if __name__ == "__main__": main()

What this professional example teaches:

  1. SMA is computed repeatedly across a rolling window.
  2. The first valid SMA appears only once enough observations exist.
  3. The latest SMA can be used as a simple baseline forecast.

This is useful in demand monitoring, KPI smoothing, and dashboard trend analysis.

Self-check: mathematical verification

Re-derivation from the rolling-average idea

Suppose we want the average of the last ww observed values ending at time tt.

Those values are:

xt−w+1,xt−w+2,…,xtx_{t-w+1}, x_{t-w+2}, \dots, x_t
(16)

The arithmetic mean of those ww values is:

1w(xt−w+1+xt−w+2+⋯+xt)\frac{1}{w}\left(x_{t-w+1}+x_{t-w+2}+\cdots+x_t\right)
(17)

Using summation notation, this becomes:

SMAt=1w∑i=t−w+1txi\mathrm{SMA}_t=\frac{1}{w}\sum_{i=t-w+1}^{t}x_i
(18)

This matches the canonical formula exactly.

Window-size special-case check If w=1w=1, then

SMAt=11∑i=ttxi=xt\mathrm{SMA}_t=\frac{1}{1}\sum_{i=t}^{t}x_i=x_t
(19)

So a 1-period moving average equals the original series. This is consistent.

Three-period expansion check

If w=3w=3, then the general formula becomes:

SMAt=13∑i=t−2txi\mathrm{SMA}_t=\frac{1}{3}\sum_{i=t-2}^{t}x_i
(20)

which expands to:

SMAt=xt−2+xt−1+xt3\mathrm{SMA}_t=\frac{x_{t-2}+x_{t-1}+x_t}{3}
(21)

This matches the expanded form given above.

Domain check To compute

SMAt=1w∑i=t−w+1txi\mathrm{SMA}_t=\frac{1}{w}\sum_{i=t-w+1}^{t}x_i
(22)

we need the earliest index in the sum to exist.

Therefore:

t−w+1≥1t-w+1 \ge 1
(23)

which rearranges to:

t≥wt \ge w
(24)

So the requirement that at least ww observations exist is correct.

Unit check

If xix_i is measured in units, dollars, tickets, or customers, then summing values keeps those same units, and dividing by the dimensionless count ww leaves the units unchanged. So SMA has the same units as the original series. This is consistent.

Verbal-to-algebra consistency

The verbal explanation says SMA is the average of the most recent ww values and is used to smooth time-series noise. The formula computes exactly that rolling mean.

Structural verification

  • Opening restatement paragraph is present.
  • All required sections are present and non-empty.
  • Block equations use `
......
(25)

`.

  • Symbol-table entries use math mode such as $\mathrm{SMA}_t$, $w$, $x_i$, and $\hat{x}_{t+1}$.
  • Mermaid uses flowchart TD and node text in ["..."].
  • Three code blocks are present: Python beginner, R beginner, Python professional.
  • Links to EMA, forecasting, demand smoothing, and KPI trends are explicitly included.
  • No placeholder text remains.

Common Pitfalls and Edge Cases

  • Choosing the wrong window size: Too small keeps too much noise; too large creates too much lag.
  • Comparing SMA values with raw points without noting lag: The moving average is smoother but slower to respond.
  • Using SMA for strongly seasonal series without adjustment: A simple window may blur important seasonal structure.
  • Ignoring missing values: Gaps in the time series can distort rolling averages if not handled carefully.
  • Mixing centered and trailing averages: This file uses a trailing SMA ending at time tt.
  • Using SMA as if it were a full forecasting model: It is a baseline smoother, not a rich model of dynamics.
  • Forgetting that the first w−1w-1 periods may not have a full SMA: Early values need explicit handling.
  • Assuming equal weighting is always desirable: Sometimes EMA is preferable because it responds faster to new information.

References and Standard Results

  • Simple Moving Average definition, SMA∗t=1w∑∗i=t−w+1txi\mathrm{SMA} *t=\frac{1}{w}\sum* {i=t-w+1}^{t}x_i
  • Rolling-window arithmetic mean interpretation
  • Trailing-window form for time-series smoothing
  • Window-size tradeoff between smoothness and responsiveness
  • Baseline forecast relation, x^t+1=SMAt\hat{x}_{t+1}=\mathrm{SMA}_t
  • Distinction between SMA and EMA
  • Use of rolling averages in demand and KPI monitoring

#economics-business#population-and-labor-force-metrics#time-series-and-forecasting

Keyboard shortcuts

Single keys, ignored while typing in a field or with Cmd, Ctrl or Alt held.

0
Home
1 2 3 4
Work, Writing, Tools, About
j / k
Next / previous section on this page
n / p
Next / previous project or essay
u
Up one level
l
Deutsch
t
Light or dark theme
?
This list
Esc
Close