pub struct ZScore { /* private fields */ }Expand description
Z-Score — how many standard deviations the latest price sits from its rolling mean.
ZScore = (price − SMA(price, n)) / population_stddev(price, n)A reading of +2 means price is two standard deviations above its recent
average — statistically stretched to the upside; −2 is the mirror. It is
the standard normalisation behind mean-reversion strategies: a large
magnitude flags an extension, a return toward 0 flags reversion. A window
with zero dispersion (a flat series) yields 0.
§Example
use wickra_core::{Indicator, ZScore};
let mut indicator = ZScore::new(20).unwrap();
let mut last = None;
for i in 0..80 {
last = indicator.update(f64::from(i));
}
assert!(last.is_some());Implementations§
Trait Implementations§
Source§impl Indicator for ZScore
impl Indicator for ZScore
Source§fn update(&mut self, value: f64) -> Option<f64>
fn update(&mut self, value: f64) -> Option<f64>
Feed one new data point into the indicator and return the freshly computed
output, or
None if the indicator is still warming up.Source§fn reset(&mut self)
fn reset(&mut self)
Reset all internal state, leaving the indicator equivalent to a freshly
constructed instance with the same parameters.
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
Number of inputs required before the first non-
None output can be produced.Auto Trait Implementations§
impl Freeze for ZScore
impl RefUnwindSafe for ZScore
impl Send for ZScore
impl Sync for ZScore
impl Unpin for ZScore
impl UnsafeUnpin for ZScore
impl UnwindSafe for ZScore
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>>
Run the indicator over a slice of inputs in order, returning one output (or
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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