MCPcopy Create free account
hub / github.com/Open-Quant/openquant / test_ewma

Function test_ewma

crates/openquant/tests/fast_ewma.rs:23–30  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21
22#[test]
23fn test_ewma() {
24 let price_arr = load_prices();
25 let ewma_res = ewma(&price_arr, 20).unwrap();
26
27 assert_eq!(ewma_res.len(), price_arr.len());
28 assert_eq!(ewma_res[0], price_arr[0]);
29 // By hand: the first two prices are 1205 and 1005, alpha = 2 / 21, so the adjusted EWMA is
30 // (1005 + (19/21) 1205) / (1 + 19/21) = (21 * 1005 + 19 * 1205) / 40 = 44000 / 40 = 1100.
31 assert_eq!(&price_arr[..2], &[1205.0, 1005.0]);
32 assert!((ewma_res[1] - 1100.0).abs() < 1e-9);
33}

Callers

nothing calls this directly

Calls 2

ewmaFunction · 0.85
load_pricesFunction · 0.70

Tested by

no test coverage detected