# NAG CL Interfaceg05pmc (times_​smooth_​exp)

Settings help

CL Name Style:

## 1Purpose

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

## 2Specification

 #include
 void g05pmc (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)
The function may be called by the names: g05pmc, nag_rand_times_smooth_exp or nag_rand_exp_smooth.

## 3Description

g05pmc returns $\left\{{x}_{t}:t=1,2,\dots ,n\right\}$, a realization of a time series from an exponential smoothing model defined by one of five smoothing functions:
• Single Exponential Smoothing
 $xt = mt-1 + εt mt = α xt + (1-α) mt-1$
• Brown Double Exponential Smoothing
 $xt = mt-1 + rt-1 α + εt mt = α xt + (1-α) mt-1 rt = α (mt-mt-1) + (1-α) rt-1$
• Linear Holt Exponential Smoothing
 $xt = mt-1 + ϕrt-1 + εt mt = α xt + (1-α) (mt-1+ϕrt-1) rt = γ (mt-mt-1) + (1-γ) ϕ rt-1$
 $xt = mt-1 + ϕrt-1 + st-1-p + εt mt = α (xt- s t-p ) + (1-α) ( m t-1 +ϕ r t-1 ) rt = γ (mt- m t-1 ) + (1-γ) ϕ rt-1 st = β (xt-mt) + (1-β) s t-p$
• Multiplicative Holt–Winters Smoothing
 $xt = (mt-1+ϕrt-1) × s t-1-p + εt mt = α xt / s t-p + (1-α) ( m t-1 +ϕ r t-1 ) rt = γ (mt- m t-1 ) + (1-γ) ϕ r t-1 st = β xt / mt + (1-β) s t-p$
where ${m}_{t}$ is the mean, ${r}_{t}$ is the trend and ${s}_{t}$ is the seasonal component at time $t$ with $p$ being the seasonal order. The errors, ${\epsilon }_{t}$ are either drawn from a normal distribution with mean zero and variance ${\sigma }^{2}$ or randomly sampled, with replacement, from a user-supplied vector.

## 4References

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

## 5Arguments

1: $\mathbf{mode}$Nag_InitialValues Input
On entry: indicates if g05pmc is continuing from a previous call or, if not, how the initial values are computed.
${\mathbf{mode}}=\mathrm{Nag_InitialValuesSupplied}$
Values for ${m}_{0}$, ${r}_{0}$ and ${s}_{-\mathit{j}}$, for $\mathit{j}=0,1,\dots ,p-1$, are supplied in init.
${\mathbf{mode}}=\mathrm{Nag_ContinueNoUpdate}$
g05pmc continues from a previous call using values that are supplied in r. r is not updated.
${\mathbf{mode}}=\mathrm{Nag_ContinueAndUpdate}$
g05pmc continues from a previous call using values that are supplied in r. r is updated.
Constraint: ${\mathbf{mode}}=\mathrm{Nag_InitialValuesSupplied}$, $\mathrm{Nag_ContinueNoUpdate}$ or $\mathrm{Nag_ContinueAndUpdate}$.
2: $\mathbf{n}$Integer Input
On entry: the number of terms of the time series being generated.
Constraint: ${\mathbf{n}}\ge 0$.
3: $\mathbf{itype}$Nag_ExpSmoothType Input
On entry: the smoothing function.
${\mathbf{itype}}=\mathrm{Nag_SingleExponential}$
Single exponential.
${\mathbf{itype}}=\mathrm{Nag_BrownsExponential}$
Brown's double exponential.
${\mathbf{itype}}=\mathrm{Nag_LinearHolt}$
Linear Holt.
${\mathbf{itype}}=\mathrm{Nag_AdditiveHoltWinters}$
${\mathbf{itype}}=\mathrm{Nag_MultiplicativeHoltWinters}$
Multiplicative Holt–Winters.
Constraint: ${\mathbf{itype}}=\mathrm{Nag_SingleExponential}$, $\mathrm{Nag_BrownsExponential}$, $\mathrm{Nag_LinearHolt}$, $\mathrm{Nag_AdditiveHoltWinters}$ or $\mathrm{Nag_MultiplicativeHoltWinters}$.
4: $\mathbf{p}$Integer Input
On entry: if ${\mathbf{itype}}=\mathrm{Nag_AdditiveHoltWinters}$ or $\mathrm{Nag_MultiplicativeHoltWinters}$, the seasonal order, $p$, otherwise p is not referenced.
Constraint: if ${\mathbf{itype}}=\mathrm{Nag_AdditiveHoltWinters}$ or $\mathrm{Nag_MultiplicativeHoltWinters}$, ${\mathbf{p}}>1$.
5: $\mathbf{param}\left[\mathit{dim}\right]$const double Input
Note: the dimension, dim, of the array param must be at least
• $1$, when ;
• $3$, when ${\mathbf{itype}}=\mathrm{Nag_LinearHolt}$;
• $4$, when .
On entry: the smoothing parameters.
If ${\mathbf{itype}}=\mathrm{Nag_SingleExponential}$ or $\mathrm{Nag_BrownsExponential}$, ${\mathbf{param}}\left[0\right]=\alpha$ and any remaining elements of param are not referenced.
If ${\mathbf{itype}}=\mathrm{Nag_LinearHolt}$, ${\mathbf{param}}\left[0\right]=\alpha$, ${\mathbf{param}}\left[1\right]=\gamma$, ${\mathbf{param}}\left[2\right]=\varphi$ and any remaining elements of param are not referenced.
If ${\mathbf{itype}}=\mathrm{Nag_AdditiveHoltWinters}$ or $\mathrm{Nag_MultiplicativeHoltWinters}$, ${\mathbf{param}}\left[0\right]=\alpha$, ${\mathbf{param}}\left[1\right]=\gamma$, ${\mathbf{param}}\left[2\right]=\beta$ and ${\mathbf{param}}\left[3\right]=\varphi$ and any remaining elements of param are not referenced.
Constraints:
• if ${\mathbf{itype}}=\mathrm{Nag_SingleExponential}$, $0.0\le \alpha \le 1.0$;
• if ${\mathbf{itype}}=\mathrm{Nag_BrownsExponential}$, $0.0<\alpha \le 1.0$;
• if ${\mathbf{itype}}=\mathrm{Nag_LinearHolt}$, $0.0\le \alpha \le 1.0$ and $0.0\le \gamma \le 1.0$ and $\varphi \ge 0.0$;
• if ${\mathbf{itype}}=\mathrm{Nag_AdditiveHoltWinters}$ or $\mathrm{Nag_MultiplicativeHoltWinters}$, $0.0\le \alpha \le 1.0$ and $0.0\le \gamma \le 1.0$ and $0.0\le \beta \le 1.0$ and $\varphi \ge 0.0$.
6: $\mathbf{init}\left[\mathit{dim}\right]$const double Input
Note: the dimension, dim, of the array init must be at least
• $1$, when ${\mathbf{itype}}=\mathrm{Nag_SingleExponential}$;
• $2$, when ;
• $2+{\mathbf{p}}$, when .
On entry: if ${\mathbf{mode}}=\mathrm{Nag_InitialValuesSupplied}$, the initial values for ${m}_{0}$, ${r}_{0}$ and ${s}_{-\mathit{j}}$, for $\mathit{j}=0,1,\dots ,p-1$, used to initialize the smoothing.
If ${\mathbf{itype}}=\mathrm{Nag_SingleExponential}$, ${\mathbf{init}}\left[0\right]={m}_{0}$ and any remaining elements of init are not referenced.
If ${\mathbf{itype}}=\mathrm{Nag_BrownsExponential}$ or $\mathrm{Nag_LinearHolt}$, ${\mathbf{init}}\left[0\right]={m}_{0}$ and ${\mathbf{init}}\left[1\right]={r}_{0}$ and any remaining elements of init are not referenced.
If ${\mathbf{itype}}=\mathrm{Nag_AdditiveHoltWinters}$ or $\mathrm{Nag_MultiplicativeHoltWinters}$, ${\mathbf{init}}\left[0\right]={m}_{0}$, ${\mathbf{init}}\left[1\right]={r}_{0}$ and ${\mathbf{init}}\left[2\right]$ to ${\mathbf{init}}\left[2+p-1\right]$ hold the values for ${s}_{-\mathit{j}}$, for $\mathit{j}=0,1,\dots ,p-1$. Any remaining elements of init are not referenced.
7: $\mathbf{var}$double Input
On entry: the variance, ${\sigma }^{2}$ of the Normal distribution used to generate the errors ${\epsilon }_{i}$. If ${\mathbf{var}}\le 0.0$ then Normally distributed errors are not used.
8: $\mathbf{r}\left[\mathit{dim}\right]$double Communication Array
Note: the dimension, dim, of the array r must be at least
• $13$, when ;
• $13+{\mathbf{p}}$, when .
On entry: if ${\mathbf{mode}}=\mathrm{Nag_ContinueNoUpdate}$ or $\mathrm{Nag_ContinueAndUpdate}$, r must contain the values as returned by a previous call to g05pmc, r need not be set otherwise.
On exit: if ${\mathbf{mode}}=\mathrm{Nag_ContinueNoUpdate}$, r is unchanged. Otherwise, r contains the information on the current state of smoothing.
Constraint: if ${\mathbf{mode}}=\mathrm{Nag_ContinueNoUpdate}$ or $\mathrm{Nag_ContinueAndUpdate}$, r must have been initialized by at least one call to g05pmc or g13amc with ${\mathbf{mode}}\ne \mathrm{Nag_ContinueNoUpdate}$, and r must not have been changed since that call.
9: $\mathbf{state}\left[\mathit{dim}\right]$Integer Communication Array
Note: the dimension, $\mathit{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: $\mathbf{e}\left[{\mathbf{en}}\right]$const double Input
On entry: if ${\mathbf{en}}>0$ and ${\mathbf{var}}\le 0.0$, a vector from which the errors, ${\epsilon }_{t}$ are randomly drawn, with replacement.
If ${\mathbf{en}}\le 0$, e is not referenced.
11: $\mathbf{en}$Integer Input
On entry: if ${\mathbf{en}}>0$, the length of the vector e.
If both ${\mathbf{var}}\le 0.0$ and ${\mathbf{en}}\le 0$ then ${\epsilon }_{\mathit{t}}=0.0$, for $\mathit{t}=1,2,\dots ,n$.
12: $\mathbf{x}\left[{\mathbf{n}}\right]$double Output
On exit: the generated time series, ${x}_{\mathit{t}}$, for $\mathit{t}=1,2,\dots ,n$.
13: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
On entry, argument $⟨\mathit{\text{value}}⟩$ had an illegal value.
NE_ENUM_INT
On entry, ${\mathbf{p}}=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{itype}}=\mathrm{Nag_AdditiveHoltWinters}$ or $\mathrm{Nag_MultiplicativeHoltWinters}$, ${\mathbf{p}}\ge 2$.
NE_INT
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 0$.
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.
See Section 7.5 in the Introduction to the NAG Library CL Interface 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 8 in the Introduction to the NAG Library CL Interface for further information.
NE_REAL_ARRAY
Model unsuitable for multiplicative Holt–Winter, try a different set of parameters.
On entry, ${\mathbf{param}}\left[⟨\mathit{\text{value}}⟩\right]=⟨\mathit{\text{value}}⟩$.
Constraint: $0\le {\mathbf{param}}\left[i\right]\le 1$.
On entry, ${\mathbf{param}}\left[⟨\mathit{\text{value}}⟩\right]=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{itype}}=\mathrm{Nag_BrownsExponential}$, $0<{\mathbf{param}}\left[i\right]\le 1$.
On entry, ${\mathbf{param}}\left[⟨\mathit{\text{value}}⟩\right]=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{param}}\left[i\right]\ge 0$.

Not applicable.

## 8Parallelism and Performance

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.

None.

## 10Example

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 g13amc.
g05pmc is then called multiple times to obtain simulated forecast confidence intervals.

### 10.1Program Text

Program Text (g05pmce.c)

### 10.2Program Data

Program Data (g05pmce.d)

### 10.3Program Results

Program Results (g05pmce.r)