Example: HoltWintersExponentialSmoothing

A series of 12 seasonal data values are analysed using the Multiplicative and the Additive Holt-Winters method. The season size is nseason = 4. The objective is to predict one season ahead, nforecasts = 4 using each method. The forecasts and prediction interval lower and upper bounds are returned. The mean sum of squares of the one-step ahead forecast errors is shown to be smallest using the Multiplicative model.


import com.imsl.stat.*;
import com.imsl.math.PrintMatrix;

public class HoltWintersExponentialSmoothingEx1 {

    public static void main(String args[]) {
        double[] y = {23, 25, 36, 31, 26, 28, 48, 36, 31, 42, 53, 43};
        double confidence = 95.0;
        int nobs = y.length, nseason = 4, nforecasts = nseason;

        // Compute the time series and forecasts
        // using the Multiplicative model.
        HoltWintersExponentialSmoothing hw
                = new HoltWintersExponentialSmoothing(nseason, y);
        hw.setConfidence(confidence);
        hw.setNumberForecasts(nforecasts);
        double[][] ser = hw.compute();
        double[] ysm = hw.getSmoothedSeries();
        double[][] forecasts = hw.getForecasts();

        new PrintMatrix("Input time series").print(y);
        new PrintMatrix("Smoothed Multiplicative series").print(ysm);
        new PrintMatrix("Parameters and internal sequence").print(ser);
        new PrintMatrix("   Multiplicative forecasts\nwith "
                + confidence + "% prediction interval").print(forecasts);
        System.out.println("MSS - Multiplicative "
                + (hw.getSumOfSquares() / (double) (nobs - nseason)));

        // Compute the time series and forecasts
        // using the Additive model.
        hw = new HoltWintersExponentialSmoothing(nseason, y);
        hw.setConfidence(confidence);
        hw.setNumberForecasts(nforecasts);
        hw.setAdditive();
        ser = hw.compute();
        ysm = hw.getSmoothedSeries();
        forecasts = hw.getForecasts();

        new PrintMatrix("\n\nSmoothed Additive series").print(ysm);
        new PrintMatrix("Parameters and internal sequence").print(ser);
        new PrintMatrix("      Additive forecasts\nwith "
                + confidence + "% prediction interval").print(forecasts);
        System.out.println("MSS - Additive "
                + (hw.getSumOfSquares() / (double) (nobs - nseason)));
    }
}

Output

Input time series
    0   
 0  23  
 1  25  
 2  36  
 3  31  
 4  26  
 5  28  
 6  48  
 7  36  
 8  31  
 9  42  
10  53  
11  43  

Smoothed Multiplicative series
      0     
 0  23      
 1  25      
 2  36      
 3  31      
 4  24.15   
 5  27.652  
 6  41.767  
 7  38.034  
 8  30.435  
 9  33.715  
10  54.504  
11  45.243  

Parameters and internal sequence
      0       1      2    
 0   0.038  1      0.437  
 1   0      0      0.8    
 2   0      0      0.87   
 3   0      0      1.252  
 4  28.75   1.438  1.078  
 5  30.275  1.525  0.826  
 6  31.815  1.54   0.874  
 7  33.544  1.729  1.33   
 8  35.202  1.657  1.054  
 9  36.885  1.683  0.832  
10  38.928  2.043  0.964  
11  40.927  2      1.315  
12  42.846  1.919  1.032  

   Multiplicative forecasts
with 95.0% prediction interval
     0       1       2     
0  37.252  27.539  46.964  
1  44.99   35.24   54.739  
2  63.908  53.989  73.826  
3  52.136  42.166  62.105  

MSS - Multiplicative 15.347754266704447


Smoothed Additive series
      0     
 0  23      
 1  25      
 2  36      
 3  31      
 4  23      
 5  26.323  
 6  38.58   
 7  38.542  
 8  34.048  
 9  35.73   
10  56.627  
11  43.827  

Parameters and internal sequence
      0       1      2     
 0   0.268  0.643   1      
 1   0      0      -5.75   
 2   0      0      -3.75   
 3   0      0       7.25   
 4  28.75   0       2.25   
 5  29.555  0.518  -3.555  
 6  30.523  0.807  -2.523  
 7  33.859  2.432  14.141  
 8  35.609  1.994   0.391  
 9  36.785  1.468  -5.785  
10  39.936  2.55    2.064  
11  41.513  1.924  11.487  
12  43.215  1.781  -0.215  

      Additive forecasts
with 95.0% prediction interval
     0       1       2     
0  39.211  27.801  50.621  
1  48.841  36.371  61.311  
2  60.046  45.745  74.347  
3  50.125  33.244  67.007  

MSS - Additive 21.181134361693125
Link to Java source.