Accord.NET Framework

## MeasuresExponentialWeightedVariance Method (Double, Double, Boolean) |

Calculates the exponentially weighted variance.

Syntax

public static double ExponentialWeightedVariance( this double[] values, double alpha = 0, bool unbiased = false )

- values
- Type: SystemDouble

A vector of observations whose EW variance will be calculated. It is assumed that the vector is ordered with the most recent observations at the end of the vector (and the oldest observations at the start). - alpha (Optional)
- Type: SystemDouble

The weighting to be applied to the calculation. A higher alpha discounts older observations faster. Alpha must be between 0 and 1 (inclusive). - unbiased (Optional)
- Type: SystemBoolean

Use a standard estimation bias correction.

Returns a Double giving the exponentially weighted variance.

Examples

The following example shows how to compute the EW variance.

/* Suppose we have a time series of observations. Our sample has 17 observations. We wish to compute the variance for our series but would like to provide a heavier weighting to the more recent observations. First, create a vector with the oldest data at the start and the most recent data at the end of the vector. */ double[] timeSeries = { 2, 2, 1, 3, 5, 6, 4, 2, 7, 8, 9, 2, 3, 4, 5, 6, 7 }; // The window size determines how many observations to include in the // calculation. If no window is specified, the entire dataset is used. int window = 15; // We set alpha to 20% meaning each previous observation's contribution // carries 20% less weight (relative to its immediate successor). double alpha = 0.2; // Now we calculate the EW variance. The result should be 3.80. double ewVar = timeSeries.ExponentialWeightedVariance(window, alpha);

See Also