npx claudepluginhub brainbytes-dev/everything-claude-tradingThis skill uses the workspace's default tool permissions.
name: signal-processing
Provides Ktor server patterns for routing DSL, plugins (auth, CORS, serialization), Koin DI, WebSockets, services, and testApplication testing.
Conducts multi-source web research with firecrawl and exa MCPs: searches, scrapes pages, synthesizes cited reports. For deep dives, competitive analysis, tech evaluations, or due diligence.
Provides demand forecasting, safety stock optimization, replenishment planning, and promotional lift estimation for multi-location retailers managing 300-800 SKUs.
name: signal-processing description: Signal processing for financial data — wavelets, Fourier analysis, noise filtering. Use when extracting signals from noisy financial data.
Financial data is dominated by noise. At daily frequency, the signal-to-noise ratio of equity returns is approximately 0.05 (annualized mean / annualized std). The challenge is extracting actionable structure without overfitting to noise.
Key principle: Every filter involves a tradeoff between smoothness (noise reduction) and responsiveness (lag). There is no lag-free noise reduction — any claim otherwise violates causality.
Any time series can be decomposed into sinusoidal components at different frequencies:
Financial returns are approximately white noise (flat spectrum), but squared returns and volatility show strong low-frequency power (persistence).
The Discrete Fourier Transform (DFT) decomposes a time series into frequency components:
X(f) = sum_{t=0}^{N-1} x(t) * exp(-2*pi*i*f*t/N)
Power spectrum: P(f) = |X(f)|^2
Interpretation:
- Peaks in P(f) indicate dominant cycles
- Frequency f corresponds to period T = N/f (in data units)
- For daily data: f=1 ~ 1-day cycle, f=21 ~ monthly cycle, f=252 ~ annual cycle
Practical issues:
- Spectral leakage: Apply window function (Hann, Hamming) before DFT
- Non-stationarity: Financial series change character over time — use short-window STFT
- Spurious cycles: Statistical test required (Fisher's test for periodicity)
Short-Time Fourier Transform (STFT):
Wavelets decompose a signal into components at multiple scales simultaneously, with both time and frequency localization — superior to Fourier for non-stationary data.
Multi-Resolution Analysis (MRA):
x(t) = A_J(t) + D_J(t) + D_{J-1}(t) + ... + D_1(t)
A_J: approximation at scale J (smoothest trend)
D_j: detail at scale j (oscillations at that scale)
For daily financial data with Daubechies-4 wavelet:
D1: 2-4 day oscillations (noise)
D2: 4-8 day oscillations (short-term)
D3: 8-16 day oscillations (swing trading)
D4: 16-32 day oscillations (monthly cycle)
D5: 32-64 day oscillations (quarterly cycle)
A5: trend component (> 64 days)
Wavelet choice:
Haar: Simplest, step-function. Good for detecting jumps.
Daubechies (db4-db8): Smooth, compact support. General purpose.
Symlets: Near-symmetric Daubechies. Reduced phase distortion.
Coiflets: Zero moments. Good for approximation.
Wavelet denoising procedure:
1. Decompose signal using DWT to level J
2. Apply thresholding to detail coefficients D1...DJ
- Hard threshold: set |D_j| < lambda to zero
- Soft threshold: shrink |D_j| by lambda toward zero (smoother)
3. Threshold selection:
- Universal: lambda = sigma * sqrt(2 * log(N))
- SURE (Stein Unbiased Risk Estimate): data-adaptive
- Level-dependent: different lambda for each scale
4. Reconstruct signal from thresholded coefficients
Data-adaptive decomposition that does not require pre-specified basis functions:
EMD decomposes x(t) into Intrinsic Mode Functions (IMFs):
x(t) = sum(IMF_k(t)) + residual(t)
Sifting process:
1. Find local maxima and minima of x(t)
2. Fit upper envelope (through maxima) and lower envelope (through minima)
3. Compute mean of envelopes: m(t)
4. IMF candidate: h(t) = x(t) - m(t)
5. Repeat until h(t) satisfies IMF conditions
6. Subtract IMF from signal, repeat for next IMF
Advantages:
- Fully data-adaptive, no basis function choice
- Handles non-linear, non-stationary data naturally
- IMFs have physical meaning (instantaneous frequency)
Disadvantages:
- Mode mixing: different scales can leak into same IMF
- No mathematical framework (empirical method)
- Ensemble EMD (EEMD) reduces mode mixing but is slower
Widely used in macroeconomics, applicable to financial trend extraction:
Minimize: sum(y_t - tau_t)^2 + lambda * sum((tau_{t+1} - 2*tau_t + tau_{t-1})^2)
tau_t: trend component
lambda: smoothing parameter
lambda = 1600 for quarterly macro data (convention)
lambda = 129600 for monthly data
lambda = 6.25 for annual data
For daily financial data: lambda = 10^6 to 10^8
Tradeoff: larger lambda = smoother trend (more lag)
Criticism: HP filter can produce spurious cycles at the boundary and generates artificial dynamics in random walk data. Use with awareness of these limitations.
Moving average variants:
Savitzky-Golay filter:
Butterworth filter:
Asset: [Name] | Frequency: Daily | Period: [Start]-[End]
Wavelet Decomposition (db4, 6 levels):
Scale | Period Range | Variance Share | Dominant Feature
D1 | 2-4 days | 42% | Noise / microstructure
D2 | 4-8 days | 18% | Short-term mean reversion
D3 | 8-16 days | 12% | Weekly cycle
D4 | 16-32 days | 10% | Monthly rotation
D5 | 32-64 days | 8% | Quarterly earnings
A5 | >64 days | 10% | Trend
Key Finding: 60% of variance is at scales D1-D2 (< 8 days).
Trend component (A5) is smooth and tradable with low turnover.
Denoised signal (A5+D5+D4) Sharpe: 0.65 vs raw: 0.42.
Goal | Recommended Filter | Key Parameter
Smooth trend extraction | EMA or Butterworth LP | Period > 50 days
Cycle isolation | Butterworth bandpass | Band: 20-60 days
Noise removal preserving peaks| Savitzky-Golay | Window=21, degree=3
Adaptive smoothing | KAMA or wavelet | ER threshold
Multi-scale decomposition | Wavelet (db4) | Levels: 5-7
Non-stationary cycle analysis | EMD / EEMD | Max IMFs: 8-10
Real-time trend (low lag) | Hull MA or KAMA | Period: 20-50
1. Visual inspection of raw signal
2. Compute power spectrum (FFT) — identify dominant frequencies
3. Choose denoising method based on signal characteristics:
- Stationary cycles: Fourier filtering
- Multi-scale, non-stationary: Wavelet denoising
- Simple trend: Moving average or Butterworth
4. Apply filter with initial parameters
5. Evaluate:
- Correlation between denoised signal and future returns
- Lag measurement (cross-correlation peak)
- Turnover of signal-based trades
- Sharpe ratio improvement vs raw signal
6. Optimize filter parameters via walk-forward cross-validation
7. Confirm no look-ahead bias (causal filter for live trading)
Before using signal processing in production trading: