FerroWave · examples

Jump detection

Detect jumps and discrete events in a return series using wavelet detail coefficients.

The Haar wavelet's detail coefficients spike sharply at discontinuities — exactly the shape of an overnight gap, a news-driven jump, or a regime shift. Threshold the finest detail against a robust noise estimate and you have an O(N), parameter-free jump locator.

When to use it

  • You want a fast, parameter-free locator for discontinuities in a price or signal series.
  • You want robust noise estimation (MAD) rather than a hand-tuned threshold.
  • You want the raw wavelet primitive. For a calibrated finance jump test with p-values and classification, see ferro_wave_finance's jump_event_signal.

Example

use ferro_wave::{Signal, Haar, BoundaryMode, dwt};
use ferro_wave::analysis::denoising::{estimate_noise_mad,
    compute_threshold, ThresholdRule};
 
let signal = Signal::from_slice(&prices);
let coeffs = dwt(&signal, &Haar::new(), BoundaryMode::Periodic)?;
 
// MAD-robust noise on the finest detail
let sigma     = estimate_noise_mad(&coeffs.detail);
let threshold = compute_threshold(
    &coeffs.detail, sigma, ThresholdRule::Universal,
    signal.len()); // universal uses N, not detail.len()
 
let jumps: Vec<usize> = coeffs.detail.iter()
    .enumerate()
    .filter(|(_, &d)| d.abs() > threshold)
    .map(|(i, _)| i * 2) // Haar stride
    .collect();
# Ok::<(), ferro_wave::WaveletError>(())

Notes

  • The detection threshold is the universal rule σ·√(2 ln N); compute is O(N) with no parameter tuning.
  • Haar detail at level 1 has stride 2, so coefficient index i maps back to sample i · 2.

Use the sanitized analysis API for threshold rules and noise-estimation variants.