pub struct Sma<const N: usize> { /* private fields */ }Expand description
Simple Moving Average over a fixed window of N prices.
Keeps a rolling sum so each update is O(1); the sum is reseeded from the live
window every 16 · N finite updates to bound floating-point drift, exactly
as wickra_core::Sma does. Output is sum / N once the window is full,
None before.
§Example
use wickra_embed_core::{Indicator, Sma};
let mut sma = Sma::<3>::new();
assert_eq!(sma.update(1.0), None);
assert_eq!(sma.update(2.0), None);
assert_eq!(sma.update(3.0), Some(2.0));
assert_eq!(sma.update(4.0), Some(3.0));Implementations§
Trait Implementations§
Source§impl<const N: usize> Indicator for Sma<N>
impl<const N: usize> Indicator for Sma<N>
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<const N: usize> Freeze for Sma<N>
impl<const N: usize> RefUnwindSafe for Sma<N>where
Ring<N>: RefUnwindSafe,
impl<const N: usize> Send for Sma<N>
impl<const N: usize> Sync for Sma<N>
impl<const N: usize> Unpin for Sma<N>
impl<const N: usize> UnsafeUnpin for Sma<N>where
Ring<N>: UnsafeUnpin,
impl<const N: usize> UnwindSafe for Sma<N>where
Ring<N>: UnwindSafe,
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