pub struct RealizedVolatility { /* private fields */ }Expand description
Realized Volatility — the square root of the sum of squared log returns over
the trailing period bars.
r_t = ln(price_t / price_{t−1})
RV = √( Σ r_t² over the last `period` returns )Unlike HistoricalVolatility — which reports
the annualised sample standard deviation of log returns (mean-centred,
divided by n − 1, scaled by √trading_periods and ×100) — realized
volatility is the raw, un-centred, un-annualised quadratic variation
estimator used in high-frequency econometrics. It makes no Gaussian
assumption and no mean subtraction: it simply accumulates squared returns,
which converges to the integrated variance of the price path as the
sampling frequency rises. Multiply by √trading_periods yourself if an
annual figure is wanted.
Non-finite and non-positive prices are ignored (the log return would be undefined): the tick is dropped, state is left untouched, and the last value is returned.
Each update is O(1): a running sum of squared returns is maintained over
the rolling window.
§Example
use wickra_core::{Indicator, RealizedVolatility};
let mut indicator = RealizedVolatility::new(20).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§
Trait Implementations§
Source§impl Clone for RealizedVolatility
impl Clone for RealizedVolatility
Source§fn clone(&self) -> RealizedVolatility
fn clone(&self) -> RealizedVolatility
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 RealizedVolatility
impl Debug for RealizedVolatility
Source§impl Indicator for RealizedVolatility
impl Indicator for RealizedVolatility
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 RealizedVolatility
impl RefUnwindSafe for RealizedVolatility
impl Send for RealizedVolatility
impl Sync for RealizedVolatility
impl Unpin for RealizedVolatility
impl UnsafeUnpin for RealizedVolatility
impl UnwindSafe for RealizedVolatility
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