pub struct Garch11 { /* private fields */ }Expand description
GARCH(1,1) conditional volatility — the square root of the generalized-autoregressive-conditional-heteroskedasticity variance recursion.
r_t = ln(price_t / price_{t−1})
σ²_t = ω + α · r²_{t−1} + β · σ²_{t−1}
out = √σ²_tGARCH(1,1) (Bollerslev 1986) generalizes the
EwmaVolatility recursion by adding a constant ω,
which pins the process to a finite long-run (unconditional) variance
ω / (1 − α − β). The α term gives weight to the latest squared return
(the “ARCH” shock) and β to the previous variance (the “GARCH”
persistence). When ω = 0 and α + β = 1 the model degenerates to EWMA; a
proper GARCH keeps ω > 0 and α + β < 1 so volatility mean-reverts rather
than drifting.
The recursion is seeded with the unconditional variance (σ²₁ = ω / (1 − α − β)) and emits from the first log return onward. Unlike EWMA — which decays to
zero on a flat series — a flat series here mean-reverts toward ω / (1 − β)
(the α-term vanishes but the ω floor and the β carry remain), so the
output is always strictly positive. Each update is O(1).
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::{Garch11, Indicator};
// Typical equity daily estimate.
let mut indicator = Garch11::new(0.000_002, 0.10, 0.88).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 Garch11
impl Garch11
Sourcepub fn new(omega: f64, alpha: f64, beta: f64) -> Result<Self>
pub fn new(omega: f64, alpha: f64, beta: f64) -> Result<Self>
Construct a new GARCH(1,1) indicator from its three parameters.
omega (ω) is the constant variance floor, alpha (α) the weight on
the latest squared return, and beta (β) the persistence of the
previous variance.
§Errors
Returns Error::InvalidParameter unless every parameter is finite,
omega > 0, alpha >= 0, beta >= 0, and alpha + beta < 1 (the
covariance-stationarity condition that gives a finite long-run variance).
Sourcepub const fn unconditional_variance(&self) -> f64
pub const fn unconditional_variance(&self) -> f64
Long-run (unconditional) variance ω / (1 − α − β).
Trait Implementations§
Source§impl Indicator for Garch11
impl Indicator for Garch11
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 Garch11
impl RefUnwindSafe for Garch11
impl Send for Garch11
impl Sync for Garch11
impl Unpin for Garch11
impl UnsafeUnpin for Garch11
impl UnwindSafe for Garch11
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