Mathwords logoMathwords

Moving Average — Definition, Formula & Example

A moving average is a sequence of averages, each taken over a fixed number of consecutive data points, that slides forward one step at a time. It smooths out day-to-day ups and downs so the underlying trend is easier to see.

For a time series x1,x2,…,xnx_1, x_2, \ldots, x_n and a window length kk (with 1≤k≤n1 \le k \le n), the kk-period simple (trailing) moving average at time tt is the arithmetic mean of the kk observations ending at tt. It is defined only for t=k,k+1,…,nt = k, k+1, \ldots, n, so it produces n−k+1n - k + 1 values. Each of those kk observations gets weight 1k\tfrac{1}{k}, and every older observation gets weight 0.

Key Formula

MAt=xt+xt−1+⋯+xt−k+1k=1k∑i=0k−1xt−i\text{MA}_t = \frac{x_t + x_{t-1} + \cdots + x_{t-k+1}}{k} = \frac{1}{k}\sum_{i=0}^{k-1} x_{t-i}
Where:
  • MAt\text{MA}_t = the moving average at time period t
  • xtx_t = the data value observed at time period t
  • kk = the window length (number of periods averaged)
  • tt = the current time period, where t is at least k

Worked Example

Problem: A park kiosk rents out 12, 18, 15, 21, 24, and 30 bikes on Days 1 through 6. Find the 3-day moving average for each day where it is defined.
Step 1: The first full 3-day window ends on Day 3. Average Days 1, 2, and 3.
MA3=12+18+153=453=15\text{MA}_3 = \frac{12 + 18 + 15}{3} = \frac{45}{3} = 15
Step 2: Slide the window forward one day. You do not need to re-add everything: drop the oldest value (Day 1) and add the newest value (Day 4).
MA4=45−12+213=543=18\text{MA}_4 = \frac{45 - 12 + 21}{3} = \frac{54}{3} = 18
Step 3: Keep sliding until the window reaches the last day.
MA5=15+21+243=603=20,MA6=21+24+303=753=25\text{MA}_5 = \frac{15 + 21 + 24}{3} = \frac{60}{3} = 20, \qquad \text{MA}_6 = \frac{21 + 24 + 30}{3} = \frac{75}{3} = 25
Answer: The 3-day moving averages are 15, 18, 20, and 25 for Days 3 through 6. The raw rentals drop from 18 to 15 on Day 3, but the moving average rises every day, which reveals a steady upward trend.

Visualization

Why It Matters

News reports use a 7-day moving average of case counts or gas prices so weekend dips do not look like real drops. Stock charts plot 50-day and 200-day moving averages to show long-term price direction. In statistics and data science courses that cover time series, a moving average is often the first tool you use to separate trend from noise. It differs from exponential smoothing, which counts every past value and gives older values gradually smaller weights.

Common Mistakes

Mistake: Computing a 3-day moving average for Day 1 and Day 2, or expecting one average for every data point.
Correction: A window needs k complete values, so the first average appears at Day k. With 6 data points and k = 3, you get 6 − 3 + 1 = 4 averages, not 6.

Related Terms

  • Time Series — The time-ordered data a moving average smooths
  • Average — The single mean computed inside each window
  • Weighted Average — Basis for weighted moving averages favoring recent data
  • Exponential Smoothing — Alternative time series smoothing method weighting recent data more