pub struct VolatilityRatio { /* private fields */ }Expand description
Schwager’s Volatility Ratio — the current bar’s true range divided by the exponential moving average of the prior true ranges.
TR_t = true range of bar t
VR_t = TR_t / EMA_n(TR through bar t−1)Jack Schwager’s volatility ratio measures how today’s range compares to its
recent typical level: a reading above 2.0 marks a wide-ranging day —
today’s true range is more than twice the smoothed average — which often
precedes or accompanies a reversal. The denominator is the exponential
moving average of true range excluding the current bar, seeded with the
simple average of the first period true ranges, so a single large bar
stands out instead of inflating its own benchmark.
True range is max(high − low, |high − prev_close|, |low − prev_close|),
identical to the Atr building block, but here it is compared
to a standard EMA (smoothing 2 / (period + 1)) rather than Wilder
smoothing, which keeps the ratio distinct from TR / ATR. Each update is
O(1).
A flat market drives every true range — and the EMA — to 0; the ratio is
then 0.0 rather than an undefined 0 / 0. Candle::new rejects non-finite
fields, so no in-method finiteness guard is needed.
§Example
use wickra_core::{Candle, Indicator, VolatilityRatio};
let mut indicator = VolatilityRatio::new(14).unwrap();
let mut last = None;
for i in 0..40 {
let base = 100.0 + f64::from(i);
let candle = Candle::new(base, base + 2.0, base - 1.0, base + 0.5, 1_000.0, 0).unwrap();
last = indicator.update(candle);
}
assert!(last.is_some());Implementations§
Source§impl VolatilityRatio
impl VolatilityRatio
Trait Implementations§
Source§impl Clone for VolatilityRatio
impl Clone for VolatilityRatio
Source§fn clone(&self) -> VolatilityRatio
fn clone(&self) -> VolatilityRatio
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 VolatilityRatio
impl Debug for VolatilityRatio
Source§impl Indicator for VolatilityRatio
impl Indicator for VolatilityRatio
Source§type Input = Candle
type Input = Candle
f64 for a price, or Candle / Tick).Source§fn update(&mut self, candle: Candle) -> Option<f64>
fn update(&mut self, candle: Candle) -> 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 VolatilityRatio
impl RefUnwindSafe for VolatilityRatio
impl Send for VolatilityRatio
impl Sync for VolatilityRatio
impl Unpin for VolatilityRatio
impl UnsafeUnpin for VolatilityRatio
impl UnwindSafe for VolatilityRatio
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