Moving Average: Only Full Windows Count

Time SeriesEasy+10 XP+10

Moving Average: Only Full Windows Count

A moving average smooths a noisy series by replacing each point with the mean of the window values ending there. It's the first tool anyone reaches for in time-series work, and the basis of half the features you'd engineer from a sequence.

Task: write moving_average(series, window) returning a list of floats rounded to 4 decimal places.

Only full windows count. With 5 values and a window of 3 you get 3 averages, not 5 — the first two positions don't have enough history behind them.

  • If window is larger than the series, return an empty list.
  • A window of 1 returns the series unchanged.

Moving Average Smoothing

Raw Data
Moving Average
Window Size (k)5
MA(t) = [y(t-4) + ... + y(t)] / 5
Window
5
Current MA
43.10

Examples

series = [1.0, 2.0, 3.0, 4.0, 5.0]
window = 3
returns [2.0, 3.0, 4.0]
series = [10.0, 20.0]
window = 2
returns [15.0]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run