diff --git a/benches/traquer.rs b/benches/traquer.rs index f65a72e..60f42f2 100644 --- a/benches/traquer.rs +++ b/benches/traquer.rs @@ -292,7 +292,7 @@ fn criterion_benchmark(c: &mut Criterion) { b.iter(|| black_box(momentum::disparity(&stats.close, 16).collect::>())) }); c.bench_function("sig-momentum-tsi", |b| { - b.iter(|| black_box(momentum::tsi(&stats.close, 6, 10, 3).collect::>())) + b.iter(|| black_box(momentum::tsi(&stats.close, 6, 10).collect::>())) }); c.bench_function("sig-momentum-special_k", |b| { b.iter(|| black_box(momentum::special_k(&stats.close).collect::>())) diff --git a/src/momentum.rs b/src/momentum.rs index b67066a..e153a63 100644 --- a/src/momentum.rs +++ b/src/momentum.rs @@ -1301,15 +1301,14 @@ pub fn psych(data: &[T], window: usize) -> impl Iterator>(); +/// 3, 6).collect::>(); /// /// ``` pub fn tsi( data: &[T], short: usize, long: usize, - signal: usize, -) -> impl Iterator + '_ { +) -> impl Iterator + '_ { let diffs = data .windows(2) .map(|pair| pair[1].to_f64().unwrap() - pair[0].to_f64().unwrap()) @@ -1326,15 +1325,7 @@ pub fn tsi( .zip(abs_pcds) .map(|(pcd, apcd)| 100.0 * pcd / apcd) .collect::>(); - let signal = iter::repeat(f64::NAN) - .take(short - 1) - .chain(smooth::ewma(&tsi[short - 1..], signal)); - iter::repeat((f64::NAN, f64::NAN)).take(long).chain( - tsi.iter() - .zip(signal) - .map(|(&x, y)| (x, y)) - .collect::>(), - ) + iter::repeat(f64::NAN).take(long).chain(tsi) } /// Pring's Special K diff --git a/tests/momentum_test.rs b/tests/momentum_test.rs index aa8a93e..c59854f 100644 --- a/tests/momentum_test.rs +++ b/tests/momentum_test.rs @@ -1180,7 +1180,7 @@ fn test_psych() { #[test] fn test_tsi() { let stats = common::test_data(); - let (tsi, tsi_sig): (Vec, Vec) = momentum::tsi(&stats.close, 6, 10, 3).unzip(); + let tsi: Vec = momentum::tsi(&stats.close, 6, 10).collect(); assert_eq!(stats.close.len(), tsi.len()); assert_eq!( vec![ @@ -1206,28 +1206,6 @@ fn test_tsi() { ], tsi[15..] ); - assert_eq!( - vec![ - -11.901736158099775, - -12.240208722437886, - -12.289327166384927, - -10.991640654357855, - -8.530253464421122, - -5.601551181836266, - -3.7880858146019802, - 1.4475747198659064, - 7.983461323250848, - 10.65262893880699, - 13.50756522794859, - 18.206767909525055, - 20.489542773794945, - 23.61778069502798, - 27.76303682465747, - 33.64024394535278, - 33.98750951181481, - ], - tsi_sig[15 + 2..] - ); } #[test]