Skip to content

Filter Methods

The Mathematics of Market Signal Processing

Section titled “The Mathematics of Market Signal Processing”
📐 Technical Reference

Like master craftsmen who understand not just how to use their tools but why they work, this guide unveils the mathematical foundations underlying our curated collection of digital signal processing filters. Here, we bridge the gap between academic DSP theory and practical trading applications.

Financial markets generate time series data with unique characteristics that challenge traditional DSP approaches:

Non-Stationarity

Unlike audio signals, market data exhibits regime changes where statistical properties shift dramatically. Filters must adapt or maintain robustness across these transitions.

Heavy Tails

Price movements follow distributions with fatter tails than Gaussian, requiring filters that handle extreme events gracefully without distortion.

Multi-Scale Dynamics

Markets operate on multiple timescales simultaneously — from microsecond arbitrage to decade-long cycles. Effective filters must isolate relevant scales.

The Discrete Fourier Transform (DFT) decomposes price series into frequency components:

X(k) = Σ(n=0 to N-1) x(n) × e^(-j2πkn/N)

Where:

  • x(n) = price at time n
  • X(k) = frequency component k
  • N = number of samples

This reveals the cyclical patterns hidden in price data.

Low-pass filters attenuate high-frequency noise while preserving trend information. In trading, these create smoothed price representations for trend following.

The general form of an Infinite Impulse Response (IIR) low-pass filter:

y[n] = Σ(i=0 to M) bᵢ×x[n-i] - Σ(j=1 to N) aⱼ×y[n-j]

Where:

  • bᵢ = feedforward coefficients
  • aⱼ = feedback coefficients
  • M, N = filter orders

2-Pole Butterworth Design

Critical frequency: ωc = √2 × π / period
Pole location: a₁ = e^(-ωc)
Transfer function:
H(z) = K × (1 + 2z⁻¹ + z⁻²)/(1 - 2a₁cos(ωc)z⁻¹ + a₁²z⁻²)
Where K ensures unity gain at DC

Characteristics:

  • Maximally flat passband
  • -12dB/octave rolloff
  • Minimal phase distortion

MESA Adaptive Moving Average (MAMA)

MAMA adjusts its smoothing based on the dominant market cycle:

1. Hilbert Transform extracts phase:
HT(x) = 0.0962×x + 0.5769×x[2] - 0.5769×x[4] - 0.0962×x[6]
2. Homodyne Discriminator finds period:
Phase difference → Instantaneous period
3. Adaptive alpha:
α = FastLimit / DeltaPhase (constrained by SlowLimit)
4. Dual-speed smoothing:
MAMA = α×price + (1-α)×MAMA[1]
FAMA = α/2×MAMA + (1-α/2)×FAMA[1]

The result adapts to market conditions, tightening during trends and loosening during cycles.

High-pass filters remove trend components to isolate short-term fluctuations, creating oscillators for mean reversion strategies.

Transfer Function:
H(z) = K × (1 - z⁻¹)/(1 - αz⁻¹)
Where:
ω = π / period
α = e^(-ω)
K = (1 - α)/2
Implementation:
y[n] = K×(x[n] - x[n-1]) + α×y[n-1]

Properties:

  • 6dB/octave rolloff
  • 45° phase lead at cutoff
  • Minimal lag

Band-pass filters extract specific frequency ranges, ideal for identifying market cycles.

A band-pass filter combines high-pass and low-pass characteristics:

Centre frequency: f₀ = 1/period
Bandwidth: BW (in frequency units)
Quality factor: Q = f₀/BW
Transfer function peak at f₀
Attenuation outside passband
Centre frequency: fc = 0.5/period
ω = 2π × fc
Bandwidth to Q conversion:
Q = 1/(2×sinh(ln(2)/2 × BW × ω/sin(ω)))
Filter coefficients:
α = sin(ω)×sinh(ln(2)/2 × Q × ω/sin(ω))
b₀ = sin(ω)/2 × 1/(1+α)
b₁ = 0
b₂ = -b₀
a₁ = -2cos(ω) × 1/(1+α)
a₂ = (1-α) × 1/(1+α)

Mathematical Basis The Voss filter achieves negative group delay through anticipatory coupling:

Filter order: N = 3 × prediction_horizon
Output computation:
y[n] = 0.5×(3+N)×x[n] - Σ(i=0 to N-1)((i+1)/N × y[n-N+i])
Key insight: Weighted feedback creates phase lead
Limitation: Input must be band-limited
Practical range: 1-3 bars prediction

Critical Understanding: Prediction is only valid for band-limited signals. Raw price cannot be meaningfully predicted; only filtered components.

Group Delay Formula:

τg(ω) = -d(∠H(e^jω))/dω

Measures filter delay at each frequency. Zero-lag filters achieve τg ≈ 0 in passband.

# Recalculate only on parameter change
if period != period[1]:
omega = calculate_omega(period)
update_coefficients(omega)
# Use cached coefficients for filtering
output = apply_filter(input, cached_coefficients)

Cascade architectures, or serial processing chains, allow complex signal processing by chaining multiple filters together:

  1. Noise → Trend → Cycle:

    • Stage 1: SuperSmoother (remove noise)
    • Stage 2: High-pass (remove trend)
    • Result: Clean cycle component
  2. Adaptive Cascade:

    • Stage 1: MAMA (adaptive smoothing)
    • Stage 2: Ultimate Smoother (zero-lag refinement)
    • Result: Responsive yet stable signal
  3. Predictive Chain:

    • Stage 1: Band-pass (isolate cycle)
    • Stage 2: Voss Predictive (forecast cycle)
    • Result: Anticipatory signals

While not implemented in FiltersToolkit, wavelet concepts inspire multi-scale approaches:

Price = Trend + Cycles + Noise
Trend: Ultimate Smoother (long period)
Cycles: Multiple band-pass filters
Noise: Residual after filtering

Cryptocurrency

  • 24/7 trading requires robust startup handling
  • High volatility benefits from adaptive approaches
  • Consider shorter periods due to rapid evolution

Forex

  • Lower noise allows aggressive filtering
  • Session-based adjustments recommended
  • Longer periods capture macro trends

Equities

  • Opening gaps require special handling
  • Intraday vs daily filtering differs significantly
  • Volume-dependent variants often superior

This mathematical reference is part of our commitment to sharing institutional-grade DSP knowledge with the trading community. By documenting these foundations, we enable traders to:

  • Understand the mathematical principles behind effective filtering
  • Implement custom variations for specific needs
  • Contribute improvements to the community
  • Build upon proven methodologies

Related Open Source Resources:

  • Practical Implementation: Explore our FiltersToolkit for hands-on experimentation
  • Specific Filters: Deep dive into the Ultimate Smoother or other implementations
  • Custom Development: Use these mathematical foundations to create your own filters
  • Community Discussion: Share insights in our Discord channel

Join Our Trading Community

Connect with fellow traders, share insights, and learn together.

Join Discord

“Mathematics is the language in which the universe speaks. In financial markets, filters are our translators—converting the cacophony of price action into comprehensible signals. Master the mathematics, master the message.” 📊