Package com.imsl.stat

Class HoltWintersExponentialSmoothing

java.lang.Object
com.imsl.stat.HoltWintersExponentialSmoothing
All Implemented Interfaces:
Serializable, Cloneable

public class HoltWintersExponentialSmoothing extends Object implements Serializable, Cloneable
Calculates parameters and forecasts using the Holt-Winters Multiplicative or Additive forecasting method for seasonal data.

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:

$$\begin{array}{ll}L_s=\frac{1}{s}\sum \limits_{i=1}^s y_i,&s>1\\b_s=\frac{1}{s}\sum\limits_{i=1}^s \frac{\left(y_{i+s}-y_i\right)}{s},&s>1\\S_i=y_i/L_s\;or\;y_i-L_s,&i=1, \ldots,s\;\left(\mbox{Multiplicative or Additive}\right)\end{array} $$

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

    Constructors
    Constructor
    Description
    HoltWintersExponentialSmoothing(int nseason, double[] y)
    Constructor for HoltWintersExponentialSmoothing.
  • Method Summary

    Modifier and Type
    Method
    Description
    final double[][]
    Computes the values of the smoothing parameters.
    double[][]
    Returns the forecasts past the series data.
    double[]
    Returns the fitted series values.
    double
    Returns 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.
    void
    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
    Remove the trend and the seasonal components and fit only the level component.
    void
    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
    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
    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 \)).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • HoltWintersExponentialSmoothing

      public HoltWintersExponentialSmoothing(int nseason, double[] y)
      Constructor for HoltWintersExponentialSmoothing.
      Parameters:
      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.
  • Method Details

    • getSumOfSquares

      public double getSumOfSquares()
      Returns the sum of squares of the one step ahead forecast errors.
      Returns:
      a double scalar containing the sum of squares of the one step ahead forecast errors.
    • getSmoothedSeries

      public double[] getSmoothedSeries()
      Returns the fitted series values.
      Returns:
      a double array containing the fitted series values.
    • getForecasts

      public double[][] getForecasts()
      Returns the forecasts past the series data.
      Returns:
      an 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.
    • 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 the 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.
      Returns:
      a double matrix 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 - 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.

    • 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 - an int scalar 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 data y.
      Parameters:
      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.

    • 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 - an int scalar 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 - 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.

    • setLowerBounds

      public void setLowerBounds(double[] xlb)
      Sets the lower bounds for each of the smoothing parameters, (\( \alpha\), \(\beta\), \(\gamma \)).
      Parameters:
      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.

    • setUpperBounds

      public void setUpperBounds(double[] xub)
      Sets the upper bounds for each of the smoothing parameters, (\( \alpha\), \(\beta\), \(\gamma \)).
      Parameters:
      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.

    • setInitialValues

      public void setInitialValues(double[][] sequences)
      Sets the initial values for the level, trend, and seasonal component sequences.
      Parameters:
      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.

    • setNumberOfObservations

      public void setNumberOfObservations(int nobs)
      Sets the number of equally spaced series values.
      Parameters:
      nobs - an int scalar 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 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.