Struct Ema
pub struct Ema { /* private fields */ }Expand description
Exponential Moving Average over a stream of prices.
The first period samples accumulate like an SMA to produce the seed
value. From sample period + 1 onward the standard EMA recurrence is
used: ema = price * k + prev_ema * (1 - k) where k = 2 / (period + 1).
§Example
use sdk::indicators::Ema;
let mut ema = Ema::new(3).unwrap();
ema.push("100.0".parse().unwrap());
ema.push("200.0".parse().unwrap());
assert!(!ema.is_ready());
ema.push("300.0".parse().unwrap());
assert!(ema.is_ready());
// Seed value equals the SMA of the first 3 samples.
assert_eq!(ema.value().unwrap(), "200.0".parse().unwrap());Implementations§
§impl Ema
impl Ema
pub fn new(period: usize) -> Result<Self, InvalidPeriod>
pub fn new(period: usize) -> Result<Self, InvalidPeriod>
Create a new EMA with the given window size.
Returns Err(InvalidPeriod) if period is zero.
Trait Implementations§
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§
§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)