Exponentially Weighted Moving Average

medium
Unit 13 · Statistics & Time Series0/3 to milestone

An EWMA smooths a noisy series by giving recent points more weight:

s0=x0,st=α xt+(1−α) st−1s_0 = x_0, \qquad s_t = \alpha\, x_t + (1 - \alpha)\, s_{t-1}

Implement ewma(x, alpha) returning a NumPy array the same length as x.

Missing values: if x[t] is NaN, carry the previous smoothed value forward (s_t = s_{t-1}). If the series starts with NaNs, output NaN until the first real value, which becomes the starting point.

Example

ewma([10, 20, 30], alpha=0.5)   # array([10., 15., 22.5])
#time-series#numpy3 visible + 2 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Exponentially Weighted Moving Average · TechGradify