Skip to main content

Ema

Struct Ema 

Source
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§

Source§

impl Ema

Source

pub fn new(period: usize) -> Self

Construct an EMA with the given period. A period of 0 yields an alpha of 2.0 and never produces a meaningful value; callers pass a positive period (the bindings validate up front).

Source

pub const fn period(&self) -> usize

Configured period.

Source

pub const fn alpha(&self) -> f64

Smoothing factor alpha.

Source

pub const fn value(&self) -> Option<f64>

Current value if seeded.

Trait Implementations§

Source§

impl Clone for Ema

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Ema

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Indicator for Ema

Source§

type Input = f64

Type of one input data point (f64 for a price, Candle for an OHLC bar).
Source§

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)

Reset all internal state, leaving the indicator equivalent to a freshly constructed instance with the same parameters.
Source§

fn warmup_period(&self) -> usize

Number of inputs required before the first non-None output.
Source§

fn is_ready(&self) -> bool

Whether the indicator has produced at least one value since construction or the last reset.
Source§

fn name(&self) -> &'static str

Stable, human-readable indicator name.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.