Struct Sma
pub struct Sma { /* private fields */ }Expand description
Simple Moving Average over a fixed window of prices.
Uses a ring buffer with a running sum — O(1) per push and per value query, no allocations after construction.
§Example
use sdk::indicators::Sma;
let mut sma = Sma::new(3).unwrap();
sma.push("100.0".parse().unwrap());
sma.push("200.0".parse().unwrap());
assert!(!sma.is_ready());
sma.push("300.0".parse().unwrap());
assert!(sma.is_ready());
assert_eq!(sma.value().unwrap(), "200.0".parse().unwrap());Implementations§
§impl Sma
impl Sma
pub fn new(period: usize) -> Result<Self, InvalidPeriod>
pub fn new(period: usize) -> Result<Self, InvalidPeriod>
Create a new SMA with the given window size.
Returns Err(InvalidPeriod) if period is zero.
pub fn push(&mut self, price: Price)
pub fn push(&mut self, price: Price)
Push a new price sample into the window.
Uses checked arithmetic so that extreme Decimal values (near
Decimal::MAX) do not panic — the sample is silently dropped when
the running sum would overflow.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Sma
impl RefUnwindSafe for Sma
impl Send for Sma
impl Sync for Sma
impl Unpin for Sma
impl UnsafeUnpin for Sma
impl UnwindSafe for Sma
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)