Smoothing & filters#

Track and denoise the level of a series: moving averages and designed filters.

Smoothing & moving averages#

Track the level of a series and suppress short-term noise.

Function

Description

Butterworth low-pass filter

General-order IIR Butterworth low-pass filter.

Double Exponential MA (DEMA)

Mulloy's Double EMA: 2*EMA - EMA(EMA).

Exponentially-weighted mean

Exponentially-weighted moving average (pandas adjust=True).

Hull MA

Hull's responsive MA: WMA(2*WMA(n/2) - WMA(n), sqrt(n)).

Scalar Kalman filter

Scalar 1-D Kalman filter for a noisy random-walk model.

Kaufman Adaptive MA (KAMA)

Adaptive MA whose smoothing constant responds to the efficiency ratio.

FIR moving average (arbitrary taps)

Finite-impulse-response filter with user-supplied taps.

Rolling mean

Trailing-window arithmetic mean (simple moving average).

Rolling 2nd-order polynomial fit

OLS fit y = a + b*t + c*t^2 over a trailing window.

Triple Exponential MA (TEMA)

Mulloy's Triple EMA: 3*EMA - 3*EMA(EMA) + EMA(EMA(EMA)).

Triangular MA (TRIMA)

Triangular MA: SMA of an SMA. Heavier center-weighting than WMA.

Weighted Moving Average (WMA)

Linearly-weighted moving average. O(1) per step.

Filtering#

Designed frequency-domain and state-space filters.

Function

Description

Butterworth low-pass filter

General-order IIR Butterworth low-pass filter.

Butterworth band-pass filter

General-order IIR Butterworth band-pass filter.

Butterworth band-stop filter

General-order IIR Butterworth band-stop (notch) filter.

Butterworth high-pass filter

General-order IIR Butterworth high-pass filter (rejects low frequencies).

Hampel filter

Robust Hampel despiker, replace samples far from the window median (in MAD units).

Scalar Kalman filter

Scalar 1-D Kalman filter for a noisy random-walk model.

FIR moving average (arbitrary taps)

Finite-impulse-response filter with user-supplied taps.

Schmitt trigger (hysteresis comparator)

Hysteresis comparator. Latches 1.0 above the upper threshold, 0.0 below the lower threshold, and retains its previous value in between.