Exponential Moving Average

Standard Definition

The standard definition would be an expression of the form

EMA(t)=c∑k=s..tαt−kp(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(t−1)EMA(t) = cp(t) + \alpha EMA(t-1)

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

EMA(t)=cp∑k=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(t−1)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 ….