[−][src]Struct ta::indicators::ExponentialMovingAverage
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
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:
Where:
- length - number of periods
Parameters
- length - 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
Methods
impl ExponentialMovingAverage
[src]
Trait Implementations
impl Reset for ExponentialMovingAverage
[src]
impl Next<f64> for ExponentialMovingAverage
[src]
impl<'a, T: Close> Next<&'a T> for ExponentialMovingAverage
[src]
impl Clone for ExponentialMovingAverage
[src]
fn clone(&self) -> ExponentialMovingAverage
[src]
default fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Default for ExponentialMovingAverage
[src]
impl Debug for ExponentialMovingAverage
[src]
impl Display for ExponentialMovingAverage
[src]
Auto Trait Implementations
impl Send for ExponentialMovingAverage
impl Sync for ExponentialMovingAverage
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,