Butterworth Filter

The Butterworth Filter, the two-pole Butterworth low-pass filter, smooths away the cycles shorter than the cutoff period n and keeps the trend, with a flat response below the cutoff. Angles are in degrees.

The formula for the Butterworth Filter first sets its coefficient alpha from the cutoff period n:

\[\beta = 2.415 \cdot \left(1 - \cos\left(\frac{360}{n}\right)\right)\] \[\alpha = -\beta + \sqrt{\beta^{2} + 2 \cdot \beta}\]

The filter then averages the last three prices with weights 1, 2 and 1 and adds its own last two values:

\[\text{Butterworth} = \frac{\alpha^{2}}{4} \cdot (\text{Price} + 2 \cdot \text{Price}_{t-1} + \text{Price}_{t-2}) + 2 \cdot (1 - \alpha) \cdot \text{Butterworth}_{t-1} - (1 - \alpha)^{2} \cdot \text{Butterworth}_{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. It follows the price like a moving average; averaging the last three prices removes the two-period cycle completely.

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_BUTTER, two-pole Butterworth filter, Butterworth low-pass filter.

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

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_BUTTER (Butterworth Filter)
Share