Weighted Moving Average

The Weighted Moving Average (WMA), also called the linearly weighted moving average, gives each price a weight that rises linearly from the oldest to the latest price of the window.

The formula for the Weighted Moving Average is as follows:

\[\text{WMA} = \frac{\sum_{i=1}^{n} i \cdot \text{Close}_{i}}{\sum_{i=1}^{n} i}\]

Where \(\text{Close}_{i}\) is the i-th closing price of the window of n periods, from \(i = 1\) for the oldest to \(i = n\) for the latest. The latest price weighs n times as much as the oldest, so the WMA follows the price more closely than the SMA of the same length, and unlike the EMA it forgets a price completely once it leaves the window.

A moving average smooths the price by averaging it over the last n periods, so that the trend shows through the noise of single periods. It is the oldest and most widely used trend indicator: the direction of the average shows the direction of the trend, the price above (below) it an uptrend (downtrend), and other indicators, from the MACD to the Bollinger Bands, are built on it. Every moving average trades smoothness against lag: the more periods it averages, the smoother it is and the later it turns after the price. The averages differ in how they weight the prices within the window and whether they adapt their speed to the market, each a different answer to that trade-off.

Also known as: WMA, linear weighted moving average, linearly weighted moving average.

In the Finance Toolkit this is get_moving_average with method="weighted", the same function as Moving Average.

Example · ^GSPC · 2021 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_moving_average:

from financetoolkit import Toolkit

toolkit = Toolkit(
    tickers=["^GSPC"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.technicals.get_moving_average(method="weighted", window=50)

Which returns:

References

  • Paper Murphy, J.J. (1999). “Technical Analysis of the Financial Markets.” New York Institute of Finance.
  • Paper Achelis, S.B. (2000). “Technical Analysis from A to Z.” 2nd edition, McGraw-Hill.
  • Library Referenced against TA-Lib’s WMA (Weighted Moving Average)
  • Library Referenced against TA-Lib’s VWMA (Volume Weighted Moving Average)
  • Library Referenced against pandas-ta-classic’s vwma (Volume Weighted Moving Average)
  • Library Referenced against pandas-ta-classic’s sinwma (Sine Weighted Moving Average)
  • Library Referenced against pandas-ta-classic’s fwma (Fibonacci Weighted Moving Average)
  • Library Referenced against pandas-ta-classic’s pwma (Pascal Weighted Moving Average)
  • Library Referenced against finta’s EVWMA (Elastic Volume Weighted Moving Average)
  • Library Shares similar logic as Tulip Indicators’ vwma (Volume Weighted Moving Average)
Share