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 and a window length (with ), the -period simple (trailing) moving average at time is the arithmetic mean of the observations ending at . It is defined only for , so it produces values. Each of those observations gets weight , and every older observation gets weight 0.
Key Formula
Where:
- = the moving average at time period t
- = the data value observed at time period t
- = the window length (number of periods averaged)
- = 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.
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).
Step 3: Keep sliding until the window reaches the last day.
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.
