pub struct Rwi { /* private fields */ }Expand description
Mike Poulos’ Random Walk Index — a trend-vs.-random-walk indicator that asks “how many standard deviations away from a random walk is the current move?”.
For each lookback i ∈ [2, period], RWI computes the ratio of the actual
price displacement over i bars to the expected displacement of a random
walk of the same length:
RWI_High_t(i) = (high_t − low_{t-i+1}) / (ATR_i(t) * sqrt(i))
RWI_Low_t(i) = (high_{t-i+1} − low_t) / (ATR_i(t) * sqrt(i))where ATR_i(t) is the simple average of true-range over the most recent
i bars. The reported RWI_High_t / RWI_Low_t are the maxima of these
ratios across all lookbacks i ∈ [2, period].
RWI_High crossing above RWI_Low and exceeding 1 (> 2 is the typical
strong-trend threshold) signals an uptrend dominating random-walk; the
mirror situation flags a downtrend. When both lines are below 1, neither
direction beats a random walk and the market is read as ranging.
The first output is emitted after period candles (the second one provides
the first period = 2 lookback, so the indicator emits at index
period - 1).
§Example
use wickra_core::{Candle, Indicator, Rwi};
let mut indicator = Rwi::new(14).unwrap();
let mut last = None;
for i in 0..80 {
let base = 100.0 + f64::from(i);
let candle =
Candle::new(base, base + 2.0, base - 2.0, base + 1.0, 10.0, i64::from(i)).unwrap();
last = indicator.update(candle);
}
assert!(last.is_some());Implementations§
Source§impl Rwi
impl Rwi
Sourcepub fn new(period: usize) -> Result<Self>
pub fn new(period: usize) -> Result<Self>
Construct a new RWI with the given lookback period.
§Errors
Returns Error::PeriodZero if period == 0.
Returns Error::InvalidPeriod if period < 2 — RWI’s shortest
lookback is i = 2, so a one-bar window would emit nothing.
Trait Implementations§
Source§impl Indicator for Rwi
impl Indicator for Rwi
Source§type Input = Candle
type Input = Candle
f64 for a price, or Candle / Tick).Source§fn update(&mut self, candle: Candle) -> Option<RwiOutput>
fn update(&mut self, candle: Candle) -> Option<RwiOutput>
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 Rwi
impl RefUnwindSafe for Rwi
impl Send for Rwi
impl Sync for Rwi
impl Unpin for Rwi
impl UnsafeUnpin for Rwi
impl UnwindSafe for Rwi
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