Files
QuanTAlib/lib/trends/ssf/Ssf.md
T

3.5 KiB

SSF: Ehlers Super Smooth Filter

"Noise is the enemy of the trend follower. The Super Smooth Filter is the silencer."

The Super Smooth Filter (SSF) is a 2-pole Butterworth filter designed by John Ehlers. It offers superior noise reduction compared to standard moving averages while maintaining minimal lag. By using complex conjugate poles, it achieves a "maximally flat" response in the passband, meaning it preserves the trend signal with high fidelity while aggressively suppressing high-frequency noise.

Historical Context

John Ehlers introduced the Super Smooth Filter to address the limitations of traditional filters like the EMA and SMA, which often sacrifice responsiveness for smoothness. The SSF uses digital signal processing (DSP) principles to achieve an optimal balance, making it a favorite among quantitative traders who need clean signals for algorithmic systems.

Architecture & Physics

The SSF is an Infinite Impulse Response (IIR) filter.

  • 2-Pole Design: Uses two poles in the Z-domain to create a sharper cutoff than single-pole filters (like EMA).
  • Butterworth Characteristic: Maximally flat passband response, minimizing distortion of the trend.
  • Minimal Lag: Despite its smoothing power, it reacts relatively quickly to significant price changes.

Zero-Allocation Design

Our implementation is optimized for high-frequency trading.

  • State: Tracks only the previous two SSF values (SSF[1], SSF[2]).
  • O(1) Complexity: Constant time update regardless of period.
  • No Buffers: Uses a compact state struct, no heap allocations in the hot path.

Mathematical Foundation

The filter coefficients are derived from the desired cutoff period:

\text{arg} = \frac{\pi \sqrt{2}}{N} c_2 = 2 e^{-\text{arg}} \cos(\text{arg}) c_3 = -e^{-2 \cdot \text{arg}} c_1 = 1 - c_2 - c_3

The recursive formula for the filter is:

\text{SSF}_t = c_1 \cdot \frac{P_t + P_{t-1}}{2} + c_2 \cdot \text{SSF}_{t-1} + c_3 \cdot \text{SSF}_{t-2}

Where:

  • P_t is the current price.
  • P_{t-1} is the previous price.
  • \text{SSF}_{t-1} and \text{SSF}_{t-2} are the previous filter outputs.

Note: This implementation uses high-precision constants (Math.Sqrt(2) and Math.PI) rather than the approximations (1.414 and 3.14159) found in some reference implementations.

Performance Profile

Metric Complexity Notes
Throughput High Few multiplications and additions per bar
Complexity O(1) Recursive calculation
Accuracy 9/10 Excellent noise suppression
Timeliness 8/10 Low lag for the amount of smoothing
Overshoot 8/10 Minimal overshoot due to Butterworth design
Smoothness 9/10 Superior to EMA/SMA

Validation

Validated against OoplesFinance.StockIndicators.

Provider Error Tolerance Notes
OoplesFinance 10.0 Matches CalculateEhlersSuperSmootherFilter with deviation due to our use of high-precision constants (Math.Sqrt(2), Math.PI) vs Ooples' shallow approximations (1.414, 3.14159).

Common Pitfalls

  1. Initialization: The filter requires a few bars to stabilize. Per Ehlers' design, the output is set to the input price for the first 4 bars.
  2. Period Selection: Unlike an SMA, the "Period" N in SSF refers to the cutoff wavelength. A period of 10 means it filters out cycles shorter than 10 bars. It is roughly comparable to an EMA of the same length but smoother.