pub struct CoefficientOfVariation { /* private fields */ }Expand description
Coefficient of Variation — the rolling population standard deviation divided by the rolling mean.
mean = (1/n) · Σ price
sd = √( (1/n) · Σ price² − mean² )
CV = sd / meanCV is a dimensionless dispersion measure: it scales StdDev by the price
level so two assets at very different price magnitudes can be compared
directly. A higher CV means more relative variability for the same
average price.
When the rolling mean is exactly zero the ratio is undefined; the
indicator returns 0.0 in that degenerate case rather than producing a
NaN/infinity.
§Example
use wickra_core::{CoefficientOfVariation, Indicator};
let mut indicator = CoefficientOfVariation::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 CoefficientOfVariation
impl Clone for CoefficientOfVariation
Source§fn clone(&self) -> CoefficientOfVariation
fn clone(&self) -> CoefficientOfVariation
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CoefficientOfVariation
impl Debug for CoefficientOfVariation
Source§impl Indicator for CoefficientOfVariation
impl Indicator for CoefficientOfVariation
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 CoefficientOfVariation
impl RefUnwindSafe for CoefficientOfVariation
impl Send for CoefficientOfVariation
impl Sync for CoefficientOfVariation
impl Unpin for CoefficientOfVariation
impl UnsafeUnpin for CoefficientOfVariation
impl UnwindSafe for CoefficientOfVariation
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