FerroWave · examples
Multi-scale variance
Decompose variance across time scales with the MODWT.
dwt_multilevel separates a signal into one approximation plus N detail bands,
each concentrating variance from a distinct frequency octave. The band variances
sum to the signal's total variance (Parseval), giving a clean attribution by
scale.
When to use it
- You want to know how much of your realized volatility lives at intraday vs daily vs weekly scale.
- You want a compact, interpretable multi-scale feature vector per window for a downstream model.
- You want an exact attribution — band variances that sum to the total by Parseval, not an approximation.
Example
use ferro_wave::{Signal, Daubechies, DaubechiesType,
BoundaryMode, dwt_multilevel};
let signal = Signal::from_slice(&log_returns);
let wavelet = Daubechies::new(DaubechiesType::Db4);
let decomp = dwt_multilevel(
&signal, &wavelet, 5,
BoundaryMode::Periodic,
)?;
// Variance per band — sums to signal.variance()
let bands: Vec<f64> = decomp.details.iter()
.map(|d| variance(d))
.collect();
// D1 ≈ intraday · D2-3 ≈ daily · D4-5 ≈ weekly+
# Ok::<(), ferro_wave::WaveletError>(())Notes
- Each detail band
Djconcentrates variance from one dyadic frequency octave; the approximationA5holds the residual trend. - For a shift-invariant version whose levels stay the input length, swap in
modwt_multileveland use the wavelet-variance energy identity.