Skip to content

Commit

Permalink
marubozu
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Jul 27, 2023
1 parent 248d3d7 commit 67ae7e7
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 10 deletions.
7 changes: 7 additions & 0 deletions ta_lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ta_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
members = [
"core",
"momentum",
"patterns",
"price",
"trend",
"volatility",
Expand Down
4 changes: 2 additions & 2 deletions ta_lib/core/src/series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ impl<T> IntoIterator for Series<T> {

impl Into<Vec<f64>> for Series<f64> {
fn into(self) -> Vec<f64> {
self.into_iter().filter_map(|x| x).collect()
self.data.into_iter().map(|x| x.unwrap_or(0.0)).collect()
}
}

impl Into<Vec<bool>> for Series<bool> {
fn into(self) -> Vec<bool> {
self.into_iter().filter_map(|x| x).collect()
self.data.into_iter().map(|x| x.unwrap_or(false)).collect()
}
}

Expand Down
1 change: 1 addition & 0 deletions ta_lib/patterns/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ version = "0.1.0"
edition = "2021"

[dependencies]
core = { path = "../core" }
1 change: 1 addition & 0 deletions ta_lib/patterns/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod marubozu;
16 changes: 8 additions & 8 deletions ta_lib/patterns/src/marubozu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ pub fn bullish(open: &[f64], high: &[f64], low: &[f64], close: &[f64]) -> Vec<bo
let low = Series::from(low);
let close = Series::from(close);

close.shift(1) > open.shift(1)
&& high.shift(1) == close.shift(1)
&& low.shift(1) == open.shift(1)
(close.shift(1).gt_series(&open.shift(1))
& high.shift(1).eq_series(&close.shift(1))
& low.shift(1).eq_series(&open.shift(1))).into()
}

pub fn bearish(open: &[f64], high: &[f64], low: &[f64], close: &[f64]) -> Vec<bool> {
Expand All @@ -17,9 +17,9 @@ pub fn bearish(open: &[f64], high: &[f64], low: &[f64], close: &[f64]) -> Vec<bo
let low = Series::from(low);
let close = Series::from(close);

close.shift(1) < open.shift(1)
&& high.shift(1) == open.shift(1)
&& low.shift(1) == close.shift(1)
(close.shift(1).lt_series(&open.shift(1))
& high.shift(1).eq_series(&open.shift(1))
& low.shift(1).eq_series(&close.shift(1))).into()
}

#[cfg(test)]
Expand All @@ -32,7 +32,7 @@ mod tests {
let high = vec![3.0, 3.0, 3.0, 3.0, 3.0];
let low = vec![1.0, 1.0, 1.0, 1.0, 1.0];
let close = vec![2.0, 2.5, 2.0, 1.5, 2.0];
let expected = vec![true, true, true, true, true];
let expected = vec![false, false, false, false, false];

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

Expand All @@ -45,7 +45,7 @@ mod tests {
let high = vec![3.0, 3.0, 3.0, 3.0, 3.0];
let low = vec![1.0, 1.0, 1.0, 1.0, 1.0];
let close = vec![2.0, 2.5, 2.0, 1.5, 2.0];
let expected = vec![true, true, true, true, true];
let expected = vec![false, false, false, false, false];

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

Expand Down

0 comments on commit 67ae7e7

Please sign in to comment.