pub struct MedianChannel { /* private fields */ }Expand description
Median Channel: a robust analogue of Bollinger Bands built from the rolling median and the median absolute deviation (MAD).
middle = median(close, period)
MAD = median( | close_i − middle | )
upper = middle + multiplier · MAD
lower = middle − multiplier · MADWhere BollingerBands centre on the mean and scale
by the standard deviation — both of which a single spike can drag
arbitrarily far — the Median Channel uses two order statistics. The
breakdown point of the median and MAD is 50%: up to half the window can be
contaminated before the centre or width is materially distorted. That makes
the channel well suited to noisy, gap-prone, or fat-tailed series where
Bollinger Bands flare on every outlier. Both quantiles use the type-7
interpolation shared with RollingQuantile.
§Example
use wickra_core::{Indicator, MedianChannel};
let mut indicator = MedianChannel::new(20, 2.0).unwrap();
let mut last = None;
for i in 0..40 {
last = indicator.update(100.0 + f64::from(i % 5));
}
assert!(last.is_some());Implementations§
Source§impl MedianChannel
impl MedianChannel
Sourcepub fn new(period: usize, multiplier: f64) -> Result<Self>
pub fn new(period: usize, multiplier: f64) -> Result<Self>
Construct a new Median Channel.
§Errors
Returns Error::PeriodZero if period == 0, or
Error::NonPositiveMultiplier if multiplier is not strictly
positive and finite.
Sourcepub const fn multiplier(&self) -> f64
pub const fn multiplier(&self) -> f64
Configured multiplier.
Trait Implementations§
Source§impl Clone for MedianChannel
impl Clone for MedianChannel
Source§fn clone(&self) -> MedianChannel
fn clone(&self) -> MedianChannel
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 MedianChannel
impl Debug for MedianChannel
Source§impl Indicator for MedianChannel
impl Indicator for MedianChannel
Source§type Output = MedianChannelOutput
type Output = MedianChannelOutput
Source§fn update(&mut self, value: f64) -> Option<MedianChannelOutput>
fn update(&mut self, value: f64) -> Option<MedianChannelOutput>
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 MedianChannel
impl RefUnwindSafe for MedianChannel
impl Send for MedianChannel
impl Sync for MedianChannel
impl Unpin for MedianChannel
impl UnsafeUnpin for MedianChannel
impl UnwindSafe for MedianChannel
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