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§fn clone(&self) -> AdaptiveRsi
fn clone(&self) -> AdaptiveRsi
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§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 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 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§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