Struct ta::indicators::ExponentialMovingAverage[][src]

pub struct ExponentialMovingAverage { /* fields omitted */ }
Expand description

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:

  • period - number of periods

Parameters

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

Example

use ta::indicators::ExponentialMovingAverage;
use ta::Next;

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

Links

Implementations

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.