Exponential Moving Average

Standard Definition

The standard definition would be an expression of the form

EMA(t)=ck=s..tαtkp(k)EMA(t) = c \sum_{k=s..t} \alpha^{t-k} p(k)

which can be expressed as the update rule

EMA(t)=cp(t)+αEMA(t1)EMA(t) = cp(t) + \alpha EMA(t-1)

If p(t)=p and s = 0, then

EMA(t)=cpk=0..tαk=cp1αt+11αcp1αEMA(t) = cp \sum_{k=0..t} \alpha^k = cp \frac{1-\alpha^{t+1}}{1-\alpha} \rightarrow \frac{cp}{1-\alpha}

To ensure the EMA is asymptotically unbiased with constant price, choose c = 1-\alpha and define the update rule as

EMA(t)=(1α)p(t)+αEMA(t1)EMA(t)=(1-\alpha)p(t) + \alpha EMA(t-1)

Implementation

Using a floating-point implementation,

double alpha;
double ema = 0.0;
ema = p + alpha * (ema - p);

This approach may not be suitable for high-frequency applications, due to jitter. Instead fixed point integer arithmetic might be used.

Navigation

About

Raedwulf ….