pub struct RviVolatility { /* private fields */ }Expand description
Relative Volatility Index — Donald Dorsey’s RSI-shaped volatility gauge.
Where RSI partitions price changes into gains and losses and Wilder-smooths each side, RVI partitions the rolling standard deviation of price into “up volatility” (when price rose since the previous bar) and “down volatility” (when price fell), then applies the same Wilder smoothing and ratio:
sd_t = stddev_pop(close over `period`) // single scalar each bar
up_t = sd_t if close_t > close_{t-1}, else 0
down_t = sd_t if close_t < close_{t-1}, else 0
AvgUp_t = Wilder(up, period)
AvgDown_t = Wilder(down, period)
RVI_t = 100 · AvgUp_t / (AvgUp_t + AvgDown_t)The output is bounded on [0, 100]. A series with no down-bars saturates
at 100; a series with no up-bars saturates at 0. A completely flat
series (no movement, both averages zero) returns 50 by the same
undefined-RS convention as RSI (crates/wickra-core/src/indicators/rsi.rs).
§Example
use wickra_core::{Indicator, RviVolatility};
let mut indicator = RviVolatility::new(10).unwrap();
let mut last = None;
for i in 0..80 {
last = indicator.update(100.0 + (f64::from(i) * 0.3).sin() * 5.0);
}
assert!(last.is_some());Implementations§
Source§impl RviVolatility
impl RviVolatility
Sourcepub fn new(period: usize) -> Result<Self>
pub fn new(period: usize) -> Result<Self>
Construct an RVI with the given period.
period is used both as the standard-deviation window length and as
the Wilder smoothing constant for the up/down averages.
§Errors
Returns Error::PeriodZero if period == 0, or
Error::InvalidPeriod if period == 1 (a 1-bar rolling standard
deviation is always zero and the indicator would never produce a
meaningful reading).
Trait Implementations§
Source§impl Clone for RviVolatility
impl Clone for RviVolatility
Source§fn clone(&self) -> RviVolatility
fn clone(&self) -> RviVolatility
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 RviVolatility
impl Debug for RviVolatility
Source§impl Indicator for RviVolatility
impl Indicator for RviVolatility
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 RviVolatility
impl RefUnwindSafe for RviVolatility
impl Send for RviVolatility
impl Sync for RviVolatility
impl Unpin for RviVolatility
impl UnsafeUnpin for RviVolatility
impl UnwindSafe for RviVolatility
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