()
| 21 | |
| 22 | #[test] |
| 23 | fn 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 | } |
nothing calls this directly
no test coverage detected