There are well-known on-line formulas for computing exponentially weighted moving averages and standard deviations of a process (xn)n=0,1,2,…. For the mean,

μn=(1−α)μn−1+αxn

and for the variance

σ2n=(1−α)σ2n−1+α(xn−μn−1)(xn−μ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

M3,n=(1−α)M3,n−1+αf(xn,μn,μn−1,Sn,Sn−1)

and

M4,n=(1−α)M4,n−1+αf(xn,μn,μn−1,Sn,Sn−1,M3,n,M3,n−1)

from which you could compute the skewness γn=M3,n/σ3n and the kurtosis kn=M4,n/σ4n 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 viaCn(x,y)=(1−α)Cn−1(x,y)+α(xn−ˉxn)(yn−ˉyn−1)

where ˉxn and ˉyn are the exponential moving means of x and y. The asymmetry between x and y is illusory, and disappears when you notice that y−ˉyn=(1−α)(y−ˉyn−1).

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

En(f(x))=αf(xn)+(1−α)En−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.

**Answer**

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

Let Y be the previous EWMA and let X=xn, which is presumed independent of Y. By definition, the new weighted average is Z=αX+(1−α)Y for a constant value α. For notational convenience, set β=1−α. Let F denote the CDF of a random variable and ϕ denote its moment generating function, so that

ϕX(t)=EF[exp(tX)]=∫Rexp(tx)dFX(x).

With Kendall and Stuart, let μ′k(Z) denote the non-central moment of order k for the random variable Z; that is, μ′k(Z)=E[Zk]. The skewness and kurtosis are expressible in terms of the μ′k for k=1,2,3,4; for example, the skewness is defined as μ3/μ3/22 where

μ3=μ′3−3μ′2μ′1+2μ′13 and μ2=μ′2−μ′12

are the third and second central moments, respectively.

By standard elementary results,

1+μ′1(Z)t+12!μ′2(Z)t2+13!μ′3(Z)t3+14!μ′4(Z)t4+O(t5)=ϕZ(t)=ϕαX(t)ϕβY(t)=ϕX(αt)ϕY(βt)=(1+μ′1(X)αt+12!μ′2(X)α2t2+⋯)(1+μ′1(Y)βt+12!μ′2(Y)β2t2+⋯).

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 ϕZ(t).

**Attribution***Source : Link , Question Author : Chris Taylor , Answer Author : whuber*