liveBook · Manning

Exponential moving average

As explained in Statistics Every Programmer Needs

An exponentially weighted moving average is a time-series average that assigns geometrically decreasing weights to older observations.

An exponentially weighted moving average (EWMA) gives recent observations more influence than older ones. It can smooth a time series for short-term forecasting or track a process mean so that small shifts are easier to detect. section 7.4 section 14.3.5

To update an EWMA, combine the current observation with the previous EWMA: new EWMA = λ × current observation + (1 − λ) × previous EWMA. Initialize it with the first measurement. The smoothing constant λ determines how strongly the latest observation affects the result; the contribution of earlier observations diminishes with each update. Simple exponential smoothing uses the same recent-observation emphasis, with a smoothing parameter α between 0 and 1. section 14.3.5 section 7.4.3

For forecasting, choose the smoothing model to match the patterns visible in the series:

  • Simple exponential smoothing (SES) suits data without a clear trend or seasonal pattern. section 7.4.4
  • Double exponential smoothing adds a trend component. section 7.4.6
  • Holt–Winters adds seasonality as well as trend; its additive and multiplicative variations address different seasonal behavior. section 7.4.4
>>> from statsmodels.tsa.holtwinters import SimpleExpSmoothing
>>> ses_model = SimpleExpSmoothing(train).fit()

Fit SES to a time-ordered training series with statsmodels when neither trend nor seasonality is apparent. section 7.4.6

>>> hw_model = ExponentialSmoothing(train,
>>>                                 trend = 'add',
>>>                                 seasonal = 'add',
>>>                                 seasonal_periods = 5).fit()

Fit a Holt–Winters model with additive trend and seasonality. The five-period setting assumes a recurring pattern every five observations; that assumption should be checked against the data. section 7.4.7

Validate forecasts against later observations rather than relying on a smooth-looking fit. In a stock-price example, models are fitted to six months of closing prices and forecast the following month; Holt–Winters and ARIMA are compared using AIC and BIC, then forecasted prices are plotted against actual prices. Stock-price volatility and unpredictable influences limit forecast accuracy. section 7.2.3 section 7.4.7

Figure 14.9 This EWMA chart displays the exponentially weighted moving average of piston ring diameters across 40 samples. The chart shows how the process mean evolves over time, with recent data points having more influence on the chart’s trajectory than older ones. The CL represents the overall EWMA mean, whereas the UCL and LCL indicate the expected range of variation. Data points within these limits suggest the process is under control, whereas any point outside may signal a shift or trend that requires further investigation.
figure

An EWMA chart tracks piston-ring diameters across 40 samples. Its center line and control limits provide context: a crossing may signal a process shift that warrants investigation. section 14.3.5

How Statistics Every Programmer Needs covers it

How deep it goes
Defines decaying weights and recursive EWMA updates, then demonstrates fitted forecasting variants without deriving their parameter optimization.
Examples
Uses Python fits to forecast stock closing prices and an EWMA chart of piston-ring diameters.
What it assumes
Assumes time-ordered observations and introduces the choice among models with no trend, a trend, or seasonality.
What you can do after
Apply it via statsmodels to fit smoothing forecasts, or operate an EWMA chart to investigate potential process shifts.
How it connects
Connects simple exponential smoothing, Holt–Winters forecasting, ARIMA comparison, and control charts.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.