Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Apr 24, 2024
1 parent fd89e3d commit a800229
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ta_lib/strategies/confirm/src/dso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,6 @@ mod tests {
let result_short_signal: Vec<bool> = short_signal.into();

assert_eq!(result_long_signal, expected_long_signal);
assert_eq!(expected_short_signal, result_short_signal);
assert_eq!(result_short_signal, expected_short_signal);
}
}
100 changes: 100 additions & 0 deletions ta_lib/strategies/confirm/src/vi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,103 @@ impl Confirm for ViConfirm {
(vip.sgt(&vim), vip.slt(&vim))
}
}

#[cfg(test)]
mod tests {
use super::*;
use core::prelude::*;
use std::collections::VecDeque;

#[test]
fn test_confirm_vi() {
let confirm = ViConfirm::new(1.0, 3.0);
let data = VecDeque::from([
OHLCV {
open: 6.490,
high: 6.514,
low: 6.490,
close: 6.511,
volume: 100.0,
},
OHLCV {
open: 6.511,
high: 6.522,
low: 6.506,
close: 6.512,
volume: 100.0,
},
OHLCV {
open: 6.512,
high: 6.513,
low: 6.496,
close: 6.512,
volume: 100.0,
},
OHLCV {
open: 6.512,
high: 6.528,
low: 6.507,
close: 6.527,
volume: 100.0,
},
OHLCV {
open: 6.527,
high: 6.530,
low: 6.497,
close: 6.500,
volume: 100.0,
},
OHLCV {
open: 6.500,
high: 6.508,
low: 6.489,
close: 6.505,
volume: 100.0,
},
OHLCV {
open: 6.505,
high: 6.510,
low: 6.483,
close: 6.492,
volume: 100.0,
},
OHLCV {
open: 6.492,
high: 6.496,
low: 6.481,
close: 6.491,
volume: 100.0,
},
OHLCV {
open: 6.491,
high: 6.512,
low: 6.486,
close: 6.499,
volume: 100.0,
},
OHLCV {
open: 6.499,
high: 6.500,
low: 6.481,
close: 6.486,
volume: 100.0,
},
]);
let series = OHLCVSeries::from_data(&data);

let (long_signal, short_signal) = confirm.validate(&series);

let expected_long_signal = vec![
false, true, true, true, false, false, false, false, true, false,
];
let expected_short_signal = vec![
false, false, false, false, true, true, true, true, false, true,
];

let result_long_signal: Vec<bool> = long_signal.into();
let result_short_signal: Vec<bool> = short_signal.into();

assert_eq!(result_long_signal, expected_long_signal);
assert_eq!(result_short_signal, expected_short_signal);
}
}

0 comments on commit a800229

Please sign in to comment.