pub struct RollingQuantile { /* private fields */ }Expand description
The quantile-th quantile of the last period values, with linear
interpolation between order statistics.
h = (period − 1) · quantile
lower = ⌊h⌋
result = sorted[lower] + (h − lower) · (sorted[lower + 1] − sorted[lower])This is the type-7 / NumPy-default quantile definition: quantile = 0.0
returns the window minimum, 0.5 the median, 1.0 the maximum, and
fractional values interpolate linearly between the bracketing order
statistics. Rolling quantiles are the building block for distribution-aware
thresholds — a price sitting above its rolling 90th-percentile, a volatility
regime split at the 25th/75th percentiles, robust band edges that ignore the
tails.
Each update is O(period log period): the window is copied into a scratch
buffer and sorted with total ordering (NaN-safe).
§Example
use wickra_core::{Indicator, RollingQuantile};
// Rolling median of the last 5 values.
let mut indicator = RollingQuantile::new(5, 0.5).unwrap();
let out = indicator.update(1.0);
assert!(out.is_none()); // warming upImplementations§
Source§impl RollingQuantile
impl RollingQuantile
Sourcepub fn new(period: usize, quantile: f64) -> Result<Self>
pub fn new(period: usize, quantile: f64) -> Result<Self>
Construct a new rolling quantile.
quantile selects the order statistic in [0.0, 1.0].
§Errors
Returns Error::PeriodZero if period == 0, or
Error::InvalidParameter if quantile is not a finite value in
[0.0, 1.0].
Trait Implementations§
Source§impl Clone for RollingQuantile
impl Clone for RollingQuantile
Source§fn clone(&self) -> RollingQuantile
fn clone(&self) -> RollingQuantile
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 RollingQuantile
impl Debug for RollingQuantile
Source§impl Indicator for RollingQuantile
impl Indicator for RollingQuantile
Source§fn update(&mut self, value: f64) -> Option<f64>
fn update(&mut self, value: 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 RollingQuantile
impl RefUnwindSafe for RollingQuantile
impl Send for RollingQuantile
impl Sync for RollingQuantile
impl Unpin for RollingQuantile
impl UnsafeUnpin for RollingQuantile
impl UnwindSafe for RollingQuantile
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