[][src]Struct cxmr_ta_core::indicators::ExponentialMovingAverage

pub struct ExponentialMovingAverage { /* fields omitted */ }

An exponential moving average (EMA), also known as an exponentially weighted moving average (EWMA).

It is a type of infinite impulse response filter that applies weighting factors which decrease exponentially. The weighting for each older datum decreases exponentially, never reaching zero.

Formula

EMA formula

Where:

  • EMAt - is the value of the EMA at any time period t.
  • EMAt-1 - is the value of the EMA at the previous period t-1.
  • pt - is the input value at a time period t.
  • α - is the coefficient that represents the degree of weighting decrease, a constant smoothing factor between 0 and 1.

α is calculated with the following formula:

alpha formula

Where:

  • length - number of periods

Parameters

  • length - number of periods (integer greater than 0)

Example

use ta::indicators::ExponentialMovingAverage;
use ta::{Calculate, Next};

let mut ema = ExponentialMovingAverage::new(3).unwrap();
assert_eq!(ema.calc(2.0), 2.0);
assert_eq!(ema.calc(5.0), 3.5);
assert_eq!(ema.calc(1.0), 2.25);
assert_eq!(ema.calc(6.25), 4.25);

Links

Methods

impl ExponentialMovingAverage[src]

pub fn new(length: u32) -> Result<Self>[src]

pub fn length(&self) -> u32[src]

Trait Implementations

impl Calculate for ExponentialMovingAverage[src]

impl Clone for ExponentialMovingAverage[src]

impl Debug for ExponentialMovingAverage[src]

impl Default for ExponentialMovingAverage[src]

impl Display for ExponentialMovingAverage[src]

impl<T: Close> Next<T> for ExponentialMovingAverage[src]

impl Reset for ExponentialMovingAverage[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.