Exponential Moving Averages

The exponential moving average (EMA) is a way of recursively calculating the average, emphasizing most recent data more than older data. The EMA, by the way, is a mathematical realization of real filters. Simple averages can only be calculated, they cannot be generated in physically realizable filters. The equation for the EMA is

In words, this equation says that today's EMA is formed by taking a fraction of today's data and adding it to the compliment of the fraction multiplying yesterday's EMA. The equation is convergent when K is less than one because if the data input becomes constant, the value of the EMA approaches that constant. Consider the case where all the new samples are unity. The EMA starts with a zero value, and gradually builds up to almost unity. When this occurs the equation for the NEW EMA is approximately

Since the EMA is a kind of moving average, it is also a low-pass filter. A common way to characterize filters is by their impulse response. An impulse is a mathematical function that is infinitely high and has zero width. The height approaches infinity and the width approaches zero in such a way that the area of the conceptual rectangle is unity. Applying the impulse to the input of a filter is similar to striking a bell and listening for it to ring out. The impulse function is zero everywhere in time except at time equal zero.

Consider multiplying the impulse by \/K, and using this value of the impulse to be the input to our EMA filter. We will assess the impulse response of the EMA using discrete time intervals. The initial output of the EMA filter is unity because there is no old EMA. The EMAl after the first sample is (1 - K) because the old EMA value was unity and there is no new sample. Similarly EMA2 is (1 -K)2 because the old EMA value was (1 - K) and there is no new sample. As shown in Figure 4-4, the

TIME INCREMENTS Figure 4-4 EMA Filter Impulse Response decay of the response to the impulse falls as the exponent of the trial. That is, the EMA has an exponential decay. Now it's easy to see how the exponential moving average got its name. The rate of the decay depends on the K factor.

We can derive the equivalence between an EMA and a SMA using a specific value of K. To do this, we first equate the finite impulse response to an exponential for the Nth sample as

where a is a constant to be found.

Taking the natural logarithm of both sides of this equation, we have

Expanding the natural logarithm to an infinite series we have ln(l -K) = -K- K2/2 - K3/3 - K*/4

When K is small, we can ignore all but the first term, and equating ln(l - K) in the preceding two equations, we have the result that

Since N is proportional to time, the impulse response of the EMA filter is just r{-Kt). The Fourier transform (the frequency response) of an exponential function, normalized for unity transfer response at zero frequency, is

where W - 2 * Pi * frequency j - imaginary operator, a 90-degree shift H(W)- 1/(1 -f jW/K).

We note that the X in the sin(X)/X SMA function is Pi times the frequency times the SMA period. In the EMA frequency response the variable is 2 * Pi times the frequency normalized to K. Equating the frequency variables, we have

Pi • F * Window - 2 * Pi * F/K Performing the algebra, we obtain the result that

The amplitude response of the EMA as a function of frequency is compared with the amplitude response of the SMA in Figure 4-5. Equivalence between the SMA and EMA is subject to definition. For example, if we force the amplitude response of the two filters to be the same when half the cycle period is equal

Exponential Moving Average Response
NORMALIZED FREQUENCY Figure 4-5 EMA/SMA Frequency Response Comparison

to the window length, then the relationship for the EMA K factor is approximately

Hutson- derived the relationship between the EMA K factor and the SMA window length as

This definition is based on the average age of each. Note that this definition is substantially the same as the first definition derived except for the shortest window lengths.

Examination of the H(jW) frequency response gives insight into the phase delay of an EMA. Wrhen the frequency is near zero, jW/K is much smaller than unity and can be ignored. In this case the output is almost the same as the input, and there is no phase delay. On the other hand, when the frequency approaches infinity, jW/K is much larger than unity and the unity factor in the denominator can be ignored. When this is done, the denominator has a 90-degree phase shift due to the imaginary operator. An interesting result is that the phase lag of an EMA is never more than 90 degrees at any frequency. Since the phase lag of an EMA is always less than the phase lag of an SMA, the EMA is the preferred type of moving average in many applications.

0 0

Post a comment