Articles

Home  >  Technical Analysis  >  Articles  >  General Articles  >  Hybrid FIR and IIR Filters
Printer Friendly Version

Hybrid FIR and IIR Filters

Page: 1 2 3 4
by John Ehlers -  Aug 28, 2006
6.2 (from 5 ratings)

Simple Moving Averages are a subset of FIR Filters. Exponential Moving Averages are a subset of IIR filters. Traders are not necessarily limited to the selection of one or the other. This article describes how you can make hybrid filters and realized the best characteristics of both.

Many traders have come to me, asking me to make their indicators act just one day sooner.  They are convinced that this is just the edge they need to make a zillion dollars.  While their profit expectation may not be realized, it is true that lag is the downfall of many trading systems.  If you want to shorten the lag of your indicators, or if you want to get more smoothing from your filters, the techniques in this article may be just what you have been seeking.  Rather than creating the indicators, I will show you ways to make your own techniques better by improving their filters.  Filters are part of almost every indicator.

There are two fundamentally different kinds of filters, Finite Impulse Response (FIR) and Infinite Impulse Response (IIR) filters.  Simple Moving Average (SMA) and Weighted Moving Average (WMA) filters are examples of FIR filters and an Exponential Moving Average (EMA) is an example of an IIR filter.

An impulse can be pictured as data that has a value of one at only one bar and is zero everywhere else.  When this data is a applied to a five bar simple moving average, for example, the output of the moving average is zero until the impulse enters the input of the filter.  Then the output is one-fifth, the input averaged across the width of the filter.  As time progresses, the filter output remains one-fifth when the impulse is positioned at the second, third, fourth, and fifth position of the moving average.  Finally, the impulse falls outside the moving average and the filter output becomes zero, and remains zero for the rest of the data set.  Thus, the response to the impulse input is finite in duration – it only lasts as long as the impulse is within the filter length.  This is why it is so named FIR.  The output of the Simple Moving Average is plotted with respect to the right hand side of the filter on our charts.  However, the average position is at (N-1)/2 for an N bar moving average.  The difference between where the average is plotted and its average position is the lag of the filter.  Thus, a 5 bar Simple Moving Average will have a 2 bar lag.

A Weighted Moving Average (WMA) is another example of a FIR filter.  In a WMA, the oldest data has a weight of one, the next oldest has a weight of two, and so on, until the most recent data has a weight of N for an N-length WMA.  When an impulse is applied to the input of a WMA the output is a scaled replica of the weighting function.  The weighting is in the shape of a triangle, with the result that the lag is the “center of gravity” of the weighting function, or about one-third the length of the filter.  The lag can be calculated as (N-1)/3 for an N-Bar WMA.  Therefore, a 4 bar WMA has a lag of only one bar, a 7 bar WMA has a lag of 2 bars, and so on.

IIR filters are fundamentally different from FIR filters because a recursive calculation is employed, using the results of a previous calculation.  The equation to compute an EMA is
 

 EMA = *Price + (1-)*EMA[1]
 Where  is a number less than one

In English, this equation says that the current EMA value is equal to a fraction of the current price plus the quantity one minus that fraction, the quantity times the previous EMA value.  If the Price is an impulse, the first output value of the EMA is because there is no previous filter output value.  The next output value is *(1-) because there is no new input and the previous calculation value was .  Then, the next output value is *(1-)2.  The following output value is *(1-)3, and so on.  The sequence continues, so that the Nth output value is *(1-)N.  The output value decreases as the exponent of the sample number, hence the name Exponential Moving Average.  Regardless of how many samples have occurred since the impulse event, there is theoretically some contribution of the impulse present in the output.  That makes the EMA an Infinite Impulse Response filter.  It can be shown that the alpha term in an EMA can be computed to provide the equivalent smoothing of a SMA as

 = 2 / (Length + 1)

Since the lag produced by a SMA is approximately half the filter length, it also can be shown that the alpha of an EMA can be computed from the amount of allowed lag as

 = 1 / (Lag + 1)

From these equations, it can be seen that an EMA having  = .33 is equivalent to a five bar SMA or a 7 bar WMA (the lag of a 7 bar WMA being 2 bars).

Let’s examine the performance of some of these filters.  The prices are sampled data, and information theory says that we must have at least two samples per cycle of the highest frequency being considered.  This highest frequency is called the Nyquist frequency, and is a 2 bar cycle.  Generalized frequency responses are normalized so that the Nyquist frequency is one.  With this normalization, a four bar cycle has a normalized frequency of 2/4= 0.5 and a 20 bar cycle has a normalized frequency of 2/20=0.1, and so on.  To observe the amplitude response of the filters, the output is scaled in decibels (dB).  A decibel is ten times the log of the power ratio.  Therefore half power is –3 dB and one-tenth power is –10 dB.  It should also be noted that power is proportional to the square of the wave amplitude.  With these definitions, we see the response of a four bar SMA in Figure 1.  One 4-bar cycle exactly fits in the 4-bar SMA.  One fully cycle averages to zero, so we see a notch in the response at the 0.5 normalized frequency.   There are two 2-bar cycles that exactly fit within the 4-bar SMA.  These two cycles also average to zero, producing the notch at the 1.0 normalized frequency.  Incidentally, all even-order symmetrical FIR filters always produce a notch for the 2 bar cycle (Nyquist frequency = 1).  For this reason, even order (2, 4, 8, 10, etc.) symmetrical FIR filters are preferred over odd order FIR filters.

One FIR filter of interest to traders is a 6th order filter whose coefficients are symmetrically weighted as [.0833 .1667 .25 .25 .1667 .0933].  The response of this filter, shown in Figure 2, has a notch for 2, 3, and 4 bar cycles.  This filter has a lag of 2.5 bars for all frequencies.

Page: 1 2 3 4
» Page 2




Copyright © 2001-2008 Trade2Win Ltd.