pub struct BipowerVariation { /* private fields */ }Expand description
Realized Bipower Variation — the sum of adjacent absolute log-return
products over the trailing period returns, scaled to estimate integrated
variance.
r_t = ln(price_t / price_{t−1})
BV = (π / 2) · Σ |r_t| · |r_{t−1}| over the windowBipower variation (Barndorff-Nielsen & Shephard 2004) estimates the same
integrated variance as RealizedVolatility’s
Σ r², but by multiplying neighbouring absolute returns rather than
squaring a single one. A price jump inflates exactly one return; because that
return appears in a product with its (ordinary) neighbour rather than squared,
its contribution stays bounded — so BV is robust to jumps while realized
variance is not. The constant π / 2 = μ₁⁻² (with μ₁ = E|Z| = √(2/π) for a
standard normal) debiases the product of two half-normal magnitudes back to a
variance scale.
The output is on the variance scale (the jump-robust counterpart of
realized variance, not volatility); take its square root for a volatility,
and compare RV − BV to isolate the jump contribution. A window of period
returns contributes period − 1 adjacent products; each update is O(1) via
a running sum.
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.
§Example
use wickra_core::{BipowerVariation, Indicator};
let mut indicator = BipowerVariation::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§
Source§impl BipowerVariation
impl BipowerVariation
Sourcepub fn new(period: usize) -> Result<Self>
pub fn new(period: usize) -> Result<Self>
Construct a new bipower-variation indicator.
period is the number of log returns in the rolling window; the estimate
uses the period − 1 adjacent products between them.
§Errors
Returns Error::PeriodZero if period == 0, or
Error::InvalidPeriod if period == 1 (an adjacent product needs at
least two returns).
Trait Implementations§
Source§impl Clone for BipowerVariation
impl Clone for BipowerVariation
Source§fn clone(&self) -> BipowerVariation
fn clone(&self) -> BipowerVariation
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 BipowerVariation
impl Debug for BipowerVariation
Source§impl Indicator for BipowerVariation
impl Indicator for BipowerVariation
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 BipowerVariation
impl RefUnwindSafe for BipowerVariation
impl Send for BipowerVariation
impl Sync for BipowerVariation
impl Unpin for BipowerVariation
impl UnsafeUnpin for BipowerVariation
impl UnwindSafe for BipowerVariation
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> BatchNanExt for T
impl<T> BatchNanExt for T
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