pub struct HistoricalVolatility { /* private fields */ }Expand description
Historical Volatility — the annualised standard deviation of log returns.
This is the realised (backward-looking) volatility used to price options and size risk:
r_t = ln(price_t / price_{t−1})
HV = stddev_sample(r over period) · √trading_periods · 100The log returns over the window are measured with the sample standard
deviation (divisor n − 1, the unbiased estimator), then scaled to an
annual figure by √trading_periods — 252 for daily bars, 52 for
weekly, 12 for monthly — and expressed as a percentage.
§Example
use wickra_core::{Indicator, HistoricalVolatility};
// 20-bar window, 252 trading days per year.
let mut indicator = HistoricalVolatility::new(20, 252).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 HistoricalVolatility
impl HistoricalVolatility
Sourcepub fn new(period: usize, trading_periods: usize) -> Result<Self>
pub fn new(period: usize, trading_periods: usize) -> Result<Self>
Construct a new Historical Volatility indicator.
period is the number of log returns in the rolling window;
trading_periods is the annualisation factor (252 daily, 52
weekly, 12 monthly).
§Errors
Returns Error::PeriodZero if period or trading_periods is 0,
or Error::InvalidPeriod if period == 1 (the sample standard
deviation needs at least two returns).
Trait Implementations§
Source§impl Clone for HistoricalVolatility
impl Clone for HistoricalVolatility
Source§fn clone(&self) -> HistoricalVolatility
fn clone(&self) -> HistoricalVolatility
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 HistoricalVolatility
impl Debug for HistoricalVolatility
Source§impl Indicator for HistoricalVolatility
impl Indicator for HistoricalVolatility
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 HistoricalVolatility
impl RefUnwindSafe for HistoricalVolatility
impl Send for HistoricalVolatility
impl Sync for HistoricalVolatility
impl Unpin for HistoricalVolatility
impl UnsafeUnpin for HistoricalVolatility
impl UnwindSafe for HistoricalVolatility
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