Weighted Moving Average (WMA)

wma(data, weights)

Calculate the weighted moving average of a list of data points using a list of weights.

syse.wma(data, weights)

Calculate the weighted moving average of a list of data points using a list of weights.

Parameters:
  • data (list) – A list of data points.

  • weights (list) – A list of weights to be applied to each data point.

Returns:

The weighted moving average.

Return type:

float

Examples:

Suppose you are a financial analyst, and you want to analyze the stock price of a company over the past 5 days. You have a list of the daily closing prices for the past 5 days, and you believe that the most recent day’s price should be given a higher weight than the previous days. You can use the above Python function to calculate the weighted moving average of the stock prices over the past 5 days, where the weight of the most recent day’s price is 0.5 and the weights of the previous days are 0.3, 0.1, and 0.1 respectively. This information can be useful in determining whether the stock price is trending up or down and making investment decisions accordingly.