pub struct MedianAbsoluteDeviation { /* private fields */ }Expand description
Median Absolute Deviation of the last period values.
med = median(window)
MAD = median( |x_i − med| for x_i in window )MAD is the median analogue of the standard deviation: it is a robust
dispersion measure that ignores extreme outliers (a single huge spike
barely moves the result) and is widely used as a sturdier alternative
to StdDev for risk reporting on heavy-tailed return distributions.
Multiplying MAD by 1.4826 produces a consistent estimator of the
underlying Gaussian standard deviation (the “robust σ”); Wickra returns
the raw MAD so the caller chooses whether to scale.
Each update is O(period log period): the window is kept as a deque
and copied into a small scratch buffer that is sorted twice (once to
pick the median, once to pick the median of absolute deviations). The
rolling structure makes the constant factor low; for the typical
period range (10–100) this is dwarfed by the streaming overhead.
§Example
use wickra_core::{Indicator, MedianAbsoluteDeviation};
let mut indicator = MedianAbsoluteDeviation::new(20).unwrap();
let mut last = None;
for i in 0..40 {
last = indicator.update(100.0 + f64::from(i));
}
assert!(last.is_some());Implementations§
Trait Implementations§
Source§impl Clone for MedianAbsoluteDeviation
impl Clone for MedianAbsoluteDeviation
Source§fn clone(&self) -> MedianAbsoluteDeviation
fn clone(&self) -> MedianAbsoluteDeviation
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 MedianAbsoluteDeviation
impl Debug for MedianAbsoluteDeviation
Source§impl Indicator for MedianAbsoluteDeviation
impl Indicator for MedianAbsoluteDeviation
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 MedianAbsoluteDeviation
impl RefUnwindSafe for MedianAbsoluteDeviation
impl Send for MedianAbsoluteDeviation
impl Sync for MedianAbsoluteDeviation
impl Unpin for MedianAbsoluteDeviation
impl UnsafeUnpin for MedianAbsoluteDeviation
impl UnwindSafe for MedianAbsoluteDeviation
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