pub struct GeometricMa { /* private fields */ }Expand description
Geometric Moving Average — the rolling geometric mean of the last period
inputs.
GMA = (Π value_i)^(1/period) = exp( (1/period) · Σ ln(value_i) )The geometric mean is the natural average for multiplicative quantities
such as prices and growth factors: averaging in log-space weights relative
(percentage) moves symmetrically, so a +10% followed by a −10% move
pulls the average below the start, exactly as compounded returns do. It is
always less than or equal to the arithmetic mean of the same window.
Maintained incrementally in O(1): the running sum of natural logs is updated by adding the newcomer’s log and subtracting the departing value’s log as the window slides.
The geometric mean is only defined for strictly positive inputs. A non-finite or non-positive input is ignored (it leaves the window unchanged and returns the current value), mirroring the non-finite handling of the other moving averages.
§Example
use wickra_core::{Indicator, GeometricMa};
let mut indicator = GeometricMa::new(5).unwrap();
let mut last = None;
for i in 0..80 {
last = indicator.update(100.0 + f64::from(i));
}
assert!(last.is_some());Implementations§
Source§impl GeometricMa
impl GeometricMa
Trait Implementations§
Source§impl Clone for GeometricMa
impl Clone for GeometricMa
Source§fn clone(&self) -> GeometricMa
fn clone(&self) -> GeometricMa
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 GeometricMa
impl Debug for GeometricMa
Source§impl Indicator for GeometricMa
impl Indicator for GeometricMa
Source§fn update(&mut self, input: f64) -> Option<f64>
fn update(&mut self, input: 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 GeometricMa
impl RefUnwindSafe for GeometricMa
impl Send for GeometricMa
impl Sync for GeometricMa
impl Unpin for GeometricMa
impl UnsafeUnpin for GeometricMa
impl UnwindSafe for GeometricMa
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