nag_rngs_arma_time_series (g05pac) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG C Library Manual

NAG Library Function Document

nag_rngs_arma_time_series (g05pac)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_rngs_arma_time_series (g05pac) generates a realization of a univariate time series from an autoregressive moving average (ARMA) model. The realization may be continued or a new realization generated at subsequent calls to nag_rngs_arma_time_series (g05pac).

2  Specification

#include <nag.h>
#include <nagg05.h>
void  nag_rngs_arma_time_series (Integer mode, double xmean, Integer p, const double phi[], Integer q, const double theta[], double avar, double *var, Integer n, double x[], Integer igen, Integer iseed[], double r[], NagError *fail)

3  Description

Let the vector xt, denote a time series which is assumed to follow an autoregressive moving average (ARMA) model of the form:
xt-μ= ϕ1xt-1-μ+ϕ2xt-2-μ++ϕpxt-p-μ+ εt-θ1εt-1-θ2εt-2--θqεt-q (1)
where εt, is a residual series of independent random perturbations assumed to be Normally distributed with zero mean and variance σ2. The parameters ϕi, for i=1,2,,p, are called the autoregressive (AR) parameters, and θj, for j=1,2,,q, the moving average (MA) parameters. The parameters in the model are thus the p ϕ values, the q θ values, the mean μ and the residual variance σ2.
nag_rngs_arma_time_series (g05pac) sets up a reference vector containing initial values corresponding to a stationary position using the method described in Tunnicliffe–Wilson (1979). The function can then return a realization of x1,x2,,xn. On a successful exit, the recent history is updated and saved in the reference vector r so that nag_rngs_arma_time_series (g05pac) may be called again to generate a realization of xn+1,xn+2,, etc. See the description of the argument mode in Section 5 for details.
One of the initialization functions nag_rngs_init_repeatable (g05kbc) (for a repeatable sequence if computed sequentially) or nag_rngs_init_nonrepeatable (g05kcc) (for a non-repeatable sequence) must be called prior to the first call to nag_rngs_arma_time_series (g05pac).

4  References

Knuth D E (1981) The Art of Computer Programming (Volume 2) (2nd Edition) Addison–Wesley
Tunnicliffe–Wilson G (1979) Some efficient computational procedures for high order ARMA models J. Statist. Comput. Simulation 8 301–309

5  Arguments

1:     modeIntegerInput
On entry: a code for selecting the operation to be performed by the function.
Set up reference vector only.
Generate terms in the time series using reference vector set up in a prior call to nag_rngs_arma_time_series (g05pac).
Set up reference vector and generate terms in the time series.
Constraint: mode=0, 1 or 2.
2:     xmeandoubleInput
On entry: the mean of the time series.
3:     pIntegerInput
On entry: p, the number of autoregressive coefficients supplied.
Constraint: p0.
4:     phi[p]const doubleInput
On entry: the autoregressive coefficients of the model, ϕ1,ϕ2,,ϕp.
5:     qIntegerInput
On entry: q, the number of moving average coefficients supplied.
Constraint: q0.
6:     theta[q]const doubleInput
On entry: the moving average coefficients of the model, θ1,θ2,,θq.
7:     avardoubleInput
On entry: σ2, the variance of the Normal perturbations.
Constraint: avar0.0.
8:     vardouble *Output
On exit: the proportion of the variance of a term in the series that is due to the moving-average (error) terms in the model. The smaller this is, the nearer is the model to non-stationarity.
9:     nIntegerInput
On entry: n, the number of observations to be generated.
Constraint: n0.
10:   x[n]doubleOutput
On exit: contains the next n observations from the time series.
11:   igenIntegerInput
On entry: must contain the identification number for the generator to be used to return a pseudorandom number and should remain unchanged following initialization by a prior call to nag_rngs_init_repeatable (g05kbc) or nag_rngs_init_nonrepeatable (g05kcc).
12:   iseed[4]IntegerCommunication Array
On entry: contains values which define the current state of the selected generator.
On exit: contains updated values defining the new state of the selected generator.
13:   r[dim]doubleCommunication Array
Note: the dimension, dim, of the array r must be at least p+q+5+maxp,q+1.
On entry: if mode=1, the reference vector from the previous call to nag_rngs_arma_time_series (g05pac).
On exit: the reference vector.
14:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

On entry, argument value had an illegal value.
On entry, mode=value.
Constraint: 0mode2.
On entry, n=value.
Constraint: n0.
On entry, p=value.
Constraint: p0.
On entry, q=value.
Constraint: q0.
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.
On entry, avar=value.
Constraint: avar0.0.
phi does not define a stationary autoregressive process.

7  Accuracy

The errors in the initialization process should be very much smaller than the error term; see Tunnicliffe–Wilson (1979).

8  Further Comments

The time taken by nag_rngs_arma_time_series (g05pac) is essentially of order p 2.
Note:  nag_rngs_init_repeatable (g05kbc) and nag_rngs_init_nonrepeatable (g05kcc) must be used with care if this function is used as well. The reference vector, as mentioned before, contains a copy of the recent history of the series. This will not be altered properly by calls to any of the above functions. A call to nag_rngs_init_repeatable (g05kbc) or nag_rngs_init_nonrepeatable (g05kcc) should be followed by a call to nag_rngs_arma_time_series (g05pac) with mode=0 to re-initialize the time series reference vector in use. To maintain repeatability with nag_rngs_init_repeatable (g05kbc), the calls to nag_rngs_arma_time_series (g05pac) should be performed in the same order and at the same point or points in the simulation every time nag_rngs_init_repeatable (g05kbc) is used. When the generator state is saved and restored using the arguments igen and iseed, the time series reference vector must be saved and restored as well.
The ARMA model for a time series can also be written as:
xn-E = A1 xn-1-E + + ANA xn-NA-E + B1 an + + BNB an-NB+1
This is related to the form given in Section 3 by:

9  Example

This example calls nag_rngs_arma_time_series (g05pac) to set up the reference vector for an autoregressive model after initialization by nag_rngs_init_repeatable (g05kbc). The model is given by
where εt is a series of independent random Normal perturbations with variance 1.0. nag_rngs_arma_time_series (g05pac) is then called to generate a sample of ten observations, which are printed.

9.1  Program Text

Program Text (g05pace.c)

9.2  Program Data


9.3  Program Results

Program Results (g05pace.r)

nag_rngs_arma_time_series (g05pac) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG C Library Manual

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