Zero Lag Filtering

Discussion in 'Technical Analysis' started by panzerman, Sep 13, 2016.

  1. panzerman

    panzerman

    I recently discovered how to implement a zero lag filter and wanted to share it here.

    Use your favorite IIR (recursive) filter and use in a bidirectional (aka forward-backward) method.
    https://www.dspguide.com/ch19/4.htm

    This works by forward filtering price using the recursive feature of an IIR filter, and then filtering the forward data in reverse via reverse recursion. This is the filtfilt function in MatLab.
    http://www.mathworks.com/help/signal/ref/filtfilt.html
    http://stackoverflow.com/questions/17675053/matlabs-filtfilt-algorithm

    This forward-backward method produces a zero phase response in the frequency domain, which results in zero lag in the time domain (by convolving the impulse responses.) I personally use John Ehlers' 2-pole supersmoother as the IIR filter and use a 10 day period as the filter cutoff.

    The filtered data can be traded directly in a trend following method, or used as input into other technical indicators, such as RSI.
     
  2. Mysteron

    Mysteron

    The time lag for the information that is being filtered is ever present and can't be avoided.
     
    Rationalize likes this.
  3. Yes, but zero lag sounds really cool...
     
    Last edited: Sep 13, 2016
  4. panzerman

    panzerman

    You know I didn't invent this math or this method. It really is zero lag. See attached spreadsheet for daily Merck data. The only parameter you need to change is the period (cell C1), which has the effect of changing the filter cutoff frequency.
     
    • mrk.zip
      File size:
      24.4 KB
      Views:
      169
  5. Simples

    Simples

    1. Zero Phase != Zero Lag
    2. Zero Phase as described in your link only makes sense for repainting historical data. If used for signals or trade management, such changes will occur in the past, after the fact. Not too useful for real-time decisions.
    3. Zero Phase doesn't make much difference anyways and will likely just be confusing in real trading. There are other superior formulas for curve-fitting the past too.
    4. "Zero Lag" may reduce whip-saws compared to normal bar-prices (OHLC, Median, etc.), but will not eliminate whip-saws across longer periods of bars and is not adaptive to price action.
    5. "Roofing filter" may remove much of trend-component relative to the chosen period and force value/distribution symmetry around 0, but again, not adaptive.
    6. You can find all possible phases using Fourier Transform techniques as well. However, phase on it's own is actually one of the least useful values since price action is non-stationary.
    7. Much of signal processing is so far removed from proper trading it's very hard to use in practical trading. Though, can be one more tool in the toolbox to be considered.
    8. Beware the illusions(!) that you've found something extraordinary worthwhile! :banghead::sneaky:
    9. If it works for you: Great!
    Actual trading is about calculated patience, taking on risks for others and relentless improvements.

    Good share anyways! :D Long time since I saw some DSP stuff. Had to go through 1 year of analysing that fluff..
     
    Last edited: Sep 13, 2016
    lxsun, ironchef and Rationalize like this.
  6. panzerman

    panzerman

    1. For the degree of precision needed in trading zero phase == zero lag.
    2. It does change the value of some of the past data, but past data is not what you trade on. You trade on the hard right edge of the chart only, and can thus can be used in real time if needed.
    3. ???
    4. This is not intended to be an adaptive filter method although could be modified as such. All such filters only react to past data anyhow and make no predictions. That would be something like linear prediction model.
    5. This isn't a roofing filter and is not designed to be adaptive, but could be.
    6. This is true, but this filter doesn't involve Fourier Transformations.
    7. DSP is the best engineering approach I personally have seen to dealing with financial data.
    8. I think the brick wall is for people who see no use at in zero lag filtering. I have never portrayed this as some kind of miracle solution.
     
  7. Check out John Ehlers' papers here. I found him a few years ago and his concepts are very interesting.

    Scroll down and you'll find a zero lag article. I also liked his Fisher Transform and Swiss Army Knife articles.

    *edit* oops I missed your reference to Ehlers in the OP.
     
    ironchef likes this.
  8. Simples

    Simples

    Same source. NP. Interesting and educational info, but not earth shattering regarding trading IMHO.

    @panzerman: I'll respond once, but not interested in argument. How many years experience you have trading? I had couple of months before I studied Ehler's, and have since moved beyond those hypothesis'.

    1. Zero phase really means trend, which is average, or any SMA, or CCI. All filters "lag", or should I say DISTORT. But zero phase has nothing directly to do with lag whatsoever.
    2. Backwards calculation may be interesting and potentially useful, but the examples in your link just shows changing the past, which doesn't do much for your analysis NOW.
    3. KISS
    4. ...
    5. Roofing could be predictive though, if just price action was clinically cyclical (in FT sense, not seasonal sense), which it ain't. Just an example of something similar.
    6. I'd rather use FT and fade that..
    7. I thought it looked neat in the beginning, especially the rocket science parts, but have since left it entirely..
    8. WTF is "zero lag filtering" anyways? Zero lag is pure price and volume per time, nothing else. Oxymoron for morons who don't know any better if you ask me.
     
    Last edited: Sep 13, 2016
  9. Jeffro72

    Jeffro72

    Amazing concept, but seems a bit too good to be true since you need 2 inputs from the future to keep the average line intact. If you remove the last two inputs (which would be from the future) on the Excel spreadsheet, the average line breaks down.

    Still beautiful to look at though. It may still work nicely with estimated values.
     
  10. panzerman

    panzerman

    Yes, the better way to do this is to filter backward, then filter forward, instead of filtering forward and then backward as in my first spreadsheet. This avoids having to estimate startup values at the hard right edge of the chart. See attached examples.
     
    #10     Sep 14, 2016