pub struct Ema { /* private fields */ }Expand description
Exponential Moving Average with smoothing factor alpha = 2 / (period + 1).
The first value is the simple mean of the first period inputs (the TA-Lib
convention); each subsequent input contributes
alpha * input + (1 - alpha) * previous, computed with the same fused
multiply-add and precomputed 1 - alpha as wickra_core::Ema, so the
steady-state output is bit-for-bit identical.
The period is a runtime value: EMA needs no window buffer (only a running
warmup sum), so it stays allocation-free without a const generic.
§Example
use wickra_embed_core::{Ema, Indicator};
let mut ema = Ema::new(3);
let mut last = None;
for i in 0..10 {
last = ema.update(100.0 + f64::from(i));
}
assert!(last.is_some());Implementations§
Trait Implementations§
Source§impl Indicator for Ema
impl Indicator for Ema
Source§fn update(&mut self, input: f64) -> Option<f64>
fn update(&mut self, input: f64) -> Option<f64>
Feed one new data point in and return the freshly computed value, or
None while 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.Auto Trait Implementations§
impl Freeze for Ema
impl RefUnwindSafe for Ema
impl Send for Ema
impl Sync for Ema
impl Unpin for Ema
impl UnsafeUnpin for Ema
impl UnwindSafe for Ema
Blanket Implementations§
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