pub fn exponential_moving_average(slice: &[f64], old: Option<f64>) -> Result<f64> {
	let length = slice.len();
	if length == 0 {
		return Err(AnalysisError::SliceIsEmpty);
	}
	Ok(match old {
		Some(ema) => (slice[length-1] - ema) * 2. / (1. + length as f64) + ema,
		None => try!(simple_moving_average(slice)),
	})
}
/// Exponential moving average (EMA) is a filter that applies weighting factors
/// which decrease exponentially. The weighting for each older datum decreases
/// exponentially, never reaching zero.
///
/// The number of periods depends on the analytical objectives. Typical number
/// of periods for short, medium and long term trends are 5-20, 20-60 and
/// 100-200 respectively.
///
/// Function calculates the weighting factor from the slice length and
/// calculates the exponential moving average using that factor. If EMA is
/// calculated for the first time previous argument needs to be 0. When previous
/// is 0 function returns simple moving average of the datum points.
///
/// # Arguments
///
/// * `slice` - array of values
/// * `old` - previous EMA if any
///
/// # Example
///
/// ```
/// use stat::analysis::trend;
///
/// let array = [3.5, 3.4, 3.3, 3.6, 3.7];
/// let value = trend::exponential_moving_average(&array, Some(3.4));
/// assert_eq!(value.ok(), Some(3.5));
/// ```
Exponential moving average (EMA) is a filter that applies weighting factors
which decrease exponentially. The weighting for each older datum decreases
exponentially, never reaching zero.

The number of periods depends on the analytical objectives. Typical number
of periods for short, medium and long term trends are 5-20, 20-60 and
100-200 respectively.

Function calculates the weighting factor from the slice length and
calculates the exponential moving average using that factor. If EMA is
calculated for the first time previous argument needs to be 0. When previous
is 0 function returns simple moving average of the datum points.
Exponential moving average ( EMA ) is a filter that applies weighting factors which decrease exponentially . The weighting for each older datum decreases exponentially never reaching zero . The number of periods depends on the analytical objectives . Typical number of periods for short medium and long term trends are 5 - 20 20 - 60 and 100 - 200 respectively . Function calculates the weighting factor from the slice length and calculates the exponential moving average using that factor . If EMA is calculated for the first time previous argument needs to be 0 . When previous is 0 function returns simple moving average of the datum points .
pub fn exponential_moving_average(slice: &[f64], old: Option<f64>) -> Result<f64> {
	let length = slice.len();
	if length == 0 {
		return Err(AnalysisError::SliceIsEmpty);
	}
	Ok(match old {
		Some(ema) => (slice[length-1] - ema) * 2. / (1. + length as f64) + ema,
		None => try!(simple_moving_average(slice)),
	})
}
pub fn exponential_moving_average ( slice : & [ f64 ] , old : Option < f64 > ) -> Result < f64 > { let length = slice . len ( ) ; if length == 0 { return Err ( AnalysisError :: SliceIsEmpty ) ; } Ok ( match old { Some ( ema ) => ( slice [ length - 1 ] - ema ) * 2. / ( 1. + length as f64 ) + ema , None => try ! ( simple_moving_average ( slice ) ) , } ) }
Exponential moving average (EMA) is a filter that applies weighting factors
which decrease exponentially.
Exponential moving average ( EMA ) is a filter that applies weighting factors which decrease exponentially .
slice
&[f64]
old
Option<f64>
example
```
use stat::analysis::trend.


` ` ` use stat :: analysis :: trend .