Skip to content

Commit

Permalink
split
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Aug 1, 2023
1 parent 01d9ff0 commit 4969c99
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions ta_lib/patterns/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ pub mod doji;
pub mod double_doji;
pub mod marubozu;
pub mod shrinking;
pub mod split;
pub mod tasuki;
64 changes: 64 additions & 0 deletions ta_lib/patterns/src/split.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use core::series::Series;

pub fn bullish(open: &[f64], high: &[f64], low: &[f64], close: &[f64]) -> Vec<bool> {
let open = Series::from(open);
let high = Series::from(high);
let low = Series::from(low);
let close = Series::from(close);

(close.shift(1).lt(&open.shift(1))
& open.shift(1).lt(&high.shift(1))
& close.shift(1).eq(&low.shift(1))
& close.gt(&open)
& close.eq(&high)
& open.gt(&low)
& close.gt(&open.shift(1)))
.into()
}

pub fn bearish(open: &[f64], high: &[f64], low: &[f64], close: &[f64]) -> Vec<bool> {
let open = Series::from(open);
let high = Series::from(high);
let low = Series::from(low);
let close = Series::from(close);

(close.shift(1).gt(&open.shift(1))
& open.shift(1).gt(&low.shift(1))
& close.shift(1).eq(&high.shift(1))
& close.lt(&open)
& close.eq(&low)
& open.lt(&high)
& close.lt(&open.shift(1)))
.into()
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_split_bullish() {
let open = vec![4.0, 3.0, 4.0, 3.0, 4.0];
let high = vec![4.5, 3.5, 4.5, 3.5, 4.5];
let low = vec![4.0, 3.0, 4.0, 3.0, 4.0];
let close = vec![4.5, 3.5, 4.5, 3.5, 4.5];
let expected = vec![false, false, false, false, false];

let result = bullish(&open, &high, &low, &close);

assert_eq!(result, expected);
}

#[test]
fn test_split_bearish() {
let open = vec![4.0, 3.0, 4.0, 3.0, 4.0];
let high = vec![4.0, 3.0, 4.0, 3.0, 4.0];
let low = vec![3.5, 2.5, 3.5, 2.5, 3.5];
let close = vec![3.5, 2.5, 3.5, 2.5, 3.5];
let expected = vec![false, false, false, false, false];

let result = bearish(&open, &high, &low, &close);

assert_eq!(result, expected);
}
}

0 comments on commit 4969c99

Please sign in to comment.