test(hv): widen geometric_series_yields_zero tolerance to 1e-6
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.
This commit is contained in:
@@ -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<f64> = (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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user