liveBook · Manning

Weighted moving average

As explained in Investing for Programmers

A weighted moving average is a moving average that assigns explicitly specified, typically linearly varying weights to observations in its time window.

A weighted moving average (WMA) smooths price data over a rolling window while giving observations different, explicitly specified weights. With linear weighting, newer prices receive greater weight than older prices, making the WMA more responsive than a simple moving average (SMA) and less exponential than an EMA. section 10.2.2

Use WMAs as part of a broader technical-analysis workflow:

  • Choose a rolling window, such as 3 or 20 trading days. section 10.2.2
  • Compare the WMA with SMA, EMA, or HMA according to the desired balance between responsiveness, smoothness, and lag. section 10.2.2 section 10.4
  • Treat faster signals as analytical inputs rather than guarantees; differences between averages can become material in large transactions. section 10.2.2

Computing a WMA in pandas

For a window of n prices, create weights 1 through n, take their dot product with each rolling price window, and divide by the sum of the weights. The final price therefore receives the largest linear weight. A reusable implementation can then add WMA columns alongside SMA, EMA, and HMA columns for historical closing prices.

How Investing for Programmers covers it

How deep it goes
Defines linear weighting and provides a rolling dot-product implementation, while deferring detailed mathematical derivation.
Examples
Demonstrates rolling WMA calculations, comparative average columns, NVIDIA closing prices, and multiple time-window outputs.
What it assumes
Assumes familiarity with rolling windows and closing-price data while introducing weighted-average comparisons and implementation.
What you can do after
Build it from scratch with pandas and NumPy, then compare its responsiveness with other moving-average calculations.
How it connects
Connects weighted moving averages with simple, exponential, Hull, ribbon, Bollinger Bands, and MACD analysis.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Investing for Programmers. The section links point to the parts of the book it draws on.