|
the EMA formula ... continuation of Part I
|
In Part I we got us several magic formulas, for moving averages.
If the last N values are P1, P2, ... PN
(where PN is the most recent), then we have:
| [SMA] SMA(N)
| = (1/N) (P1 + P2 + ... + PN )
|
The Simple Moving Average with all weights equal.
| [WMA] WMA(N)
| = (2/N(N+1)) ( P1 + 2P2 + ... + N PN )
| | = WMA(N-1) + 2/(N+1){PN - SMA(N-1)}
|
A Weighted Moving Average with weights proportional to 1, 2, 3, ... N
and the largest weight is attached to the most recent value, PN
| [EMA] EMA(N)
| = (1 - α) (PN + αPN-1 + α2PN-2 + ... )
| | = α EMA(N-1) + β PN
|
An Exponentially Weighted Moving Average with weights proportional to 1, α, α2, ...
where 0 < α < 1 and β = 1 - α
and the largest weight is attached to the most recent value, PN
>Doesn't that EMA thing stop after N values?
In part I we ignored αN which implies that we consider a weighted average of an infinite number of past values.
It's like Figure 1:
- The new EMA is a combination of the old EMA and the new P ... as in Figure 1.
- At each step we feed back the new EMA to combine with the latest P to generate a new new EMA.
- This ritual goes on forever
|  Figure 1
|
>Forever?
Well, yes ... back to the creation of the universe amd forward until your coffee break.
However, since the powers of α get smaller and smaller, ancient values have little effect on the EMA.
Note the following:
- EMA(N) / PN = α (PN-1 / PN) (EMA(N-1) / PN-1) + β
- So Y(N) = α Y(N-1) / gN-1 + β
where Y(N) = EMA(N) / PN and gN-1 = PN / PN-1 is the gain factor from day N-1 to day N.
- Then
| Y(N)
| = [α/gN-1] [ α Y(N-2) / gN-2 + β ] + β
= α2 Y(N-2) / gN-1gN-2 + αβ/gN-1 + β
| | | = [α2/gN-1gN-2] [ α Y(N-3) / gN-3 + β] + αβ/gN-1 + β
= α3 Y(N-2) / gN-1gN-2gN-3 + α2β/gN-1gN-2 + αβ/gN-1 + β
| | | ... and, for sanitary reasons, we now put gN-1gN-2gN-3...gN-k = Gk, the gain factor over the previous k values
| | | = αN Y(1) / GN + αN-1β/GN-1 + ... + α2β/G2 + αβ/G1 + β
|
For N ∞ (and we go back to the big bang)
, then αN 0 and we get (eventually):
Y(N) = β ( 1 + α/ G1 + α2/ G2 + α3/ G3 + ... )
>zzzZZZ
Wait! Don't you recognize that?
Remember the magic SUM:
gMS = I1/G1 + I2/G2 +
I3/G3 + ...
The value of Y(N) = EMA(N) / PN behaves like that gMS,
except that, instead of cumulative inflation Ik, we have the cumulative effects of βαk.
And do you remember what we thought of the gMS distribution?
We thought it was a lognormal distribution, something like Figure 2A.
>Huh? But what about the distribution of Ys?
Well, if I generate 10,000 values for P (using a normally distributed set of returns),
and the corresponding 10,000 values for Y = EMA/P (with α = 0.9), I get something like Figure 2B.
>Looks lognormal to me.
Yeah. To me, too.
>Is that useful?
I don't think so ... but it's interesting, no?
>No! Besides, weren't you trying to find a "best" α?
Oh, yes ... I was having so much fun, I almost forgot.
|  Figure 2A
 Figure 2B
|
|
Why α = 1 - 2/(N+1) ? ... in the EMA formula
|
Recall the formulas for:
| [WMA] WMA(N)
| = (2/N(N+1)) ( P1 + 2P2 + ... + N PN )
|
where the coefficient of PN-k is: WWMA(k) = 2(N-k)/N(N+1)
and
| [EMA] EMA(N)
| = (1 - α) (PN + αPN-1 + α2PN-2 + ... )
|
where the coefficient of PN-k is: WEMA(k) = αk(1 - α)
and, for the "standard" EMA formula: α = 1 - 2/(N+1)
For k = 0 (giving the weight for the "current" price), the two coefficients are:
2/(N+1) and (1 - α)
These are equal if α = 1 - 2/(N+1)
>Is that the "best" choice?
Well, if you really wanted EMA to match WMA, perhaps you could do better.
Note that the WMA weight is 0 when k = N ... giving the weight for the price N days ago.
>Why would you want EMA to match WMA?
I have no idea.
>So ... what's the "best" choice?
Define "best".
|  Figure 3
|
|