-
Couldn't load subscription status.
- Fork 161
Open
Description
let mut ker = EfficiencyRatio::new(14)?;
println!("1 {}", ker.next(1.69));
println!("2 {}", ker.next(1.69));
println!("3 {}", ker.next(1.70));
println!("4 {}", ker.next(1.70));
println!("5 {}", ker.next(1.69));Output:
1 1
2 NaN
3 1
4 1
5 0
If you keep passing 1.69, it subsequently outputs NaN.
ad hoc workaround
// https://github.com/greyblake/ta-rs/issues/73
struct FixEfficiencyRatio {
er: EfficiencyRatio,
}
impl FixEfficiencyRatio {
fn new(period: usize) -> ta::errors::Result<Self> {
Ok(Self {
er: EfficiencyRatio::new(period)?,
})
}
}
impl<T: Close> ta::Next<&T> for FixEfficiencyRatio {
type Output = f64;
fn next(&mut self, input: &T) -> f64 {
match self.er.next(input) {
v if v.is_nan() => 1.0,
v => v,
}
}
}KER implementation could be simplified with VecDeque.
Metadata
Metadata
Assignees
Labels
No labels