pub struct ParkinsonVolatility { /* private fields */ }Expand description
Parkinson Volatility — a high-low realised-volatility estimator.
Michael Parkinson (1980) noted that the extreme range of a bar carries more variance information than the closing price alone: a wide bar that closes near its open is far more “volatile” than a narrow bar that happens to close at the same level. The estimator is
sigma² = (1 / (4n · ln 2)) · Σ_{i=1..n} (ln(H_i / L_i))²
sigma = √sigma²
out = sigma · √trading_periods · 100The output is annualised to a percent in the same style as
HistoricalVolatility — trading_periods
of 252 for daily bars, 52 for weekly, 12 for monthly. Pass
trading_periods = 1 for the raw per-bar sigma · 100 figure.
Under a driftless Geometric-Brownian-Motion assumption, Parkinson’s
estimator has roughly 1/5 the variance of the close-to-close
estimator — i.e. five close-to-close samples give the same statistical
efficiency as one Parkinson sample.
§Example
use wickra_core::{Candle, Indicator, ParkinsonVolatility};
let mut indicator = ParkinsonVolatility::new(20, 252).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 - 2.0, base + 1.0, 1.0, i64::from(i))
.unwrap();
last = indicator.update(candle);
}
assert!(last.is_some());Implementations§
Source§impl ParkinsonVolatility
impl ParkinsonVolatility
Sourcepub fn new(period: usize, trading_periods: usize) -> Result<Self>
pub fn new(period: usize, trading_periods: usize) -> Result<Self>
Construct a Parkinson Volatility estimator.
period is the rolling window of bars; trading_periods is the
annualisation factor (252 daily, 52 weekly, 12 monthly, or
1 for raw per-bar volatility).
§Errors
Returns Error::PeriodZero if either parameter is 0.
Trait Implementations§
Source§impl Clone for ParkinsonVolatility
impl Clone for ParkinsonVolatility
Source§fn clone(&self) -> ParkinsonVolatility
fn clone(&self) -> ParkinsonVolatility
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 ParkinsonVolatility
impl Debug for ParkinsonVolatility
Source§impl Indicator for ParkinsonVolatility
impl Indicator for ParkinsonVolatility
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 ParkinsonVolatility
impl RefUnwindSafe for ParkinsonVolatility
impl Send for ParkinsonVolatility
impl Sync for ParkinsonVolatility
impl Unpin for ParkinsonVolatility
impl UnsafeUnpin for ParkinsonVolatility
impl UnwindSafe for ParkinsonVolatility
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