# Exponential weighted moving skewness/kurtosis

There are well-known on-line formulas for computing exponentially weighted moving averages and standard deviations of a process $(x_n)_{n=0,1,2,\dots}$. For the mean,

$\mu_n = (1-\alpha) \mu_{n-1} + \alpha x_n$

and for the variance

$\sigma_n^2 = (1-\alpha) \sigma_{n-1}^2 + \alpha(x_n - \mu_{n-1})(x_n - \mu_n)$

from which you can compute the standard deviation.

Are there similar formulas for on-line computation of exponential weighted third- and fourth-central moments? My intuition is that they should take the form

$M_{3,n} = (1-\alpha) M_{3,n-1} + \alpha f(x_n,\mu_n,\mu_{n-1},S_n,S_{n-1})$

and

$M_{4,n} = (1-\alpha) M_{4,n-1} + \alpha f(x_n,\mu_n,\mu_{n-1},S_n,S_{n-1},M_{3,n},M_{3,n-1})$

from which you could compute the skewness $\gamma_n = M_{3,n} / \sigma_n^3$ and the kurtosis $k_n = M_{4,n}/\sigma_n^4$ but I’ve not been able to find simple, closed-form expression for the functions $f$ and $g$.

Edit: Some more information. The updating formula for moving variance is a special case of the formula for the exponential weighted moving covariance, which can be computed via

$C_n(x,y) = (1-\alpha) C_{n-1}(x,y) + \alpha (x_n - \bar{x}_n) (y_n - \bar{y}_{n-1})$

where $\bar{x}_n$ and $\bar{y}_n$ are the exponential moving means of $x$ and $y$. The asymmetry between $x$ and $y$ is illusory, and disappears when you notice that $y-\bar{y}_n = (1-\alpha) (y-\bar{y}_{n-1})$.

Formulas like this can be computed by writing the central moment as an expectation $E_n(\cdot)$, where weights in the expectation are understood to be exponential, and using the fact that for any function $f(x)$ we have

$E_n(f(x)) = \alpha f(x_n) + (1-\alpha) E_{n-1}(f(x))$

It’s easy to derive the updating formulas for the mean and variance using this relation, but it’s proving to be more tricky for the third and fourth central moments.

The formulas are straightforward but they are not as simple as intimated in the question.

Let $Y$ be the previous EWMA and let $X = x_n$, which is presumed independent of $Y$. By definition, the new weighted average is $Z = \alpha X + (1 - \alpha)Y$ for a constant value $\alpha$. For notational convenience, set $\beta = 1-\alpha$. Let $F$ denote the CDF of a random variable and $\phi$ denote its moment generating function, so that

With Kendall and Stuart, let $\mu_k^{'}(Z)$ denote the non-central moment of order $k$ for the random variable $Z$; that is, $\mu_k^{'}(Z) = \mathbb{E}[Z^k]$. The skewness and kurtosis are expressible in terms of the $\mu_k^{'}$ for $k = 1,2,3,4$; for example, the skewness is defined as $\mu_3 / \mu_2^{3/2}$ where

are the third and second central moments, respectively.

By standard elementary results,

To obtain the desired non-central moments, multiply the latter power series through fourth order in $t$ and equate the result term-by-term with the terms in $\phi_Z(t)$.