diff --git a/crates/wickra-core/src/indicators/historical_volatility.rs b/crates/wickra-core/src/indicators/historical_volatility.rs index a67b2650..7b97b3c8 100644 --- a/crates/wickra-core/src/indicators/historical_volatility.rs +++ b/crates/wickra-core/src/indicators/historical_volatility.rs @@ -205,11 +205,17 @@ mod tests { #[test] fn geometric_series_yields_zero() { // A constant growth factor gives a constant log return -> zero stddev. + // The mathematical result is exactly zero, but `1.01_f64.powi(i)` and + // the subsequent log / std-dev cascade accumulate platform-sensitive + // floating-point drift on the order of 1e-7 (observed on x86_64 Linux + // and macOS; Windows happens to round closer to zero). The 1e-6 + // tolerance stays four decimal places below any realistic volatility + // value while absorbing this drift across every supported platform. let mut hv = HistoricalVolatility::new(10, 252).unwrap(); let prices: Vec = (0..40).map(|i| 100.0 * 1.01_f64.powi(i)).collect(); let out = hv.batch(&prices); for v in out.iter().skip(10).flatten() { - assert_relative_eq!(*v, 0.0, epsilon = 1e-9); + assert_relative_eq!(*v, 0.0, epsilon = 1e-6); } }