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:     modeNag_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:     nIntegerInput
On entry: the number of terms of the time series being generated.
Constraint: n0.
3:     itypeNag_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:     pIntegerInput
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:     vardoubleInput
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:   enIntegerInput
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:   failNagError *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.
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.
NE_INVALID_STATE
On entry, state vector has been corrupted or not initialized.
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

Not applicable.

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)

Produced by GNUPLOT 4.4 patchlevel 0 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) observed smoothed forecast estimated CI simulated CI bootstrapped CI

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

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