Loading...
Loading...
Compute Simple (SMA), Exponential (EMA), and Weighted (WMA) moving averages. Compare smoothing methods with interactive charts and Python pandas code.
Calculate SMA and EMA for stock prices over 7 days with a 5-period window.
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.