Swiss Army Knife Filter

Calculate Ehlers’ Swiss Army Knife filter: a family of filters that remove the trend (high-pass), the noise (low-pass) or both (band-pass) from the prices.

The Swiss Army Knife indicator of Ehlers (2006) is one second-order recursive filter whose coefficients select its response. The high-pass filters remove the trend and keep the cycles shorter than the window, the two-pole one with a steeper cut than the one-pole one. The band-pass filter keeps only the cycles around the window, which shows how strongly that cycle is present and where it turns. The Butterworth and Gaussian filters are low-pass filters that smooth away the cycles shorter than the window with little lag.

The formula is as follows:

\[\text{Filter} = c_{0} \cdot (b_{0} \cdot \text{Price} + b_{1} \cdot \operatorname{Price}(t-1) + b_{2} \cdot \operatorname{Price}(t-2)) + a_{1} \cdot \operatorname{Filter}(t-1) + a_{2} \cdot \operatorname{Filter}(t-2),\;\; \text{with}\;\; b_{0} = 1 \;\text{and every other coefficient 0 unless set below}\] \[\text{One-pole}\; \alpha = \frac{\cos\left(\frac{360}{\text{Window}}\right) + \sin\left(\frac{360}{\text{Window}}\right) - 1}{\cos\left(\frac{360}{\text{Window}}\right)}\] \[\text{Two-pole}\; \alpha = - \text{Beta} + \sqrt{\text{Beta}^{2} + 2 \cdot \text{Beta}},\;\; \text{with}\;\; \text{Beta} = 2.415 \cdot \left(1 - \cos\left(\frac{360}{\text{Window}}\right)\right)\] \[\text{High-pass:}\;\; c_{0} = 1 - \frac{\alpha}{2},\;\; b_{1} = - 1\;\;\text{and}\;\; a_{1} = 1 - \alpha,\;\; \text{with the one-pole alpha}\] \[\text{Two-pole high-pass:}\;\; c_{0} = \left(1 - \frac{\alpha}{2}\right)^{2},\;\; b_{1} = - 2,\;\; b_{2} = 1,\;\; a_{1} = 2 \cdot (1 - \alpha)\;\;\text{and}\;\; a_{2} = - (1 - \alpha)^{2}\] \[\text{Butterworth:}\;\; c_{0} = \frac{\alpha^{2}}{4},\;\; b_{1} = 2,\;\; b_{2} = 1,\;\; a_{1} = 2 \cdot (1 - \alpha)\;\;\text{and}\;\; a_{2} = - (1 - \alpha)^{2}\] \[\text{Gaussian:}\;\; c_{0} = \alpha^{2},\;\; a_{1} = 2 \cdot (1 - \alpha)\;\;\text{and}\;\; a_{2} = - (1 - \alpha)^{2}\] \[\text{Band-pass:}\;\; \text{Beta} = \cos\left(\frac{360}{\text{Window}}\right),\;\; \Gamma = \frac{1}{\cos\left(\frac{720 \cdot \Delta}{\text{Window}}\right)},\;\; \alpha = \Gamma - \sqrt{\Gamma^{2} - 1},\;\; c_{0} = \frac{1 - \alpha}{2},\;\; b_{2} = - 1,\;\; a_{1} = \text{Beta} \cdot (1 + \alpha)\;\;\text{and}\;\; a_{2} = - \alpha\]

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()

Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:

What did Ehlers' Swiss Army Knife Filter of Apple and Microsoft show in 2025?

Which returns:

Parameters

get_swiss_army_knife_filter accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe time period to consider for historical data. Options are: “intraday” (intraday prices), “daily” (daily prices), “weekly” (weekly prices), “monthly” (monthly prices), “quarterly” (quarterly prices), “yearly” (yearly prices). Defaults to “daily”."weekly"
close_columnstrThe column name for closing prices in the historical data. Defaults to “Adj Close”, in which case the high and low prices are adjusted for dividends in the same way."Close"
median_priceboolWhether to filter the median price (High + Low) / 2, as Ehlers does, or the close of close_column, as TA-Lib’s SWAK functions do. Defaults to True.True
windowintThe cutoff period of the high-pass and low-pass filters and the centre period of the band-pass filter, at least 5. Defaults to 20.20
methodstrThe filter. Options are: “high_pass” (one-pole high-pass filter), “two_pole_high_pass” (two-pole high-pass filter), “band_pass” (band-pass filter), “butterworth” (two-pole Butterworth low-pass filter), “gaussian” (Gaussian low-pass filter). Defaults to “band_pass”, the default of Ehlers’ listing."band_pass", the default of Ehlers' listing
deltafloatThe half bandwidth of the band-pass filter as a fraction of its centre frequency, above 0 and at most 0.5. Defaults to 0.1.0.1
roundingint | NoneThe number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise).2
growthboolWhether to calculate the growth of the Swiss Army Knife filter. Defaults to False.True
lagint | list[int]The lag to use for the growth calculation. Defaults to 1.4
standardizeboolWhether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False.True
show_columnsstr | list[str] | NoneThe columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column.None, which keeps every column

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
  • Library Referenced against TA-Lib’s SWAK_2PHP
  • Library Referenced against TA-Lib’s SWAK_BP
  • Library Referenced against TA-Lib’s SWAK_BUTTER
  • Library Referenced against TA-Lib’s SWAK_GAUSS
Share