alexgrover

Properties And Spectral Interaction Of Zero-Lag Filters

Education
COINBASE:BTCUSD   Bitcoin
Introduction

In this post i want to talk about zero-lag filters, how they interact with the price and its frequency components. I'll also talk about the phase-response, and try to clearly explain how it works and what information it can give to the user. I'll finally introduce the concept of forward-backward filtering as well as zero-phase non stable causal smoothing.

Filters And Lag

Lag is a term used in technical analysis that refer to the phase-shift induced by filters. As you know filters interact with the frequency content of a signal, they can remove certain frequency components or amplify/reduce their amplitude. Lag can be perceived when smoothing market price by using a low-pass/band-pass filter, in short a filter with lag will return past-trends instead of new one, this can be considered a tradeoff where the user can access information easier to interpret at the cost of reactivity.

Phase Response

One can visualize the phase of filters thanks to the phase-response. The phase-response is a value expressed in degree or radians and is described as the relationship of a sinusoid and the phase, its a bit confusing so let me explain you how it works. Remember that a sine wave have a amplitude and a frequency and a period, she can also have a certain phase expressed in degree, for example in this image www.davidbridgen.com/images/PHASE9.jpg the sine wave in red is shifted by 180 degree, the phase response of a filter will tell you how many degree a frequency component (sinusoid) is shifted after being filtered.

Here an image showing a frequency response : i.stack.imgur.com/zsKQj.png

This is because frequency components are shifted that lag can be perceived.

Tackling The Lag Problem

So technical analyst tackled this problem by making zero-lag filters, of course the term zero-lag must be taken lightly, basically zero-lag will mean a filter who better fit to the data. So how do this work ?

Remember that a filter posses a frequency response, the frequency response tell you how the filter interact with the frequency components of the signal. So with most of the zero-lag filters lag will be reduced by amplifying some frequency components of the filter, some zero-lag filters will have the following frequency response :


This frequency response amplify certain frequencies before the transition band, this allow the filter to better fit to the signal. Of course this is not the only way to make filter have zero-lag, common zero-lag filter structures include :

  • amplifying certain frequencies in price -> applying filter
  • applying a bandpass filter to the price -> summing the result with a low-pass filter
  • multiply a low-pass filter with cutoff frequency a by 2 -> subtract the result to a low-pass filter of cutoff frequency b with a > b

As you can see such filters produces better fit but are less smooth than other filters of the same period, this is logical, you are amplifying certain frequencies, and some of those frequencies can be high ones, basically noise, which explain the reactivity-smoothness tradeoff. The amplification process also creates artifacts such as over/undershoots which are direct effects of amplification.

Zero-Phase Smooth Filters - Non Causal

Any filter can have literally zero-lag and be smooth by a method called forward-backward filtering, this method consist in filtering the data from the left to the right and then filtering this result from the right to the left, during the last step you basically shift back the filtered result to the right, which compensate the shift produced by the first step filtering.

Such filters work by reversing the orders of the signal samples, now they are said to be non-causal because they no longer use only past information, this is why such filters are used offline, their phase response is equal to 0. Those filters are the core of many repainting indicators.

Zero-Phase Smooth Filters - Causal

Impossible ? In theory yes, at least with FIR filters, however IIR filters can work differently. IIR filters are less stable than FIR filters and posses a non-linear phase, this mean that their phase is not a linear function. IIR filters are filters using past outputs as input, as said they can sometimes produce zero-lag smooth outputs, but those results are not stable and does not occur every time, in facts they are rare events.

An example is made by using double exponential smoothing


Using low values for beta can produce non-stables results appearing non-causal, and sometimes even great fits.


However those effects does not appear constantly. Another way to have causal zero-lag filters is to forecast the data and smooth it, however you then are affected by the accuracy of your forecast model, how unfortunate.

Conclusion

This post took more time than necessary, but it is interesting to see how zero-lag filters works from a signal-processing point of view. So from now on if you see filters appearing to good to be true, you are certainly dealing with one using forward-backward filtering, either way you can't violate causality, no matter how hard you try...its also socially inappropriate (lame jokes !!!!!).

Thanks for reading !

Check out the indicators we are making at luxalgo: www.tradingview.com/u/LuxAlgo/
Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.