From ae8fcd90515a4d7f3f2b1498f2bd1101850c64e8 Mon Sep 17 00:00:00 2001 From: kingchenc Date: Sat, 23 May 2026 20:18:24 +0200 Subject: [PATCH] test(hv): widen geometric_series_yields_zero tolerance to 1e-6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The mathematical result of HistoricalVolatility on a perfectly geometric price series is exactly zero — but the underlying 1.01_f64.powi(i) + log-return + std-dev cascade accumulates platform-sensitive FP drift on the order of 1e-7 on x86_64 Linux and macOS (the Windows result happened to round closer to zero, which is why the test passed locally and on the Windows CI runner but failed on Linux and macOS). Bump the tolerance from 1e-9 to 1e-6. That stays four decimal places below any realistic annualised volatility value while comfortably absorbing the observed cross-platform drift. Also extend the comment to document the rationale so the next person who reads the test does not tighten it back down. --- .../wickra-core/src/indicators/historical_volatility.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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); } }