pub struct ExponentialMovingAverage { /* private fields */ }
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
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::{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
Implementations§
Trait Implementations§
Source§impl Clone for ExponentialMovingAverage
impl Clone for ExponentialMovingAverage
Source§fn clone(&self) -> ExponentialMovingAverage
fn clone(&self) -> ExponentialMovingAverage
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for ExponentialMovingAverage
impl Debug for ExponentialMovingAverage
Source§impl Default for ExponentialMovingAverage
impl Default for ExponentialMovingAverage
Source§impl Display for ExponentialMovingAverage
impl Display for ExponentialMovingAverage
Source§impl<T: Close> Next<T> for ExponentialMovingAverage
impl<T: Close> Next<T> for ExponentialMovingAverage
Auto Trait Implementations§
impl Freeze for ExponentialMovingAverage
impl RefUnwindSafe for ExponentialMovingAverage
impl Send for ExponentialMovingAverage
impl Sync for ExponentialMovingAverage
impl Unpin for ExponentialMovingAverage
impl UnwindSafe for ExponentialMovingAverage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more