# Moving Average/Weighted

## Mathematical Definition: Weighted moving average

In technical analysis of financial data, a weighted moving average (WMA) has the specific meaning of weights that decrease in arithmetical progression.[1] In an n-day WMA the latest day has weight n, the second latest n − 1, etc., down to one. These weights create a discrete probability distribution with:

${\displaystyle s(n):=n+(n-1)+\dots +1={\frac {n\cdot (n+1)}{2}}}$ and ${\displaystyle p_{t}(x)={\begin{cases}{\frac {n-(t-x)}{s(n)}}&\mathrm {for} \ 0\leq t-n\leq x\leq t,\\[8pt]0&\mathrm {for} \ xt\end{cases}}}$

The weighted moving average can be calculated for ${\displaystyle t\geq n}$ with the discrete probability mass function ${\displaystyle p_{t}}$ at time ${\displaystyle t\in \mathbb {N} _{0}:=\{0,1,2\dots ,\}}$, where ${\displaystyle t=0}$ is the initial day, when data collection of the financial data begins and ${\displaystyle C(0)}$ the price/cost of a product at day ${\displaystyle t=0}$. ${\displaystyle C(x)}$ the price/cost of a product at day ${\displaystyle x\in \mathbb {N} _{0}}$ for an arbitrary day x.

${\displaystyle {\text{WMA}}(t):=\sum _{x\in T=\mathbb {N} _{0}}p_{t}(x)\cdot C(x)=\sum _{x=t-n+1}^{t}p_{t}(x)\cdot C(x)={\frac {n\cdot C(t)+(n-1)\cdot C(t-1)+\cdots +2\cdot C(t-n+2)+1\cdot C(t-n+1)}{n+(n-1)+\cdots +2+1}}}$

The denominator is a triangle number equal to ${\displaystyle {\frac {n(n+1)}{2}}}$ which creates a discrete probability distribution by:

${\displaystyle {\frac {1}{s(n)}}+{\frac {2}{s(n)}}+\ldots +{\frac {n}{s(n)}}={\frac {1+2+\ldots +n}{s(n)}}={\frac {s(n)}{s(n)}}=1}$

The graph at the right shows how the weights decrease, from highest weight at day t for the most recent datum points, down to zero at day t-n.

In the more general case with weights ${\displaystyle w_{0},\ldots ,w_{n}}$ the denominator will always be the sum of the individual weights, i.e.:

${\displaystyle s(n):=\sum _{k=0}^{n}w_{k}}$ and ${\displaystyle w_{0}}$ as weight for for the most recent datum points at day t and ${\displaystyle w_{n}}$ as weight for the day ${\displaystyle t-n}$, which is n-th day before the most recent day ${\displaystyle t}$.

The discrete probability distribution ${\displaystyle p_{t}}$ is defined by:

${\displaystyle p_{t}(x)={\begin{cases}{\frac {w_{t-x}}{s(n)}}&\mathrm {for} \ 0\leq t-n\leq x\leq t,\\[8pt]0&\mathrm {for} \ 0\leq xt\end{cases}}}$

The weighted moving average with arbitrary weights is calculated by:

${\displaystyle {\text{WMA}}(t):=\sum _{x\in T=\mathbb {N} _{0}}p_{t}(x)\cdot C(x)=\sum _{x=t-n}^{t}p_{t}(x)\cdot C(x)={\frac {w_{0}\cdot C(t)+w_{1}\cdot C(t-1)+\cdots +w_{n-1}\cdot C(t-n+1)+w_{n}\cdot C(t-n)}{w_{0}+\cdots +w_{n-1}+w_{n}}}}$

This general approach can be compared to the weights in the exponential moving average in the following section.

1. "Weighted Moving Averages: The Basics". Investopedia.