pub struct Rsi { /* private fields */ }Expand description
Relative Strength Index (Wilder, 1978).
Uses Wilder’s smoothing (an EMA with alpha = 1 / period). The first output
is produced after period + 1 inputs: the seed averages the first period
gains and losses, and the first emitted RSI corresponds to the input at
index period.
§Example
use wickra_core::{Indicator, Rsi};
let mut indicator = Rsi::new(3).unwrap();
let mut last = None;
for i in 0..80 {
last = indicator.update(100.0 + f64::from(i));
}
assert!(last.is_some());Implementations§
Source§impl Rsi
impl Rsi
Sourcepub fn batch_nan(&mut self, inputs: &[f64]) -> Vec<f64>
pub fn batch_nan(&mut self, inputs: &[f64]) -> Vec<f64>
Vectorized batch returning one f64 per input (NaN during warmup).
Shadows the generic BatchNanExt::batch_nan blanket
default. RSI is a recursive (IIR) filter — Wilder smoothing — so it cannot
be SIMD-vectorized any more than the C peers manage; the win is purely in
stripping per-tick overhead. For a fresh indicator over an all-finite slice
long enough to seed (n > period) it runs the seed once and then the bare
smoothing recurrence in a tight loop with no per-tick is_finite/has_prev/
avgs_seeded branch and no Option, using the identical division at the
seed and mul_add/rsi_from_avgs afterwards — so it is bit-for-bit equal
to replaying update. Shorter or non-fresh/non-finite inputs defer to the
exact update replay.
Trait Implementations§
Source§impl Indicator for Rsi
impl Indicator for Rsi
Source§fn update(&mut self, input: f64) -> Option<f64>
fn update(&mut self, input: f64) -> Option<f64>
None if the indicator is still warming up.Source§fn reset(&mut self)
fn reset(&mut self)
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
None output can be produced.Auto Trait Implementations§
impl Freeze for Rsi
impl RefUnwindSafe for Rsi
impl Send for Rsi
impl Sync for Rsi
impl Unpin for Rsi
impl UnsafeUnpin for Rsi
impl UnwindSafe for Rsi
Blanket Implementations§
Source§impl<T> BatchExt for Twhere
T: Indicator,
impl<T> BatchExt for Twhere
T: Indicator,
Source§fn batch(&mut self, inputs: &[Self::Input]) -> Vec<Option<Self::Output>>
fn batch(&mut self, inputs: &[Self::Input]) -> Vec<Option<Self::Output>>
None during warmup) per input.Source§impl<T> BatchNanExt for T
impl<T> BatchNanExt for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more