Wavelets and Spectral Analysis for Trading
Financial time series contain activity at several horizons: microstructure effects last seconds, flows persist through a session, and macro regimes can last months. Frequency-domain tools help describe that structure. Fourier spectral analysis estimates how variance is distributed over stationary cycles; wavelets localize frequency in time, making them more suitable for changing markets.
Neither technique discovers a tradable cycle by itself. Price levels are nonstationary, periodograms are noisy, and a visually striking band can be the by-product of a calendar effect or data transformation. The appropriate question is operational: does a component measured strictly as of time t improve an out-of-sample forecast after turnover and costs?
Frequency, scale, and the data-generating process
The discrete Fourier transform represents a length-N series as sinusoidal basis functions. The periodogram at frequency f is proportional to squared Fourier magnitude. It is useful for diagnostics, such as detecting a 24-hour crypto-data artifact, but its raw estimates have high variance.
Wavelets use short, shifted basis functions. Fine scales capture high-frequency movement; coarse scales capture slow variation. A discrete wavelet transform (DWT) decomposes a series into detail coefficients Dj and an approximation AJ.
| Tool | Assumption | Strength | Frequent misuse |
|---|---|---|---|
| Periodogram | approximate stationarity | global periodic diagnostics | finding a “cycle” in prices |
| Welch spectrum | local stationarity | lower-variance spectrum | ignoring window sensitivity |
| DWT | localized multiscale behavior | compact features and denoising | boundary leakage |
| Wavelet coherence | time-varying co-movement | lead-lag exploration | causal interpretation |
Apply transforms to returns, demeaned residuals, or volatility proxies—not raw price levels—unless the nonstationarity is explicitly modeled. Use a consistent business-time grid; gap filling creates artificial low-frequency structure.
A causal wavelet feature
Standard DWT implementations are often two-sided: coefficients near the right edge depend on padding or future values. For a live signal, recompute features on each expanding historical prefix, use one-sided filters, or discard boundary coefficients. The following provides an exploratory decomposition, not a ready-made causal backtest:
import numpy as np
import pywt
def wavelet_energy(returns, wavelet="db4", level=4):
coeffs = pywt.wavedec(returns, wavelet=wavelet, level=level, mode="symmetric")
# coeffs[0] is low-frequency approximation; later entries are details
energy = [float(np.mean(c**2)) for c in coeffs]
return {"approx": energy[0],
**{f"detail_{level-i+1}": e for i, e in enumerate(energy[1:])}}
Build each feature from a trailing window ending before the decision timestamp. The boundary mode and wavelet family are hyperparameters. Selecting them after seeing Sharpe ratios is feature mining, so include them in the validation search budget described in feature engineering for trading.
Denoising without erasing information
Wavelet shrinkage thresholds small detail coefficients under the idea that they are noise. Soft thresholding is:
S_lambda(c) = sign(c) max(|c| - lambda, 0)
This can stabilize a trend estimate or a realized-volatility proxy. It can also remove exactly the brief discontinuities that carry news information. Train and evaluate an actual downstream task—forecast error, execution-quality estimate, or risk prediction—rather than judging a smoother chart.
| Observation | Interpretation | Research response |
|---|---|---|
| Energy rises only at finest scale | microstructure/noise or event activity | test spread and volume controls |
| Coarse-scale energy rises | trend or regime variance | test volatility targeting |
| One calendar frequency dominates | scheduling artifact possible | test exchange/session controls |
| Predictive feature unstable by sample | likely nonpersistent | shrink or reject |
Wavelet packet transforms offer a richer adaptive partition of frequency bands, but the large search space magnifies multiple testing. Use a fixed dictionary or nested chronological validation rather than choosing the best band on the test set.
Spectral leakage and false periodicity
Finite samples leak energy across frequencies, especially when a non-integer number of cycles fits the window. Tapers such as Hann windows reduce leakage but alter amplitude. Welch averaging reduces variance by averaging overlapping tapered segments. Both choices change results; report them.
Irregular timestamps need special care. The Lomb-Scargle periodogram can describe unevenly sampled data, but it does not repair asynchronous asset prices or stale observations. Synchronize with a defensible clock, and repeat analysis with alternative sampling intervals.
Portfolio use and validation
Useful applications include scale-specific volatility forecasts, trend signals that require agreement across horizons, and microstructure filters that reduce trading during high-frequency noise. Combine them with simple baselines: rolling volatility, moving-average trend, and the established machine learning trading pipeline.
Walk forward through independent regimes. Purge label overlap, impose a decision-to-fill delay, and calculate turnover at the same frequency as features. A band that predicts next-bar returns but requires full turnover every bar is usually not economic. Stability of sign, capacity, and conditional drawdowns should matter more than the highest isolated Sharpe.
Key takeaways
- Fourier methods describe global frequency structure; wavelets expose localized multiscale behavior.
- Transform stationary targets or residuals and make all features strictly causal.
- Denoising and band selection are model choices that require out-of-sample validation.
- Treat apparent cycles as hypotheses, then test costs, timing, and regime stability.
