PureBytes Links
Trading Reference Links
|
Sorry about my post of 7 Jul 1998 13:59:23 which was full of "engineer
speak". I had intended to send it only to Gary Fritz but must have hit the
"reply to all" button. It must have sounded pretty strange to normal
people.
Gary did a great job of explaining the terms of my post. He asked a few
questions so the purpose of this post is to answer those questions.
At 11:55 PM -0400 7/7/98, Gary Fritz wrote:
>Gary: I'd actually never even thought of MA's as filters, but now that
>you've explained it that way it makes perfect sense.
I will append a short summary of digital filter design that was recently
posted on the SciLink list by dkomo@xxxxxxxxx
At 1:59 PM -0400 7/7/98, Bob Fulks wrote:
>>Bob: You need to watch the phase shift since this causes delays.
>Gary: A "phase shift" being a place where it changes the frequency at
>which it oscillates -- maybe moving from a trading range into a trend or
>vice versa. (Or were you talking about the phase shift inherent in the
>filter, Bob? See the section about "lag," below.)
I was referring to the phase shift of the inherent filters. Phase shift
causes lag in the resulting output vs. time. A constant lag for all
frequency components vs. time (as with a simple moving average) is a result
from a linear phase shift in the filter vs. frequency. More complex filters
often have a phase shift characteristic that varies in various ways from
linear, causing distortions in the resulting output that distort trading
signals.
>Hm. Bob, is there some reasonable way (short of MESA or Fourier analysis)
>to determine the primary resonant frequency, and detect the phase shift?
>It would be very useful to be able to tell when to shift your strategy
>from range-bound to trending.
These tools can detect the power at various frequencies but I have not
found them to be very useful for building trading systems. The problem is
that the cycles you think you can clearly see in the price do not repeat
reliably. Some people use them successfully. Others seem to have been able
to detect repeating patterns made up of multiple sine wave signals at
differing frequencies extending back decades but I have not pursued this. I
tend to use bandbass filters to recover the cleanest signal I can get and
then derive trading signals from it in time.
>>Bob: Avoid using filters with lots of poles and zeros - they have weird
>>phase behavior.
>Gary: This refers to the esoteric math (complex numbers, division by zero,
>stuff like that) used to describe filter behavior. I don't even remember
>exactly what it means. :-) Bob, is there a reasonably straightforward way
>to tell if a filter has bad phase behavior? What exactly do you *mean* by
>"weird phase behavior"?
Traditional digital filter design techniques are most commonly used to
isolate narrow band communications signals (such as your local AM radio
station at say, 950 kilohertz) from interference from other stations. These
filters are called with such names as "Chebyshev filters", "Elliptic
function filters", and "Butterworth filters", etc. In this example, the AM
radio signal is contained in the band of frequencies very close (well
within 1%) to the center frequency and very closely controlled by the
transmitter. An example in a digital filter design book I have has 31
numerical constants specified to about eight significant digits each (lots
of poles and zeros). This kind of filter design doesn't work well for
market data. We need to use filters that remove the unwanted frequencies
and also have low lag and low overshoot to sudden changes in price.
The simple moving average is commonly used but it has pretty poor
characteristics, including lots of lag and spurious frequency responses at
higher frequencies. More sophisticated filters such as Tillson's T3 filter
you mention is much better. Adaptive moving averages such as the Jurik
filter are very good for tracking price movements with good filtering and
low lag.
Below is part of the post by dkomo@xxxxxxxx on filter design.
Bob Fulks
******************************************************
Background
----------
Digital filters are of two basic types: IIR (infinite impulse response) and
FIR (finite impulse response). FIR filters have the following mathematical
form (using TradeStation notation):
y = B1*close + B2*close[1] + B3*close[2] + B4*close[3] + ....
Here I'm anticipating that I'll be using closing prices as inputs to the
filter, and that Matlab numbering convention starts numbering vectors with
the index 1. As we'll see later, the B vector in Matlab will contain our
filter coefficients once the design is finished. Also, using "B" for the
coefficients of an FIR filter is fairly standard in digital signal
processing.
Now, it should be pointed out that all of us have been using digital
filters in our trading system development all along whether we realized it
or not. For example, a 5-period simple moving average is an FIR filter:
y = (1/5)*close + (1/5)*close[1] + (1/5)*close[2] + (1/5)*close[3] +
(1/5)*close[4]
In fact, a simple moving average is a lowpass FIR filter of rather poor
quality. With minimal effort we could, if we desired, come up with much
better lowpass filters using Matlab.
Another example of an FIR filter is a 10-day momentum indicator:
y = close - close[10]
Using Matlab (or other digital signal processing toolkit) we could plot the
frequency response of this 10-day momentum filter and perhaps really learn
something.
IIR filters look like this:
y = B1*close + B2*close[1] + B3*close[2] + B4*close[3] + .... + A2*y[1] +
A3*y[2] + A4*y[3] + ....
Besides using previous values of the input data series (the closes in this
case), IIR filters have feedback wherein they input previous values of the
filter outputs (the variables y[1], y[2], y[3], etc.). The awkward
numbering on the A coefficients is there for a reason. A1 is actually 1.0
and is the coefficient on the y output (the current filter output). Also,
this is how Matlab expects us to use the A coefficients once it gives them
to us. Standard notation in signal processing is to use "A" for these
feedback coefficients.
Again, some of us might be surprised to learn that we've been playing
around with IIR filters for years. Voila, consider the humble exponential
moving average:
y = a*close + (1-a)*y[1]
where a is approximately 2/(N+1) and N is the period of the average.
By: dkomo@xxxxxxxx from the SciLink list (28 May 1998)
|