Quick Start
Get up and running with IronWave in minutes.
Installation
Add IronWave to your Cargo.toml:
[dependencies]
wavelet-rs = "0.8"
Basic Signal Processing
use iron_wave::{Signal, Haar, dwt, idwt, BoundaryMode};
fn main() -> iron_wave::Result<()> {
let signal = Signal::from_slice(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]);
let haar = Haar::new();
// Forward transform
let coeffs = dwt(&signal, &haar, BoundaryMode::Periodic)?;
// Perfect reconstruction
let reconstructed = idwt(&coeffs.approximation, &coeffs.detail,
&haar, BoundaryMode::Periodic)?;
assert_eq!(signal.data(), reconstructed.data());
Ok(())
}
Financial Time Series Analysis
use iron_wave::financial::*;
use iron_wave::wavelets::{Daubechies, DaubechiesType};
fn analyze_market_data(prices: &[f64]) -> iron_wave::Result<()> {
let returns = calculate_returns(prices);
let wavelet = Daubechies::new(DaubechiesType::Db4);
// Denoise market data
let clean_returns = denoise_modwt(
&returns,
&wavelet,
DenoiseConfig::default()
)?;
// Detect market regime
let detector = RegimeDetector::new(Box::new(wavelet.clone()), 3, 60);
let regime = detector.detect_regime(&clean_returns)?;
// Estimate volatility
let volatility = estimate_volatility(
&clean_returns,
&wavelet,
VolatilityConfig::default()
)?;
// Detect jumps
let jumps = detect_jumps(
prices,
&wavelet,
JumpDetectionConfig::default()
)?;
println!("Market Regime: {:?}", regime);
println!("Annualized Volatility: {:.2}%", volatility.total_volatility * 100.0);
println!("Jumps Detected: {}", jumps.jump_indices.len());
Ok(())
}
fn calculate_returns(prices: &[f64]) -> Vec<f64> {
prices.windows(2)
.map(|w| (w[1] - w[0]) / w[0])
.collect()
}
Multifractal Analysis
use iron_wave::analysis::multifractal::*;
use iron_wave::wavelets::{Daubechies, DaubechiesType};
use iron_wave::Signal;
fn analyze_persistence(returns: &[f64]) -> iron_wave::Result<()> {
let signal = Signal::new(returns.to_vec());
let wavelet = Daubechies::new(DaubechiesType::Db4);
// Estimate Hurst exponent for long-range dependence
let hurst = estimate_hurst_exponent(&signal, &wavelet, None)?;
println!("Hurst exponent: {:.4} +/- {:.4}",
hurst.hurst_exponent, hurst.confidence_interval);
println!("Interpretation: {}", hurst.interpretation());
println!("R^2 goodness of fit: {:.4}", hurst.r_squared);
// Interpret results:
// H < 0.5: Anti-persistent (mean-reverting)
// H = 0.5: Random walk (efficient market)
// H > 0.5: Persistent (trending)
if hurst.hurst_exponent > 0.6 {
println!("Signal shows persistence - consider trend-following strategies");
} else if hurst.hurst_exponent < 0.4 {
println!("Signal shows mean-reversion - consider statistical arbitrage");
}
// Compute multifractal spectrum via wavelet leaders
let config = MultifractalConfig::with_moments(-2.0, 2.0, 0.5)
.with_bootstrap_samples(0);
let spectrum = multifractal_spectrum(&signal, &wavelet, config)?;
println!("Spectrum width: {:.3}, alpha range = [{:.3}, {:.3}]",
spectrum.spectrum_width, spectrum.alpha_min, spectrum.alpha_max);
Ok(())
}
MODWT for Non-Stationary Signals
use iron_wave::{Signal, modwt_multilevel, imodwt_multilevel};
use iron_wave::wavelets::{Daubechies, DaubechiesType};
fn main() -> iron_wave::Result<()> {
// MODWT is ideal for financial data (shift-invariant, handles any length)
let signal = Signal::from_slice(&[1.0; 127]); // Any length works!
let db4 = Daubechies::new(DaubechiesType::Db4);
// Multi-level decomposition
let coeffs = modwt_multilevel(&signal, &db4, 3)?;
// Analyze different time scales
for (i, detail) in coeffs.wavelet_coeffs.iter().enumerate() {
let scale = 2_usize.pow(i as u32 + 1);
println!("Scale {}: {} samples", scale, detail.len());
}
// Perfect reconstruction
let reconstructed = imodwt_multilevel(&coeffs, &db4)?;
Ok(())
}
Running Tests and Benchmarks
# Run all tests
cargo test
# Run with optimizations (closer to production performance)
cargo test --release
# Run benchmarks
cargo bench
# Run specific example
cargo run --example financial_risk_management