PureBytes Links
Trading Reference Links
|
----------------------------------------------------------
{Function: _SMA3
by Alex Matulich, 6/2004 - Unicorn Research Corporation}
Inputs: price(NumericSeries), length(NumericSimple);
Var: N(IntPortion(0.75*length+.5); {~20dB attenuation at f=1/length}
_SMA3 = Average(Average(Average(price, N),
IntPortion(N/1.25)), IntPortion(N/1.5));
----------------------------------------------------------
It's basically a triple simple moving average. However, there's a twist.
Naturally, any time you apply a moving average on itself, you'll get a
steeper ffall-off in the frequency response (better attenuation of shorter
wavelengths). The problem with applying the same moving average onto
itself is that the filter loses much of its main lobe power (low frequency
power below the filter cutoff frequency), and the sidelobes aren't
removed, either.
What I did here is take advantage of the fact that the simple moving
average exhibits a series of nulls (infinte attenuation) in the frequency
response. In _SMA3, each subsequent average is tuned so that a null is
superimposed on the first sidelobe of the previous average, which
effectively erases the sidelobes with minimal effect on the main lobe.
Just 2 additional averages after the first one attenuates the sidelobe
power 45 dB or more, resulting in only the main lobe remaining, giving a
reasonable approximation of a "brick wall" filter. (45 dB power
attenuation translates to an amplitude of 1/178 of the original
amplitude.)
See the attached picture, showing the frequency responses of EMA, SMA, T3,
and _SMA3 using a length of 20.
The T3 Average uses a cascade of six exponential moving averages, combined
with correction coefficients to compensate for power loss in the mainlobe.
However, T3's improved frequency response comes at a cost: T3 is
susceptible to overshoot, unlike _SMA3.
Advantages to _SMA3 over T3:
* Better attenuation of high frequencies above the cutoff while preserving
the power of main lobe.
* No overshoot, but with better tracking of large changes in the input
signal. Lag is about the same as T3 (_SMA3 usually lags T3 slightly, but
occasionally leads it).
* The _SMA3 main lobe has a much sharper roll-off than T3, and the
side-lobes are still better attenuated, while the attenuation at
wavelength of 'length' is about the same for T3 and _SMA3 (21 dB for T3,
20 dB for _SMA3).
The disadvantage to _SMA3 over T3 is that _SMA3 is computationally slower.
However, this can be cured by maintaining running sums to calculate each
average, rather than summing up the past data on each new bar. That is,
at each new bar, subtract price[length] from the sum and add price[0],
instead of adding them all up every time.
T3 is a very laggy filter, but this lag can be fixed somewhat by reducing
the length parameter used for T3, while still having better smoothness
than a moving average. Because _SMA3 has a similar lag with better
smoothing than T3, one can do the same for _SMA3 and still get superior
performance to T3, without overshoot. In practice, passing
(length-1)/pi+1 as the length parameter works well for both T3 and _SMA3.
This results in a 3 dB cutoff at wavelength=length for T3.
Creating highpass and bandpass filters:
If you have a good lowpass filter, you can use it to construct a good
highpass filter and bandpass filter. The highpass filter is simply
highpass = price - _SMA3(price, length);
and the bandpass filter is
bandpass = _SMA3(price, length1) - _SMA3(price, length2);
..where length2 > length1.
I hope y'all find this useful for something.
Alex Matulich
Attachment:
filter_response.gif
Attachment:
Description: "Description: GIF image"
|