pub struct AnchoredRsi { /* private fields */ }Expand description
Anchored RSI — a cumulative Relative Strength Index whose averaging begins at a user-chosen anchor bar rather than over a fixed Wilder period.
Where crate::Rsi uses Wilder’s period-length smoothing, Anchored RSI
accumulates every up- and down-move since the anchor with equal weight, so
it answers “what is the RSI of the entire move since the anchor point?”. The
running relative strength is Σ gains / Σ losses over all bars in the
current anchor window (the bar count cancels, so this equals
avg_gain / avg_loss):
RSI_t = 100 - 100 / (1 + Σ_{i ≥ anchor} gain_i / Σ_{i ≥ anchor} loss_i)As with crate::AnchoredVwap, the anchor is chosen at runtime:
AnchoredRsi::set_anchor re-anchors at the next bar that arrives,
clearing the running sums. Because RSI needs a price change, the first bar
of a fresh anchor window only seeds the previous close and emits None; the
first value follows on the second bar (warmup period 2).
Saturation follows the standard convention: a window with no losses yet (and at least one gain) reads 100, no gains yet reads 0, and a perfectly flat window reads the neutral 50. Non-finite inputs are ignored, leaving the last value unchanged.
§Example
use wickra_core::{AnchoredRsi, Indicator};
let mut indicator = AnchoredRsi::new();
let mut last = None;
for i in 0..80 {
let price = 100.0 + (f64::from(i) * 0.5).sin() * 5.0;
// Re-anchor at bar 40 (e.g. a major swing low).
if i == 40 {
indicator.set_anchor();
}
last = indicator.update(price);
}
assert!(last.is_some());Implementations§
Source§impl AnchoredRsi
impl AnchoredRsi
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Construct a fresh Anchored RSI. The first bar to arrive is the anchor.
Sourcepub fn set_anchor(&mut self)
pub fn set_anchor(&mut self)
Mark a re-anchor: the next Indicator::update call clears the
running sums and previous close before folding in its own bar, starting
a fresh anchored window.
Trait Implementations§
Source§impl Clone for AnchoredRsi
impl Clone for AnchoredRsi
Source§fn clone(&self) -> AnchoredRsi
fn clone(&self) -> AnchoredRsi
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 AnchoredRsi
impl Debug for AnchoredRsi
Source§impl Default for AnchoredRsi
impl Default for AnchoredRsi
Source§fn default() -> AnchoredRsi
fn default() -> AnchoredRsi
Source§impl Indicator for AnchoredRsi
impl Indicator for AnchoredRsi
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 AnchoredRsi
impl RefUnwindSafe for AnchoredRsi
impl Send for AnchoredRsi
impl Sync for AnchoredRsi
impl Unpin for AnchoredRsi
impl UnsafeUnpin for AnchoredRsi
impl UnwindSafe for AnchoredRsi
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> 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