Exponential Smoothing

Exponential smoothing is a general method for removing noise from a data series, or producing a short term forecast of time series data.

Single exponential smoothing is equivalent to computing an exponential moving average. The smoothing parameter is determined automatically, by minimizing the squared difference between the actual and the forecast values. Double exponential smoothing introduces a linear trend, and so takes two arguments.

Exponential smoothing is implemented by the ExponentialSmoothingModel class. A variety of methods is available, including single and double exponential smoothing.

Creating Exponential Smoothing Models

The constructor of the ExponentialSmoothingModel class takes two arguments. The first is a Vector<T> that contains the time series data. The second argument determines the smoothing method that is to be used. It is of type ExponentialSmoothingMethod, and can take on the following values:

ExponentialSmoothingMethod values

Value

Description

Single

Use single exponential smoothing.

Double

Use double exponential smoothing.

For single exponential smoothing models, this is all that is required. The example below creates a single exponential smoothing model for a vector y:

C#
var model1 = new ExponentialSmoothingModel(y, ExponentialSmoothingMethod.Single);

For double exponential smoothing models, the TrendEstimator property, of type ExponentialSmoothingTrendEstimator determines how the initial value for the trend is determined. Its possible values are as follows:

ExponentialSmoothingTrendEstimator values

Value

Description

Initial

The difference between the first two observations is taken as the initial value.

Initial2

The average difference between the first two pairs of observations is taken as the initial value.

Initial3

The average difference between the first three pairs of observations is taken as the initial value.

Total

The average difference between all pairs of observations is taken as the initial value.

The code below creates a double exponential smoothing model that uses the first 2 observations to initialize the trend:

C#
var model2 = new ExponentialSmoothingModel(y, ExponentialSmoothingMethod.Double);
model2.TrendEstimator = ExponentialSmoothingTrendEstimator.Initial2;

Computing the Model

The Compute method finds the parameter values that minimize the squared error of the forecast.

The parameters of the model can be retrieved through the Parameters collection. The first argument is the smoothing parameter. For double smoothing, the second parameter represents the trend. The members of this collection are of type Parameter<T>, and can be used to obtain a wide range of information about the computed values, including the standard error, significance tests and confidence intervals. If you only need the values of the parameters, the ParameterValues property can be used.

C#
model2.Fit();
Console.WriteLine("Trend: {0}", model2.Parameters[1].Value);
Console.WriteLine("Std.Err.: {0}", model2.Parameters[1].StandardError);
Console.WriteLine("t: {0}", model2.Parameters[1].Statistic);
Console.WriteLine(model2.ParameterValues);

Forecasting

Once the model has been computed, the Forecast method can then be used to forecast new values. This method has three overloads.

Without arguments, the method returns the one step ahead forecast based on the computed model. With a single argument, it computes a point forecast the specified number of steps ahead. It returns a Vector<T> that contains the point forecast for the specified number of periods:

C#
var forecast = model2.Forecast(4);

See Also