nag_rand_exp_smooth (g05pmc) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_rand_exp_smooth (g05pmc)

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_rand_exp_smooth (g05pmc) simulates from an exponential smoothing model, where the model uses either single exponential, double exponential or a Holt–Winters method.

2  Specification

#include <nag.h>
#include <nagg05.h>
void  nag_rand_exp_smooth (Nag_InitialValues mode, Integer n, Nag_ExpSmoothType itype, Integer p, const double param[], const double init[], double var, double r[], Integer state[], const double e[], Integer en, double x[], NagError *fail)

3  Description

nag_rand_exp_smooth (g05pmc) returns xt:t=1,2,,n, a realization of a time series from an exponential smoothing model defined by one of five smoothing functions: where mt is the mean, rt is the trend and st is the seasonal component at time t with p being the seasonal order. The errors, εt are either drawn from a normal distribution with mean zero and variance σ2 or randomly sampled, with replacement, from a user-supplied vector.

4  References

Chatfield C (1980) The Analysis of Time Series Chapman and Hall

5  Arguments

1:     mode Nag_InitialValuesInput
On entry: indicates if nag_rand_exp_smooth (g05pmc) is continuing from a previous call or, if not, how the initial values are computed.
mode=Nag_InitialValuesSupplied
Values for m0, r0 and s-j, for j=0,1,,p-1, are supplied in init.
mode=Nag_ContinueNoUpdate
nag_rand_exp_smooth (g05pmc) continues from a previous call using values that are supplied in r. r is not updated.
mode=Nag_ContinueAndUpdate
nag_rand_exp_smooth (g05pmc) continues from a previous call using values that are supplied in r. r is updated.
Constraint: mode=Nag_InitialValuesSupplied, Nag_ContinueNoUpdate or Nag_ContinueAndUpdate.
2:     n IntegerInput
On entry: the number of terms of the time series being generated.
Constraint: n0.
3:     itype Nag_ExpSmoothTypeInput
On entry: the smoothing function.
itype=Nag_SingleExponential
Single exponential.
itype=Nag_BrownsExponential
Brown's double exponential.
itype=Nag_LinearHolt
Linear Holt.
itype=Nag_AdditiveHoltWinters
Additive Holt–Winters.
itype=Nag_MultiplicativeHoltWinters
Multiplicative Holt–Winters.
Constraint: itype=Nag_SingleExponential, Nag_BrownsExponential, Nag_LinearHolt, Nag_AdditiveHoltWinters or Nag_MultiplicativeHoltWinters.
4:     p IntegerInput
On entry: if itype=Nag_AdditiveHoltWinters or Nag_MultiplicativeHoltWinters, the seasonal order, p, otherwise p is not referenced.
Constraint: if itype=Nag_AdditiveHoltWinters or Nag_MultiplicativeHoltWinters, p>1.
5:     param[dim] const doubleInput
Note: the dimension, dim, of the array param must be at least
  • 1 when itype=Nag_SingleExponential or Nag_BrownsExponential;
  • 3 when itype=Nag_LinearHolt;
  • 4 when itype=Nag_AdditiveHoltWinters or Nag_MultiplicativeHoltWinters.
On entry: the smoothing parameters.
If itype=Nag_SingleExponential or Nag_BrownsExponential, param[0]=α and any remaining elements of param are not referenced.
If itype=Nag_LinearHolt, param[0]=α, param[1]=γ, param[2]=ϕ and any remaining elements of param are not referenced.
If itype=Nag_AdditiveHoltWinters or Nag_MultiplicativeHoltWinters, param[0]=α, param[1]=γ, param[2]=β and param[3]=ϕ and any remaining elements of param are not referenced.
Constraints:
  • if itype=Nag_SingleExponential, 0.0α1.0;
  • if itype=Nag_BrownsExponential, 0.0<α1.0;
  • if itype=Nag_LinearHolt, 0.0α1.0 and 0.0γ1.0 and ϕ0.0;
  • if itype=Nag_AdditiveHoltWinters or Nag_MultiplicativeHoltWinters, 0.0α1.0 and 0.0γ1.0 and 0.0β1.0 and ϕ0.0.
6:     init[dim] const doubleInput
Note: the dimension, dim, of the array init must be at least
  • 1 when itype=Nag_SingleExponential;
  • 2 when itype=Nag_BrownsExponential or Nag_LinearHolt;
  • 2+p when itype=Nag_AdditiveHoltWinters or Nag_MultiplicativeHoltWinters.
On entry: if mode=Nag_InitialValuesSupplied, the initial values for m0, r0 and s-j, for j=0,1,,p-1, used to initialize the smoothing.
If itype=Nag_SingleExponential, init[0]=m0 and any remaining elements of init are not referenced.
If itype=Nag_BrownsExponential or Nag_LinearHolt, init[0]=m0 and init[1]=r0 and any remaining elements of init are not referenced.
If itype=Nag_AdditiveHoltWinters or Nag_MultiplicativeHoltWinters, init[0]=m0, init[1]=r0 and init[2] to init[2+p-1] hold the values for s-j, for j=0,1,,p-1. Any remaining elements of init are not referenced.
7:     var doubleInput
On entry: the variance, σ2 of the Normal distribution used to generate the errors εi. If var0.0 then Normally distributed errors are not used.
8:     r[dim] doubleInput/Output
Note: the dimension, dim, of the array r must be at least
  • 13 when itype=Nag_SingleExponential, Nag_BrownsExponential or Nag_LinearHolt;
  • 13+p when itype=Nag_AdditiveHoltWinters or Nag_MultiplicativeHoltWinters.
On entry: if mode=Nag_ContinueNoUpdate or Nag_ContinueAndUpdate, r must contain the values as returned by a previous call to nag_rand_exp_smooth (g05pmc), r need not be set otherwise.
On exit: if mode=Nag_ContinueNoUpdate, r is unchanged. Otherwise, r contains the information on the current state of smoothing.
Constraint: if mode=Nag_ContinueNoUpdate or Nag_ContinueAndUpdate, r must have been initialized by at least one call to nag_rand_exp_smooth (g05pmc) or nag_tsa_exp_smooth (g13amc) with modeNag_ContinueNoUpdate, and r must not have been changed since that call.
9:     state[dim] IntegerCommunication Array
Note: the dimension, dim, of this array is dictated by the requirements of associated functions that must have been previously called. This array MUST be the same array passed as argument state in the previous call to nag_rand_init_repeatable (g05kfc) or nag_rand_init_nonrepeatable (g05kgc).
On entry: contains information on the selected base generator and its current state.
On exit: contains updated information on the state of the generator.
10:   e[en] const doubleInput
On entry: if en>0 and var0.0, a vector from which the errors, εt are randomly drawn, with replacement.
If en0, e is not referenced.
11:   en IntegerInput
On entry: if en>0, then the length of the vector e.
If both var0.0 and en0 then εt=0.0, for t=1,2,,n.
12:   x[n] doubleOutput
On exit: the generated time series, xt, for t=1,2,,n.
13:   fail NagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.2.1.2 in the Essential Introduction for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_ENUM_INT
On entry, itype=value and p=value.
Constraint: if itype=Nag_AdditiveHoltWinters or Nag_MultiplicativeHoltWinters, p>1.
On entry, p=value.
Constraint: if itype=Nag_AdditiveHoltWinters or Nag_MultiplicativeHoltWinters, p2.
NE_INT
On entry, n=value.
Constraint: n0.
NE_INT_ARRAY
On entry, some of the elements of the array r have been corrupted or have not been initialized.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
An unexpected error has been triggered by this function. Please contact NAG.
See Section 3.6.6 in the Essential Introduction for further information.
NE_INVALID_STATE
On entry, state vector has been corrupted or not initialized.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 3.6.5 in the Essential Introduction for further information.
NE_REAL_ARRAY
Model unsuitable for multiplicative Holt–Winter, try a different set of parameters.
On entry, param[value]=value.
Constraint: 0param[i]1.
On entry, param[value]=value.
Constraint: if itype=Nag_BrownsExponential, 0<param[i]1.
On entry, param[value]=value.
Constraint: param[i]0.

7  Accuracy

Not applicable.

8  Parallelism and Performance

nag_rand_exp_smooth (g05pmc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9  Further Comments

None.

10  Example

This example reads 11 observations from a time series relating to the rate of the earth's rotation about its polar axis and fits an exponential smoothing model using nag_tsa_exp_smooth (g13amc).
nag_rand_exp_smooth (g05pmc) is then called multiple times to obtain simulated forecast confidence intervals.

10.1  Program Text

Program Text (g05pmce.c)

10.2  Program Data

Program Data (g05pmce.d)

10.3  Program Results

Program Results (g05pmce.r)

GnuplotProduced by GNUPLOT 4.6 patchlevel 3 100 150 200 250 300 350 0 5 10 15 20 25 30 35 Data Time Example Program Exponential Smoothing (95% confidence intervals (CIs) are shown) gnuplot_plot_1 observed gnuplot_plot_2 smoothed gnuplot_plot_3 forecast gnuplot_plot_4 estimated CI gnuplot_plot_5 gnuplot_plot_6 simulated CI gnuplot_plot_7 gnuplot_plot_8 bootstrapped CI gnuplot_plot_9

nag_rand_exp_smooth (g05pmc) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2015