pub struct RegimeLabel { /* private fields */ }Expand description
Regime Label — a discrete {−1, 0, +1} classification of the current
volatility regime by where the latest rolling volatility falls within its
own recent distribution.
σₜ = sample stddev of the last `vol_period` log returns
q1,q3 = 25th / 75th percentile of the last `lookback` σ readings
label = −1 if σₜ < q1 (calm regime)
+1 if σₜ > q3 (stressed regime)
0 otherwise (normal regime)This is the canonical rolling-volatility-quantile regime split: rather than
thresholding absolute volatility (which is not comparable across instruments
or epochs), it asks whether today’s volatility is unusually low or high
relative to its own recent history. −1 is a calm regime, +1 a
stressed / high-volatility regime, 0 the normal middle. Because the latest
reading is included in its own reference window, a freshly elevated
volatility prints +1 until the window catches up to the new level — it
flags the transition, not just the absolute level. When the recent
volatilities are all equal (q1 == q3, e.g. a constant drift) there is no
spread to classify against and the label is 0.
Each update is O(vol_period + lookback log lookback). Non-finite and
non-positive prices are ignored.
§Example
use wickra_core::{Indicator, RegimeLabel};
let mut indicator = RegimeLabel::new(5, 20).unwrap();
let mut last = None;
for i in 0..60 {
last = indicator.update(100.0 + (f64::from(i) * 0.5).sin());
}
assert!(last.is_some());Implementations§
Source§impl RegimeLabel
impl RegimeLabel
Sourcepub fn new(vol_period: usize, lookback: usize) -> Result<Self>
pub fn new(vol_period: usize, lookback: usize) -> Result<Self>
Construct a new Regime Label classifier.
vol_period is the window for the rolling volatility; lookback is the
window of volatility readings whose quartiles set the regime bands.
§Errors
Returns Error::InvalidPeriod if vol_period < 2 (the sample standard
deviation needs at least two returns) or if lookback < 2 (the quartile
split needs at least two readings).
Trait Implementations§
Source§impl Clone for RegimeLabel
impl Clone for RegimeLabel
Source§fn clone(&self) -> RegimeLabel
fn clone(&self) -> RegimeLabel
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 RegimeLabel
impl Debug for RegimeLabel
Source§impl Indicator for RegimeLabel
impl Indicator for RegimeLabel
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 RegimeLabel
impl RefUnwindSafe for RegimeLabel
impl Send for RegimeLabel
impl Sync for RegimeLabel
impl Unpin for RegimeLabel
impl UnsafeUnpin for RegimeLabel
impl UnwindSafe for RegimeLabel
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