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. 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:
 * $$s(n):=n+(n-1)+\dots+ 1 = \frac{n\cdot (n+1)}{2}$$ and $$

p_t(x)=\begin{cases} \frac{n-(t-x)}{s(n)} & \mathrm{for}\ 0 \le t-n \le x \le t, \\[8pt] 0 & \mathrm{for}\ xt \end{cases} $$ The weighted moving average can be calculated for $$t \ge n$$ with the discrete probability mass function $$p_t$$ at time $$t \in \N_0 := \{0,1,2\dots,\}$$, where $$t=0$$ is the initial day, when data collection of the financial data begins and $$C(0)$$ the price/cost of a product at day $$t=0$$. $$C(x)$$ the price/cost of a product at day $$x \in \N_0$$ for an arbitrary day x.
 * $$\text{WMA}(t):= \sum_{x \in T=\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 $$\frac{n(n+1)}{2}$$ which creates a discrete probability distribution by:
 * $$\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 $$w_0,\ldots, w_n$$ the denominator will always be the sum of the individual weights, i.e.:
 * $$s(n):= \sum_{k=0}^{n} w_k$$ and $$w_0$$ as weight for for the most recent datum points at day t and $$w_n$$ as weight for the day $$t-n$$, which is n-th day before the most recent day $$t$$.

The discrete probability distribution $$p_t$$ is defined by:

p_t(x)=\begin{cases} \frac{w_{t-x}}{s(n)} & \mathrm{for}\ 0 \le t-n \le x \le t, \\[8pt] 0 & \mathrm{ for }\ 0 \le x < t-n\ \mathrm{ or } \ x>t \end{cases} $$ The weighted moving average with arbitrary weights is calculated by:
 * $$\text{WMA}(t):= \sum_{x \in T=\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.