Roofing Filter

The Roofing Filter of John Ehlers (2013) is a two-pole high-pass filter followed by a SuperSmoother, which keeps only the cycles between the shortest period m and the longest period n: it removes both the trend and the noise. Ehlers uses it as the input of most of his later cycle indicators. Angles are in degrees.

The formula for the Roofing Filter first sets the coefficient alpha of its two-pole high-pass filter from the longest period n, with the 0.707 of a Butterworth filter in the angle:

\[\alpha = \frac{\cos\left(\frac{0.707 \cdot 360}{n}\right) + \sin\left(\frac{0.707 \cdot 360}{n}\right) - 1}{\cos\left(\frac{0.707 \cdot 360}{n}\right)}\]

The high-pass filter takes the second difference of the price and adds its own last two values, which removes the cycles longer than n:

\[\text{High Pass} = \left(1 - \frac{\alpha}{2}\right)^{2} \cdot (\text{Price} - 2 \cdot \text{Price}_{t-1} + \text{Price}_{t-2}) + 2 \cdot (1 - \alpha) \cdot \text{High Pass}_{t-1} - (1 - \alpha)^{2} \cdot \text{High Pass}_{t-2}\]

A two-pole SuperSmoother with critical period m then removes the cycles shorter than m, with its coefficients a and b set from m:

\[a = \exp\left(-\frac{\sqrt{2} \cdot \pi}{m}\right)\] \[b = 2 \cdot a \cdot \cos\left(\frac{\sqrt{2} \cdot 180}{m}\right)\] \[\text{Roofing Filter} = \frac{\left(1 - b + a^{2}\right) \cdot (\text{High Pass} + \text{High Pass}_{t-1})}{2} + b \cdot \text{Roofing Filter}_{t-1} - a^{2} \cdot \text{Roofing Filter}_{t-2}\]

Where Price is the median price or the close and Price(t-1) and Price(t-2) the prices one and two periods ago. The Roofing Filter swings around zero with the cycles between m and n periods: its peaks and troughs mark the turns of those cycles, without the trend that would push an oscillator to one side or the noise that would make it jitter.

A filter in the sense of digital signal processing separates the movements of the price by their length: a high-pass filter keeps the short cycles and removes the trend, a low-pass filter keeps the trend and removes the short cycles (the noise), and a band-pass filter keeps only the cycles around one length. John Ehlers’ Swiss Army Knife indicator (2006) writes them all as one second-order recursive filter, a weighted sum of the latest prices and the filter’s own last two values, whose coefficients select its response; his decycler and roofing filter (2013) combine such filters. Each takes a cutoff period n: the cycle length that separates what the filter keeps from what it removes. Unlike a moving average, these filters remove what they are designed to remove with little lag, which is why Ehlers builds his cycle indicators on them.

Also known as: Ehlers roofing filter.

In the Finance Toolkit this is get_swiss_army_knife_filter with method="roofing", the same function as Swiss Army Knife Filter.

Example · AAPL, MSFT · 2021 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_swiss_army_knife_filter:

from financetoolkit import Toolkit

toolkit = Toolkit(
    tickers=["AAPL", "MSFT"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.technicals.get_swiss_army_knife_filter(method="roofing")

Which returns:

References

  • Paper Ehlers, J.F. (2013). “Cycle Analytics for Traders: Advanced Technical Trading Concepts.” John Wiley & Sons, chapters 4 (the decycler) and 7 (the roofing filter).
Share