pub struct AdaptiveRsi { /* private fields */ }Expand description
Adaptive RSI — Wilder’s RSI in which the smoothing of the average gain and average loss adapts to trendiness via Kaufman’s efficiency ratio, so the oscillator reacts fast in a clean move and smooths through chop.
ER = |price_t − price_{t−period}| / Σ |Δprice| over the window (efficiency ratio, 0..1)
sc = ( ER·(2/3 − 2/31) + 2/31 )² (KAMA smoothing constant)
avg_gain += sc·(gain − avg_gain), avg_loss += sc·(loss − avg_loss)
RSI = 100 · avg_gain / (avg_gain + avg_loss)A fixed-period Rsi is a compromise: short periods whip in
ranges, long ones lag in trends. This adaptive form borrows Kaufman’s
efficiency ratio (directional move / total path) to set the smoothing each
bar — near 1 (a clean trend) the averages track gains and losses almost
immediately; near 0 (noise) they barely move, filtering the chop. The result
is an RSI that is responsive when it should be and quiet when it should be. It
is the efficiency-ratio cousin of Ehlers’ cycle-adaptive RSI, which instead
sets the lookback from the measured dominant cycle.
Output is bounded in [0, 100]; a flat market returns the neutral 50. The
first value lands after period + 1 inputs. Each update is O(1).
§Example
use wickra_core::{Indicator, AdaptiveRsi};
let mut indicator = AdaptiveRsi::new(14).unwrap();
let mut last = None;
for i in 0..60 {
last = indicator.update(100.0 + (f64::from(i) * 0.3).sin() * 5.0);
}
assert!(last.is_some());Implementations§
Source§impl AdaptiveRsi
impl AdaptiveRsi
Trait Implementations§
Source§impl Clone for AdaptiveRsi
impl Clone for AdaptiveRsi
Source§impl Debug for AdaptiveRsi
impl Debug for AdaptiveRsi
Source§impl Indicator for AdaptiveRsi
impl Indicator for AdaptiveRsi
Source§fn update(&mut self, price: f64) -> Option<f64>
fn update(&mut self, price: 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.Source§fn is_ready(&self) -> bool
fn is_ready(&self) -> bool
Source§fn name(&self) -> &'static str
fn name(&self) -> &'static str
Source§fn batch_nan_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
fn batch_nan_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
Source§fn batch_fast_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
fn batch_fast_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
batch_nan_into, but
an indicator with a vectorised kernel may reassociate its arithmetic to
run it in SIMD lanes. Each value then agrees with the exact batch to within
the tolerance the indicator documents (a few units in the last place), not
bit for bit; warmup positions, NaN placement and the output length are
identical. The kernels are deterministic: the same input produces the same
bits on every platform, with or without SIMD hardware. Read moreAuto Trait Implementations§
impl Freeze for AdaptiveRsi
impl RefUnwindSafe for AdaptiveRsi
impl Send for AdaptiveRsi
impl Sync for AdaptiveRsi
impl Unpin for AdaptiveRsi
impl UnsafeUnpin for AdaptiveRsi
impl UnwindSafe for AdaptiveRsi
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