Files
QuanTAlib/lib/cycles/ssfdsp/Ssfdsp.md
T
Miha Kralj 90d5638008 Add new moving average implementations: LTMA, MCNMA, NLMA, NMA, NYQMA, RAIN, and TRAMA
- LTMA (Linear Trend Moving Average): Introduces a predictive moving average using dual cascaded EMAs for trend estimation.
- MCNMA (McNicholl EMA): Implements a zero-lag TEMA using a cascaded EMA structure for enhanced responsiveness.
- NLMA (Non-Lag Moving Average): Utilizes a damped cosine kernel to achieve reduced lag in moving averages.
- NMA (Natural Moving Average): Adapts smoothing based on volatility profiles using a square-root kernel.
- NYQMA (Nyquist Moving Average): Applies the Nyquist-Shannon theorem to prevent aliasing in cascaded moving averages.
- RAIN (Rainbow Moving Average): Combines multiple SMA layers with weighted averages for multi-scale smoothing.
- TRAMA (Trend Regularity Adaptive Moving Average): Adapts smoothing based on the frequency of new highs and lows in price data.
2026-02-20 21:40:32 -08:00

4.4 KiB
Raw Blame History

SSFDSP: Ehlers SSF Detrended Synthetic Price

SSFDSP isolates the dominant cycle by subtracting a half-cycle Super-Smoother from a quarter-cycle Super-Smoother, producing a zero-centered oscillator with superior noise rejection compared to the EMA-based DSP. The 2-pole Butterworth characteristic of the Super-Smoother filter provides zero phase lag at the cutoff frequency and sharper rolloff than exponential smoothing, making SSFDSP the preferred variant for cycle-aware trading when the approximate dominant period is known.

Historical Context

John Ehlers introduced the concept of Detrended Synthetic Price in Cybernetic Analysis for Stocks and Futures (2004) as a principled method for removing the DC (trend) component while preserving cyclical energy. The original DSP used EMAs, which have a gradual frequency rolloff and non-zero phase lag. The SSF variant substitutes Super-Smoother filters, which are 2-pole Butterworth low-pass designs with matched coefficients that eliminate the Gibbs phenomenon (ringing) common in sharper filters. The result is a cleaner cycle extraction: the SSF's steeper rolloff better separates the quarter-cycle and half-cycle frequency bands, producing tighter zero crossings and more reliable turning point identification than EMA-DSP.

Architecture & Physics

1. Filter Periods

From the user-specified dominant cycle period P:

P_{fast} = \max(2, \lfloor P / 4 + 0.5 \rfloor) P_{slow} = \max(3, \lfloor P / 2 + 0.5 \rfloor)

2. Super-Smoother Coefficients

For each filter period p:

\alpha = \frac{\pi\sqrt{2}}{p} c_2 = 2 e^{-\alpha} \cos(\alpha) c_3 = -e^{-2\alpha} c_1 = 1 - c_2 - c_3

3. SSF Recursion

SSF_t = c_1 \cdot \frac{P_t + P_{t-1}}{2} + c_2 \cdot SSF_{t-1} + c_3 \cdot SSF_{t-2}

The 2-bar input averaging provides an additional anti-aliasing stage.

4. SSFDSP Output

SSFDSP_t = SSF_{fast,t} - SSF_{slow,t}

5. Complexity

O(1) per bar. Two independent 2-pole IIR filters with O(1) memory. Warmup: approximately 2 \times P_{slow} for convergence. Recursive dependencies prevent SIMD vectorization.

Mathematical Foundation

Parameters

Parameter Description Default Constraint
period Expected dominant cycle period 40 \geq 4

Super-Smoother Frequency Response

The SSF has -3 dB attenuation at the cutoff period, -12 dB/octave rolloff (2-pole), and zero phase lag at the cutoff. This is equivalent to a critically-damped Butterworth filter.

Pseudo-code

function SSFDSP(source, period):
    pFast ← max(2, round(period / 4))
    pSlow ← max(3, round(period / 2))

    // Fast SSF coefficients
    αf ← √2·π / pFast
    c2f ← 2·exp(-αf)·cos(αf)
    c3f ← -exp(-2·αf)
    c1f ← 1 - c2f - c3f

    // Slow SSF coefficients
    αs ← √2·π / pSlow
    c2s ← 2·exp(-αs)·cos(αs)
    c3s ← -exp(-2·αs)
    c1s ← 1 - c2s - c3s

    ssfFast_1 ← 0; ssfFast_2 ← 0
    ssfSlow_1 ← 0; ssfSlow_2 ← 0
    p_prev ← 0

    for each price in source:
        // Input averaging
        avg ← (price + p_prev) / 2

        // Fast SSF update
        ssfFast ← c1f·avg + c2f·ssfFast_1 + c3f·ssfFast_2

        // Slow SSF update
        ssfSlow ← c1s·avg + c2s·ssfSlow_1 + c3s·ssfSlow_2

        // SSFDSP
        ssfdsp ← ssfFast - ssfSlow

        // Shift state
        ssfFast_2 ← ssfFast_1; ssfFast_1 ← ssfFast
        ssfSlow_2 ← ssfSlow_1; ssfSlow_1 ← ssfSlow
        p_prev ← price

        emit ssfdsp

DSP vs SSFDSP

Aspect DSP (EMA-based) SSFDSP (Super-Smoother)
Filter type 1-pole IIR (exponential) 2-pole Butterworth
Rolloff -6 dB/octave -12 dB/octave
Phase lag at cutoff Non-zero Zero
Noise rejection Moderate Superior
Turning points Rounded Sharper

Output Interpretation

Condition Meaning
SSFDSP > 0 Bullish cycle phase
SSFDSP < 0 Bearish cycle phase
Zero crossing Cycle phase transition
Divergence with price Cycle energy waning; trend exhaustion
Amplitude shrinking Cycle losing dominance; transition to trend

Resources

  • Ehlers, J.F. Cybernetic Analysis for Stocks and Futures. Wiley, 2004.
  • Ehlers, J.F. Cycle Analytics for Traders. Wiley, 2013.
  • Butterworth, S. "On the Theory of Filter Amplifiers." Experimental Wireless, 7, 1930.