Files
QuanTAlib/lib/trends_FIR/_index.md
T
86fe32a682 SIMD Refactor: Merge simd-dev into dev (#55)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: aider (openrouter/anthropic/claude-sonnet-4) <aider@aider.chat>
Co-authored-by: Warp <agent@warp.dev>
2026-01-18 19:02:03 -08:00

4.2 KiB

Trends (FIR)

"FIR filters are always stable. The question is how many coefficients you need."  Digital Signal Processing folklore

Finite Impulse Response (FIR) trend indicators. These use fixed-length windows with explicit coefficients. No feedback loops, no recursion. Output depends only on current and past inputs. Always stable. Linear phase possible. SIMD-friendly batch computation.

Indicator Status

Indicator Full Name Status Description
ALMA Arnaud Legoux MA  Gaussian window with offset parameter. Smooth with configurable lag.
BLMA Blackman MA  Blackman window. Excellent side-lobe suppression (-58 dB).
BWMA Bessel-Weighted MA  Bessel window function. Good frequency resolution.
Conv Convolution MA  Generic convolution with custom kernel. Building block for others.
DWMA Double Weighted MA  WMA of WMA. Smoother than single WMA. Triangular-like response.
GWMA Gaussian Weighted MA  Centered Gaussian bell curve. No overshoot. controls width.
HAMMA Hamming MA  Hamming window. -43 dB side lobes. Good general purpose.
HANMA Hanning MA  Hanning (raised cosine). Zero at edges. Smooth roll-off.
HMA Hull MA  Reduced lag via weighted average differencing. Can overshoot.
HWMA Holt-Winters MA  Triple exponential smoothing. Tracks level, velocity, acceleration.
LSMA Least Squares MA  Linear regression endpoint. Extrapolates trend.
PWMA Pascal Weighted MA  Pascal's triangle coefficients. Binomial distribution weights.
SGMA Savitzky-Golay MA  Polynomial fit. Preserves higher moments. Shape-preserving.
SINEMA Sine-Weighted MA  Sine wave weighting. Smooth bell-shaped emphasis.
SMA Simple MA  Equal weights. Baseline reference. Lag = (N-1)/2.
TRIMA Triangular MA  Triangular weights. SMA of SMA. Emphasizes middle.
WMA Weighted MA  Linear weights. Recent prices weighted more. Lag < SMA.

Status Key:  Implemented | = Planned

Selection Guide

Use Case Recommended Why
Baseline comparison SMA Simple, well-understood. Reference for lag/smoothness.
Reduced lag HMA, WMA, LSMA HMA aggressive. WMA moderate. LSMA extrapolates.
Minimal overshoot GWMA, TRIMA Gaussian and triangular weights are gentle.
Spectral purity BLMA, HAMMA Window functions designed for frequency analysis.
Shape preservation SGMA Polynomial fit preserves peaks and valleys.
Configurable response ALMA, Conv ALMA has offset/sigma. Conv accepts any kernel.
Trend extrapolation LSMA, HWMA LSMA extends regression. HWMA tracks velocity.

FIR vs IIR Comparison

Aspect FIR (This Category) IIR (trends_IIR)
Stability Always stable Can be unstable if poorly designed
Phase Linear phase possible Nonlinear phase (causes distortion)
Coefficients Many (N = period) Few (2-4 typically)
Memory Higher Lower
Computation O(N) per sample, SIMD-friendly O(1) per sample, recursive
Lag Fixed for given N Can be lower for same smoothness
Overshoot Generally low Can overshoot (especially JMA, HMA)

Window Function Characteristics

Window Main Lobe Width Side Lobe (dB) Best For
Rectangular (SMA) Narrow -13 Frequency resolution
Hanning Medium -31 General purpose
Hamming Medium -43 Better side-lobe rejection
Blackman Wide -58 Excellent side-lobe rejection
Gaussian Configurable Configurable Tunable trade-off

Narrower main lobe = better frequency resolution. Lower side lobes = less spectral leakage.