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§
Trait Implementations§
Source§impl Indicator for Rsi
impl Indicator for Rsi
Source§fn batch_nan_into(&mut self, inputs: &[f64], out: &mut [f64])
fn batch_nan_into(&mut self, inputs: &[f64], out: &mut [f64])
RSI is a recursive (IIR) filter — Wilder smoothing — so its exact form
cannot run in SIMD lanes; the win is 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 every value is
bit-for-bit equal to replaying update. Shorter or non-fresh/non-finite
inputs defer to the exact update replay.
Source§fn batch_fast_into(&mut self, inputs: &[f64], out: &mut [f64])
fn batch_fast_into(&mut self, inputs: &[f64], out: &mut [f64])
SIMD kernel: the exact seed, then blocks of gains and losses whose two
Wilder averages run as linear-recurrence scans, combined as
100 · ag / (ag + al). Agrees with the exact batch to within a few units
in the last place; the seed value, warmup NaNs and length are
identical. Afterwards the RSI continues streaming from the kernel’s last
averages.
Source§fn update(&mut self, input: f64) -> Option<f64>
fn update(&mut self, input: f64) -> Option<f64>
None if there is no value for this input. Read moreSource§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§fn batch_nan(&mut self, inputs: &[f64]) -> Vec<f64>
fn batch_nan(&mut self, inputs: &[f64]) -> Vec<f64>
f64 per input, warmup positions filled with NaN, bit-for-bit equal
to replaying update.Source§fn batch_fast(&mut self, inputs: &[f64]) -> Vec<f64>
fn batch_fast(&mut self, inputs: &[f64]) -> Vec<f64>
Indicator::batch_fast_into) into a fresh
vector: within the indicator’s documented tolerance of
batch_nan, deterministic across platforms.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