Time Series • Time Series Analysis and Components
Time Series / P2.03 Moving Average Smoothing

P2.03 Moving Average Smoothing

Practical 2 Time Series Analysis and Components

Apply a 3-month moving average to a noisy monthly series and explain what smoothing does.

Practical / Solution

P2.03 Moving Average Smoothing

Problem Statement

Apply a 3-month moving average to a noisy monthly series and explain what smoothing does.

Learning Outcomes

  • Compute a simple moving average.
  • Explain the purpose and a limitation of smoothing.

Hint

pandas rolling(window=3).mean() is a simple moving average.

Theory

Smoothing reduces short-term fluctuation so the underlying movement is easier to see. A moving average replaces each point by the mean of neighbouring points. It can hide sudden genuine shocks.

Dataset / Data Source

Constructed 12 monthly values with noise. Teaching data.

Analysis / Program

import pandas as pd import matplotlib.pyplot as plt idx = pd.date_range("2025-01-01", periods=12, freq="MS") y = pd.Series([10, 13, 11, 16, 15, 20, 18, 22, 21, 25, 24, 28], index=idx) smooth = y.rolling(window=3, center=True).mean() y.plot(marker="o", label="original") smooth.plot(marker="o", label="3-month MA") plt.legend() plt.title("Moving average smoothing") plt.tight_layout() plt.show() print(pd.DataFrame({"y": y, "ma3": smooth.round(2)}))

Expected Output

A table of original and smoothed values. End points of a centred MA are missing. The smoothed line is less jagged.

Result / Interpretation

The moving average follows the rise but damps month-to-month jumps. Students should notice lost sharpness at turning points.

Note

A moving average reduces short-term fluctuations but may hide sudden changes.