Loading...
Loading...
Compute Simple (SMA), Exponential (EMA), and Weighted (WMA) moving averages. Compare smoothing methods with interactive charts and Python pandas code.
SMAt = (1/n) · Σi=0n-1 xt-i
Equal weight (1/n) for all n values in the window. Simple to compute but lags behind rapid changes.
EMAt = α · xt + (1 - α) · EMAt-1 where α = 2/(n+1)
Recent values get exponentially higher weight. The smoothing factor α controls responsiveness.
WMAt = Σ(wᵢ · xt-n+1+i) / Σwᵢ where wᵢ = i+1
Linearly increasing weights: oldest value gets weight 1, newest gets weight n. More responsive than SMA but less than EMA.
SMA gives equal weight to all values in the window. EMA gives exponentially more weight to recent values using a decay factor α = 2/(n+1). WMA assigns linearly increasing weights (1, 2, 3, ..., n). EMA reacts fastest to changes, SMA is smoothest, WMA is in between.
Larger windows produce smoother curves but lag more behind the data. Common choices: 5-day and 20-day for stock trading, 7-day for weekly patterns, 12-month for annual seasonality. Use MAE/RMSE to compare different window sizes for forecasting accuracy.
A golden cross occurs when the short-term MA (e.g., 50-day) crosses above the long-term MA (e.g., 200-day), signaling a potential uptrend. A death cross is the opposite - short-term crosses below long-term, signaling a potential downtrend.
Moving averages are lagging indicators - they smooth past data and reveal trends, but they don't predict future values. For forecasting, use the last MA value as a simple forecast, or combine with other methods like exponential smoothing (Holt-Winters) or ARIMA.
EMA assigns exponentially decaying weights - the most recent value gets weight α = 2/(n+1), the next gets α(1-α), then α(1-α)², etc. This means recent data points have much more influence than older ones, making EMA more responsive to changes compared to SMA where all points are equally weighted.