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

# Syntax

C#
```public static void g05pm(
int mode,
int n,
int itype,
int p,
double[] param,
double[] init,
double var,
double[] r,
G05..::..G05State g05state,
double[] e,
int en,
double[] x,
out int ifail
)```
Visual Basic
```Public Shared Sub g05pm ( _
mode As Integer, _
n As Integer, _
itype As Integer, _
p As Integer, _
param As Double(), _
init As Double(), _
var As Double, _
r As Double(), _
g05state As G05..::..G05State, _
e As Double(), _
en As Integer, _
x As Double(), _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void g05pm(
int mode,
int n,
int itype,
int p,
array<double>^ param,
array<double>^ init,
double var,
array<double>^ r,
G05..::..G05State^ g05state,
array<double>^ e,
int en,
array<double>^ x,
[OutAttribute] int% ifail
)```
F#
```static member g05pm :
mode : int *
n : int *
itype : int *
p : int *
param : float[] *
init : float[] *
var : float *
r : float[] *
g05state : G05..::..G05State *
e : float[] *
en : int *
x : float[] *
ifail : int byref -> unit
```

#### Parameters

mode
Type: System..::..Int32
On entry: indicates if g05pm is continuing from a previous call or, if not, how the initial values are computed.
${\mathbf{mode}}=0$
Values for ${m}_{0}$, ${r}_{0}$ and ${s}_{-\mathit{j}}$, for $\mathit{j}=0,1,\dots ,p-1$, are supplied in init.
${\mathbf{mode}}=1$
g05pm continues from a previous call using values that are supplied in r. r is not updated.
${\mathbf{mode}}=2$
g05pm continues from a previous call using values that are supplied in r. r is updated.
Constraint: ${\mathbf{mode}}=0$, $1$ or $2$.
n
Type: System..::..Int32
On entry: the number of terms of the time series being generated.
Constraint: ${\mathbf{n}}\ge 0$.
itype
Type: System..::..Int32
On entry: the smoothing function.
${\mathbf{itype}}=1$
Single exponential.
${\mathbf{itype}}=2$
Brown's double exponential.
${\mathbf{itype}}=3$
Linear Holt.
${\mathbf{itype}}=4$
${\mathbf{itype}}=5$
Multiplicative Holt–Winters.
Constraint: ${\mathbf{itype}}=1$, $2$, $3$, $4$ or $5$.
p
Type: System..::..Int32
On entry: if ${\mathbf{itype}}=4$ or $5$, the seasonal order, $p$, otherwise p is not referenced.
Constraint: if ${\mathbf{itype}}=4$ or $5$, ${\mathbf{p}}>1$.
param
Type: array<System..::..Double>[]()[][]
An array of size [_lparam]
Note: the dimension of the array param must be at least $1$ if ${\mathbf{itype}}=1$ or $2$, $3$ if ${\mathbf{itype}}=3$ and at least $4$ if ${\mathbf{itype}}=4$ or $5$.
On entry: the smoothing parameters.
If ${\mathbf{itype}}=1$ or $2$, ${\mathbf{param}}\left[0\right]=\alpha$ and any remaining elements of param are not referenced.
If ${\mathbf{itype}}=3$, ${\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}}=4$ or $5$, ${\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}}=1$, $0.0\le \alpha \le 1.0$;
• if ${\mathbf{itype}}=2$, $0.0<\alpha \le 1.0$;
• if ${\mathbf{itype}}=3$, $0.0\le \alpha \le 1.0$ and $0.0\le \gamma \le 1.0$ and $\varphi \ge 0.0$;
• if ${\mathbf{itype}}=4$ or $5$, $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$.
init
Type: array<System..::..Double>[]()[][]
An array of size [_linit]
Note: the dimension of the array init must be at least $1$ if ${\mathbf{itype}}=1$, $2$ if ${\mathbf{itype}}=2$ or $3$ and at least $2+{\mathbf{p}}$ if ${\mathbf{itype}}=4$ or $5$.
On entry: if ${\mathbf{mode}}=0$, 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}}=1$, ${\mathbf{init}}\left[0\right]={m}_{0}$ and any remaining elements of init are not referenced.
If ${\mathbf{itype}}=2$ or $3$, ${\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}}=4$ or $5$, ${\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.
var
Type: System..::..Double
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.
r
Type: array<System..::..Double>[]()[][]
An array of size [_lr]
Note: the dimension of the array r must be at least $13$ if ${\mathbf{itype}}=1$, $2$ or $3$ and at least $13+{\mathbf{p}}$ if ${\mathbf{itype}}=4$ or $5$.
On entry: if ${\mathbf{mode}}=1$ or $2$, r must contain the values as returned by a previous call to g05pm, r need not be set otherwise.
On exit: if ${\mathbf{mode}}=1$, r is unchanged. Otherwise, r contains the information on the current state of smoothing.
Constraint: if ${\mathbf{mode}}=1$ or $2$, r must have been initialized by at least one call to g05pm or g13am with ${\mathbf{mode}}\ne 1$, and r must not have been changed since that call.
g05state
Type: NagLibrary..::..G05..::..G05State
An Object of type G05.G05State.
e
Type: array<System..::..Double>[]()[][]
An array of size [en]
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.
en
Type: System..::..Int32
On entry: if ${\mathbf{en}}>0$, then 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$.
x
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: the generated time series, ${x}_{\mathit{t}}$, for $\mathit{t}=1,2,\dots ,n$.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

g05pm 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+εtmt=αxt+1-αmt-1$
• Brown Double Exponential Smoothing
 $xt=mt-1+rt-1α+εtmt=αxt+1-αmt-1rt=αmt-mt-1+1-αrt-1$
• Linear Holt Exponential Smoothing
 $xt=mt-1+ϕrt-1+εtmt=αxt+1-αmt-1+ϕrt-1rt=γmt-mt-1+1-γϕrt-1$
 $xt=mt-1+ϕrt-1+st-1-p+εtmt=αxt-st-p+1-αmt-1+ϕrt-1rt=γmt-mt-1+1-γϕrt-1st=βxt-mt+1-βst-p$
• Multiplicative Holt–Winters Smoothing
 $xt=mt-1+ϕrt-1×st-1-p+εtmt=αxt/st-p+1-αmt-1+ϕrt-1rt=γmt-mt-1+1-γϕrt-1st=βxt/mt+1-βst-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.

# References

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

# Error Indicators and Warnings

Errors or warnings detected by the method:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{mode}}\ne 0$, $1$ or $2$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{itype}}\ne 1$, $2$, $3$, $4$ or $5$.
${\mathbf{ifail}}=3$
 On entry, ${\mathbf{itype}}=4$ or $5$ and ${\mathbf{p}}<2$.
${\mathbf{ifail}}=4$
On entry, at least one of $\alpha$, $\beta$ or $\gamma >0.0$ or $>1.0$.
On entry, ${\mathbf{itype}}=2$ and $\alpha =0.0$.
On entry, $\varphi <0.0$.
${\mathbf{ifail}}=5$
 On entry, ${\mathbf{n}}<0$.
${\mathbf{ifail}}=8$
 On entry, ${\mathbf{mode}}=1$ or $2$ and the array r has not been initialized correctly.
${\mathbf{ifail}}=9$
On entry, the array state has not been initialized correctly.
${\mathbf{ifail}}=12$
${\mathbf{itype}}=5$ and model is unsuitable for multiplicative Holt–Winter.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

Not applicable.

None.

None.

# Example

g05pm is then called multiple times to obtain simulated forecast confidence intervals.

Example program (C#): g05pme.cs

Example program data: g05pme.d

Example program results: g05pme.r