Class HoltWintersExponentialSmoothing
- All Implemented Interfaces:
Serializable,Cloneable
HoltWintersExponentialSmoothing performs the Holt-Winters
forecasting method to an equally spaced time series,
\(\{{y_t}\}\) where N = nobs and
\(t=1,\ldots,N\) (or \(t=0,1\cdot\mbox{incy},2\cdot
\mbox{incy},\ldots,K\cdot\mbox{incy}\) where \(K\cdot
\mbox{incy}\leq N\) and \(\mbox{incy}\geq 1\)). The
Holt-Winters procedure fits three component sequences known as the
level, the trend, and the seasonal sequence. There are
two formulations, depending on whether the seasonal component of the time
series is thought to be additive or multiplicative. The seasonal component
depends on the length of the season, nseason = s, where
\(s=2,\ldots,N\).
Holt-Winters Additive Model
| \(L_t=\alpha\left(y_t-S_{t-s}\right)+\left(1-\alpha \right)\left(L_{t-1}+b_{t-1}\right)\) | the level sequence |
| \(b_t=\beta\left(L_t-L_{t-1}\right)+\left(1-\beta\right) b_{t-1}\) | the trend sequence |
| \(S_t=\gamma\left(y_t-L_t\right)+\left(1-\gamma\right) S_{t-s}\) | the seasonal sequence |
| \(F_{t+k}=L_t+kb_t+S_{t+k-s}\) | the forecast sequence |
Holt-Winters Multiplicative Model
| \(L_t=\alpha\left(y_t/S_{t-s}\right)+\left(1-\alpha \right)\left(L_{t-1}+b_{t-1}\right)\) | the level sequence |
| \(b_t=\beta\left(L_t-L_{t-1}\right)+\left(1-\beta\right) b_{t-1}\) | the trend sequence |
| \(S_t=\gamma\left(y_t/L_t\right)+\left(1-\gamma\right) S_{t-s}\) | the seasonal sequence |
| \(F_{t+k}=L_t+kb_t+S_{t+k-s}\) | the forecast sequence |
Note that without a seasonal component, both the additive and multiplicative formulations reduce to the same methods. (The seasonal sequence is set to 1 for the multiplicative model, and identically 0 for the additive model.)
Default Starting Values
Initial values are required for these sequences. The software allows the
user code to define these initial values (see setInitialValues
method). If they are not provided, then the first two seasons of data are
used:
The smoothing parameters (\(\alpha\), \(\beta
\), \(\gamma\)) are each in the interval [0,1] and
can be specified by the user (see setParameters method), or
automatically set by minimizing the within sample one-step ahead mean
squared forecast error. Note that this objective function is not necessarily
convex and solutions will depend on starting values. See Chatfield and
Yar(1988) for further discussion. Starting values for (\(\alpha
\), \(\beta\), \(\gamma\)) are
obtained by minimizing the mean squared error over nsamples
bootstrap samples of the time series. Experiments suggest that this approach
helps prevent poor starting values. Note, that solutions may vary for
different settings of the number of random samples, nsamples.
The return value of the compute method is an (N + 1)
by 3 = (nobs + 1) by 3 matrix containing the smoothing
parameter values on the first row, followed by the calculated level, trend,
and seasonal sequences. When N = nobs and s =
nseason, the format of the return value is as follows:
| Series Storage | |
|---|---|
| Row | Value |
| \(\begin{array}{c}0\\1\\2\\ \vdots\\s\\s+1\\\vdots\\N\end{array}\) | \(\begin{array}{ccc}\hat\alpha&\hat\beta& \hat\gamma\\0&0&S_1\\0&0&S_1\\\vdots&\vdots&\vdots\\L_s&b_s&S_s\\ L_{s+1}&b_{s+1}&S_{s+1}\\\vdots&\vdots&\vdots\\L_N&b_N&S_N \end{array}\) |
If one of the nonseasonal options is specifed, the return value will be
(nobs + 1) by 2 or (nobs + 1) by 1 accordingly.
The variance-covariance matrix for the parameters (\(\alpha \), \(\beta\), \(\gamma\)) is
$$\operatorname{cov}=\frac{\sum{e_i^2}}{N - 2s - 3} \left(J^T J\right)^{-1}$$where \(e_i\) is the one-step-ahead forecast error, and J is the Jacobian matrix of the series using the forecast model and calculating forecasts one step ahead of each datum. Prediction intervals are calculated following Chatfield and Yar (1991).
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionHoltWintersExponentialSmoothing(int nseason, double[] y) Constructor forHoltWintersExponentialSmoothing. -
Method Summary
Modifier and TypeMethodDescriptionfinal double[][]compute()Computes the values of the smoothing parameters.double[][]Returns the forecasts past the series data.double[]Returns the fitted series values.doubleReturns the sum of squares of the one step ahead forecast errors.double[][]Returns the variance-covariance matrix of the smoothing parameters estimated by minimizing the mean squared forecast error.voidSpecifies the use of the Additive time series model.voidsetConfidence(double confid) Sets the confidence level to use in the calculation of the prediction intervals.voidsetInitialValues(double[][] sequences) Sets the initial values for the level, trend, and seasonal component sequences.voidsetLowerBounds(double[] xlb) Sets the lower bounds for each of the smoothing parameters, (\( \alpha\), \(\beta\), \(\gamma \)).voidRemove the trend and the seasonal components and fit only the level component.voidRemove the seasonal component and fit only the level and trend components.voidsetNumberEval(int nsamples) Sets the number of evaluations of the residual norm that are sampled to obtain starting values for the smoothing parameters, (\(\alpha \), \(\beta\), \(\gamma\)).voidsetNumberForecasts(int nforecasts) Sets the number of forecasts desired past the series data.voidsetNumberOfObservations(int nobs) Sets the number of equally spaced series values.voidsetParameters(double[] params) Sets the values of the smoothing parameters for the level (\( \alpha\)), the trend (\(\beta\)), and the seasonal (\(\gamma\)) component sequences.voidsetSeriesIncrement(int incy) Sets the constant stride through the series datay.voidsetUpperBounds(double[] xub) Sets the upper bounds for each of the smoothing parameters, (\( \alpha\), \(\beta\), \(\gamma \)).
-
Constructor Details
-
HoltWintersExponentialSmoothing
public HoltWintersExponentialSmoothing(int nseason, double[] y) Constructor forHoltWintersExponentialSmoothing.- Parameters:
nseason- anintscalar containing the number of time points in a season, or the length of the season. The class requires that \(2\leq\mbox{nseason}\leq \mbox{nobs}\) unless one of the non-seasonal methods is used, in which casenseasonis ignored. See thesetNonseasonalTrendandsetNonseasonalConstantmethods for details.y- adoublearray containing the values of the time series.
-
-
Method Details
-
getSumOfSquares
public double getSumOfSquares()Returns the sum of squares of the one step ahead forecast errors.- Returns:
- a
doublescalar containing the sum of squares of the one step ahead forecast errors.
-
getSmoothedSeries
public double[] getSmoothedSeries()Returns the fitted series values.- Returns:
- a
doublearray containing the fitted series values.
-
getForecasts
public double[][] getForecasts()Returns the forecasts past the series data.- Returns:
- an
nforecastsby 1doublematrix containing the forecasts past the series data. The value of the i-th row is the forecast (i + 1) steps past the series data. IfsetConfidenceis used, the matrix will be of dimensionnforecastsby 3 and the value of the i-th row is the forecast (i+1) steps ahead followed by the prediction interval lower and upper bounds.
-
getVarCovarMatrix
public double[][] getVarCovarMatrix()Returns the variance-covariance matrix of the smoothing parameters estimated by minimizing the mean squared forecast error. The matrix is 3 by 3 unless thesetNonseasonalTrendmethod is used, in which case it is 2 by 2, or unless thesetNonseasonalConstantmethod is used, in which case it is 1 by 1. This method cannot be used together with thesetParametersmethod. Note that thecomputemethod must be invoked before invoking this method. Otherwise, the method throws aNullPointerExceptionexception.- Returns:
- a
doublematrix containing the variance-covariance matrix of the smoothing parameters estimated by minimizing the mean squared forecast error.
-
setConfidence
public void setConfidence(double confid) Sets the confidence level to use in the calculation of the prediction intervals.- Parameters:
confid- adoublescalar containing the confidence level to use in the calculation of the prediction intervals. If \(0.0\lt\mbox{confid}\lt 100.0 \), prediction intervals are provided for each forecast.Default: Prediction intervals are not provided.
-
setAdditive
public void setAdditive()Specifies the use of the Additive time series model. The Multiplicative model is the default. -
setNumberForecasts
public void setNumberForecasts(int nforecasts) Sets the number of forecasts desired past the series data.- Parameters:
nforecasts- anintscalar containing the number of forecasts desired past the series data.Default: No forecasts are computed past the series data.
-
setSeriesIncrement
public void setSeriesIncrement(int incy) Sets the constant stride through the series datay.- Parameters:
incy- anintscalar containing the constant stride through the series datay.y.lengthmust be at least \(\left(\mbox{nobs}-1 \right)*\left|\mbox{incy}\right|+1\). When \(incy\lt 0\), the series is incremented in reverse order beginning at index \(\mbox{nobs} \left(-\mbox{incy}\right)-1\).Default:
incy= 1.
-
setNonseasonalTrend
public void setNonseasonalTrend()Remove the seasonal component and fit only the level and trend components. If used, the models involve only the level (\(\alpha\)) and trend (\(\beta\)) parameters. The method is equivalent to double exponential smoothing.Default: The method includes all three components.
-
setNonseasonalConstant
public void setNonseasonalConstant()Remove the trend and the seasonal components and fit only the level component. If used, the models involve only the level (\(\alpha\)) parameter. The method is simple exponential smoothing.Default: The method includes all three components.
-
setNumberEval
public void setNumberEval(int nsamples) Sets the number of evaluations of the residual norm that are sampled to obtain starting values for the smoothing parameters, (\(\alpha \), \(\beta\), \(\gamma\)).- Parameters:
nsamples- anintscalar containing the number of evaluations.Default:
nsamples=nobs.
-
setParameters
public void setParameters(double[] params) Sets the values of the smoothing parameters for the level (\( \alpha\)), the trend (\(\beta\)), and the seasonal (\(\gamma\)) component sequences.- Parameters:
params- adoublearray containing the values of the smoothing parameters for the level (\(\alpha \)), the trend (\(\beta\)), and the seasonal (\(\gamma\)) component sequences. The array should be length 3 unless thesetNonseasonalTrendmethod is used, in which case it is of length 2 containing values for level (\(\alpha\)) and the trend (\(\beta\)) components. Likewise, if thesetNonseasonalConstantmethod is used,paramsis of length 1 and contains the value for the level parameter (\(\alpha\)) component only.Default: Parameter values are selected by minimizing the mean squared one step ahead forecast error.
-
setLowerBounds
public void setLowerBounds(double[] xlb) Sets the lower bounds for each of the smoothing parameters, (\( \alpha\), \(\beta\), \(\gamma \)).- Parameters:
xlb- adoublearray containing the lower bounds for each of the smoothing parameters, (\(\alpha \), \(\beta\), \(\gamma \)). Note that the lower bounds must be in the interval [0,1], inclusive. The array is ignored if thesetParametersmethod is used. The array should be length 3 unless thesetNonseasonalTrendmethod is used, in which case it is of length 2 containing lower bounds for level (\(\alpha\)) and the trend (\(\beta\)) components. Likewise, if thesetNonseasonalConstantmethod is used,xlbis of length 1 and contains the lower bound for the level parameter (\(\alpha\)) component only.Default: Lower bounds are all 0.
-
setUpperBounds
public void setUpperBounds(double[] xub) Sets the upper bounds for each of the smoothing parameters, (\( \alpha\), \(\beta\), \(\gamma \)).- Parameters:
xub- adoublearray containing the upper bounds for each of the smoothing parameters, (\(\alpha \), \(\beta\), \(\gamma \)). Note that the upper bounds must be in the interval [0,1], inclusive. The array is ignored if thesetParametersmethod is used. The array should be length 3 unless thesetNonseasonalTrendmethod is used, in which case it is of length 2 containing upper bounds for level (\(\alpha\)) and the trend (\(\beta\)) components. Likewise, if thesetNonseasonalConstantmethod is used,xubis of length 1 and contains the upper bound for the level parameter (\(\alpha\)) component only.Default: Upper bounds are all 1.
-
setInitialValues
public void setInitialValues(double[][] sequences) Sets the initial values for the level, trend, and seasonal component sequences.- Parameters:
sequences- an (nobs+ 1) by 3doublematrix containing the initial values for the level , trend, and seasonal component sequences. The values must be stored in rows \(1,2,\ldots,nseason\). Rows 0 andnseason+ 1 tonobsare ignored on input.sequences[0].lengthshould be equal to 3 unless thesetNonseasonalTrendmethod is used, in which case it is 2 containing initial values for level (\(\alpha\)) and the trend (\(\beta\)). Likewise, if thesetNonseasonalConstantmethod is used,sequences[0].lengthis 1 and contains the initial values for the level parameter (\( \alpha\)) only.Default: Initial values are computed by the function.
-
setNumberOfObservations
public void setNumberOfObservations(int nobs) Sets the number of equally spaced series values.- Parameters:
nobs- anintscalar containing the number of equally spaced series values.Default:
nobs=y.length.
-
compute
public final double[][] compute()Computes the values of the smoothing parameters.- Returns:
- an (
nobs+ 1) by 3doublematrix containing the values of the smoothing parameters followed by the level, trend, and seasonal component sequences. Note that if thesetNonseasonalTrendmethod is used, the matrix is of dimension (nobs+ 1) by 2 and if thesetNonseasonalConstantmethod is used, it is (nobs+ 1) by 1.
-