extern crate tars; use tars::momentum_indicators::rsi::rsi; use tars::helpers::round_array; // Some randomly generated data to test against TA-Lib (see generate_data.py & correct_values.py) const OPEN: &[f64] = &[1984.03, 1959.83, 2041.42, 2019.04, 1969.53, 2082.75, 2209.52, 2200.9, 2364.04, 2543.32, 2423.95, 2483.28, 2604.88, 2393.81, 2231.27, 2420.82, 2544.0, 2766.67, 2919.62, 2763.25]; const HIGH: &[f64] = &[2174.72, 2129.49, 2158.92, 2050.2, 2042.12, 2151.19, 2220.64, 2352.98, 2456.25, 2691.53, 2572.81, 2494.14, 2845.93, 2682.66, 2527.13, 2455.68, 2607.54, 2872.17, 3004.26, 3036.05]; const LOW: &[f64] = &[1934.7, 1921.02, 1793.77, 1887.36, 1919.72, 1868.23, 1991.19, 2011.08, 2193.91, 2183.96, 2223.15, 2363.19, 2240.03, 2208.31, 2192.15, 2199.02, 2311.16, 2463.15, 2651.8, 2749.42]; const CLOSE: &[f64] = &[1959.83, 2041.42, 2019.04, 1969.53, 2082.75, 2209.52, 2200.9, 2364.04, 2543.32, 2423.95, 2483.28, 2604.88, 2393.81, 2231.27, 2420.82, 2544.0, 2766.67, 2919.62, 2763.25, 2922.14]; #[test] fn rsi_works() { let mut result = rsi(CLOSE, 6).unwrap(); let expected = &[79.9771, 86.5336, 90.5949, 73.0035, 75.8056, 80.7258, 56.706, 44.4766, 57.3488, 63.879, 72.8847, 77.5072, 64.1009, 70.3536]; round_array(result.as_mut(), 4); assert_eq!(result, expected); }