High-Pass Filter

The High-Pass Filter, the one-pole high-pass filter, removes the trend and keeps the cycles shorter than the cutoff period n. Angles are in degrees.

The formula for the High-Pass Filter first sets its coefficient alpha from the cutoff period n:

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

The filter then takes the change of the price over one period and adds its own last value:

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

Where Price is the median price or the close and Price(t-1) the price of the period before. It swings around zero: positive while the price rises faster than its trend and negative while it falls behind it. With one pole it removes the trend gradually, so some of the longer cycles stay in.

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: SWAK_HP, one-pole high-pass filter, highpass filter.

In the Finance Toolkit this is get_swiss_army_knife_filter with method="high_pass", 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="high_pass")

Which returns:

References

  • Paper Ehlers, J.F. (2006). “Swiss Army Knife Indicator.” Technical Analysis of Stocks & Commodities, 24(1), 28-31, 50-53.
  • Library Referenced against TA-Lib’s SWAK_HP (High-Pass Filter)
  • Library Referenced against TA-Lib’s SWAK_2PHP (Two-Pole High-Pass Filter)
Share