public class HoltWintersExponentialSmoothing extends Object implements 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\).
\(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 |
\(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.)
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).
Constructor and Description |
---|
HoltWintersExponentialSmoothing(int nseason,
double[] y)
Constructor for
HoltWintersExponentialSmoothing . |
Modifier and Type | Method and Description |
---|---|
double[][] |
compute()
Computes the values of the smoothing parameters.
|
double[][] |
getForecasts()
Returns the forecasts past the series data.
|
double[] |
getSmoothedSeries()
Returns the fitted series values.
|
double |
getSumOfSquares()
Returns the sum of squares of the one step ahead forecast errors.
|
double[][] |
getVarCovarMatrix()
Returns the variance-covariance matrix of the smoothing parameters
estimated by minimizing the mean squared forecast error.
|
void |
setAdditive()
Specifies the use of the Additive time series model.
|
void |
setConfidence(double confid)
Sets the confidence level to use in the calculation of the prediction
intervals.
|
void |
setInitialValues(double[][] sequences)
Sets the initial values for the level, trend, and
seasonal component sequences.
|
void |
setLowerBounds(double[] xlb)
Sets the lower bounds for each of the smoothing parameters, (\(
\alpha\), \(\beta\), \(\gamma
\)).
|
void |
setNonseasonalConstant()
Remove the trend and the seasonal components and fit only the level
component.
|
void |
setNonseasonalTrend()
Remove the seasonal component and fit only the level and trend
components.
|
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\)).
|
void |
setNumberForecasts(int nforecasts)
Sets the number of forecasts desired past the series data.
|
void |
setNumberOfObservations(int nobs)
Sets the number of equally spaced series values.
|
void |
setParameters(double[] params)
Sets the values of the smoothing parameters for the level (\(
\alpha\)), the trend (\(\beta\)), and the
seasonal (\(\gamma\)) component sequences.
|
void |
setSeriesIncrement(int incy)
Sets the constant stride through the series data
y . |
void |
setUpperBounds(double[] xub)
Sets the upper bounds for each of the smoothing parameters, (\(
\alpha\), \(\beta\), \(\gamma
\)).
|
public HoltWintersExponentialSmoothing(int nseason, double[] y)
HoltWintersExponentialSmoothing
.nseason
- an int
scalar 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 case nseason
is
ignored. See the setNonseasonalTrend
and
setNonseasonalConstant
methods for details.y
- a double
array containing the values of the
time series.public double getSumOfSquares()
double
scalar containing the sum of squares of
the one step ahead forecast errors.public double[] getSmoothedSeries()
double
array containing the fitted series values.public double[][] getForecasts()
nforecasts
by 1 double
matrix
containing the forecasts past the series data. The value of
the i-th row is the forecast (i + 1) steps past the
series data. If setConfidence
is used, the
matrix will be of dimension nforecasts
by 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.public double[][] getVarCovarMatrix()
setNonseasonalTrend
method is
used, in which case it is 2 by 2, or unless the
setNonseasonalConstant
method is used, in which case it is
1 by 1. This method cannot be used together with the
setParameters
method. Note that the compute
method must be invoked before invoking this method. Otherwise,
the method throws a NullPointerException
exception.double
matrix containing the
variance-covariance matrix of the smoothing parameters
estimated by minimizing the mean squared forecast error.public void setConfidence(double confid)
confid
- a double
scalar 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.
public void setAdditive()
public void setNumberForecasts(int nforecasts)
nforecasts
- an int
scalar containing the number of
forecasts desired past the series data.
Default: No forecasts are computed past the series data.
public void setSeriesIncrement(int incy)
y
.incy
- an int
scalar containing the constant stride
through the series data y
. y.length
must 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.
public void setNonseasonalTrend()
Default: The method includes all three components.
public void setNonseasonalConstant()
Default: The method includes all three components.
public void setNumberEval(int nsamples)
nsamples
- an int
scalar containing the number of
evaluations.
Default: nsamples
= nobs
.
public void setParameters(double[] params)
params
- a double
array 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 the
setNonseasonalTrend
method is used, in
which case it is of length 2 containing values for
level (\(\alpha\)) and the trend
(\(\beta\)) components. Likewise, if
the setNonseasonalConstant
method is used,
params
is 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.
public void setLowerBounds(double[] xlb)
xlb
- a double
array 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 the
setParameters
method is used. The array should
be length 3 unless the setNonseasonalTrend
method is used, in which case it is of length 2 containing
lower bounds for level (\(\alpha\)) and
the trend (\(\beta\)) components.
Likewise, if the setNonseasonalConstant
method
is used, xlb
is of length 1 and contains the
lower bound for the level parameter
(\(\alpha\)) component only.
Default: Lower bounds are all 0.
public void setUpperBounds(double[] xub)
xub
- a double
array 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 the
setParameters
method is used. The array should
be length 3 unless the setNonseasonalTrend
method is used, in which case it is of length 2 containing
upper bounds for level (\(\alpha\)) and
the trend (\(\beta\)) components.
Likewise, if the setNonseasonalConstant
method
is used, xub
is of length 1 and contains the
upper bound for the level parameter
(\(\alpha\)) component only.
Default: Upper bounds are all 1.
public void setInitialValues(double[][] sequences)
sequences
- an (nobs
+ 1) by 3 double
matrix 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 and
nseason
+ 1 to nobs
are
ignored on input.
sequences[0].length
should be equal to 3
unless the setNonseasonalTrend
method is
used, in which case it is 2 containing initial values
for level (\(\alpha\)) and the trend
(\(\beta\)). Likewise, if the
setNonseasonalConstant
method is used,
sequences[0].length
is 1 and contains the
initial values for the level parameter (\(
\alpha\)) only.
Default: Initial values are computed by the function.
public void setNumberOfObservations(int nobs)
nobs
- an int
scalar containing the number of
equally spaced series values.
Default: nobs
= y.length
.
public final double[][] compute()
nobs
+ 1) by 3 double
matrix
containing the values of the smoothing parameters followed
by the level, trend, and seasonal
component sequences. Note that if the
setNonseasonalTrend
method is used, the matrix
is of dimension (nobs
+ 1) by 2 and if the
setNonseasonalConstant
method is used, it is
(nobs
+ 1) by 1.Copyright © 2020 Rogue Wave Software. All rights reserved.