diff --git a/ta_lib/core/src/bool.rs b/ta_lib/core/src/bool.rs index fd9d4c7f..6b8d52ef 100644 --- a/ta_lib/core/src/bool.rs +++ b/ta_lib/core/src/bool.rs @@ -1,6 +1,16 @@ use crate::series::Series; impl Series { + fn compare_series(&self, rhs: &Series, f: F) -> Series + where + F: Fn(f64, f64) -> bool, + { + self.zip_with(rhs, |a, b| match (a, b) { + (Some(a_val), Some(b_val)) => Some(f(*a_val, *b_val)), + _ => None, + }) + } + fn compare(&self, scalar: f64, f: F) -> Series where F: Fn(f64, f64) -> bool, @@ -31,4 +41,28 @@ impl Series { pub fn lte(&self, scalar: f64) -> Series { self.compare(scalar, |a, b| a <= b) } + + pub fn eq_series(&self, rhs: &Series) -> Series { + self.compare_series(rhs, |a, b| a == b) + } + + pub fn ne_series(&self, rhs: &Series) -> Series { + self.compare_series(rhs, |a, b| a != b) + } + + pub fn gt_series(&self, rhs: &Series) -> Series { + self.compare_series(rhs, |a, b| a > b) + } + + pub fn gte_series(&self, rhs: &Series) -> Series { + self.compare_series(rhs, |a, b| a >= b) + } + + pub fn lt_series(&self, rhs: &Series) -> Series { + self.compare_series(rhs, |a, b| a < b) + } + + pub fn lte_series(&self, rhs: &Series) -> Series { + self.compare_series(rhs, |a, b| a <= b) + } }