nag_rand_arma (g05phc) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_rand_arma (g05phc)


    1  Purpose
    7  Accuracy

1  Purpose

nag_rand_arma (g05phc) 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_rand_arma (g05phc).

2  Specification

#include <nag.h>
#include <nagg05.h>
void  nag_rand_arma (Nag_ModeRNG mode, Integer n, double xmean, Integer ip, const double phi[], Integer iq, const double theta[], double avar, double r[], Integer lr, Integer state[], double *var, double x[], 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  
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_rand_arma (g05phc) 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_rand_arma (g05phc) 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_rand_init_repeatable (g05kfc) (for a repeatable sequence if computed sequentially) or nag_rand_init_nonrepeatable (g05kgc) (for a non-repeatable sequence) must be called prior to the first call to nag_rand_arma (g05phc).

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:     mode Nag_ModeRNGInput
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_rand_arma (g05phc).
Set up reference vector and generate terms in the time series.
Constraint: mode=Nag_InitializeReference, Nag_GenerateFromReference or Nag_InitializeAndGenerate.
2:     n IntegerInput
On entry: n, the number of observations to be generated.
Constraint: n0.
3:     xmean doubleInput
On entry: the mean of the time series.
4:     ip IntegerInput
On entry: p, the number of autoregressive coefficients supplied.
Constraint: ip0.
5:     phi[ip] const doubleInput
On entry: the autoregressive coefficients of the model, ϕ1,ϕ2,,ϕp.
6:     iq IntegerInput
On entry: q, the number of moving average coefficients supplied.
Constraint: iq0.
7:     theta[iq] const doubleInput
On entry: the moving average coefficients of the model, θ1,θ2,,θq.
8:     avar doubleInput
On entry: σ2, the variance of the Normal perturbations.
Constraint: avar0.0.
9:     r[lr] doubleCommunication Array
On entry: if mode=Nag_GenerateFromReference, the reference vector from the previous call to nag_rand_arma (g05phc).
On exit: the reference vector.
10:   lr IntegerInput
On entry: the dimension of the array r.
Constraint: lrip+iq+6+maxip,iq+1.
11:   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.
12:   var double *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.
13:   x[n] doubleOutput
On exit: contains the next n observations from the time series.
14:   fail NagError *Input/Output
The NAG error argument (see Section 2.7 in How to Use the NAG Library and its Documentation).

6  Error Indicators and Warnings

Dynamic memory allocation failed.
See Section in How to Use the NAG Library and its Documentation for further information.
On entry, argument value had an illegal value.
On entry, ip=value.
Constraint: ip0.
On entry, iq=value.
Constraint: iq0.
On entry, lr is not large enough, lr=value: minimum length required =value.
On entry, n=value.
Constraint: n0.
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 2.7.6 in How to Use the NAG Library and its Documentation for further information.
On entry, state vector has been corrupted or not initialized.
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
ip or iq is not the same as when r was set up in a previous call.
Previous value of ip=value and ip=value.
Previous value of iq=value and iq=value.
On entry, avar=value.
Constraint: avar0.0.
Reference vector r has been corrupted or not initialized correctly.
On entry, the AR parameters are outside the stationarity region.

7  Accuracy

Any errors in the reference vector's initial values should be very much smaller than the error term; see Tunnicliffe–Wilson (1979).

8  Parallelism and Performance

nag_rand_arma (g05phc) 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

The time taken by nag_rand_arma (g05phc) is essentially of order ip 2.
Note:  The reference vector, r, contains a copy of the recent history of the series. If attempting to re-initialize the series by calling nag_rand_init_repeatable (g05kfc) or nag_rand_init_nonrepeatable (g05kgc) a call to nag_rand_arma (g05phc) with mode=Nag_InitializeReference must also be made. In the repeatable case the calls to nag_rand_arma (g05phc) should be performed in the same order (at the same point(s) in simulation) every time nag_rand_init_repeatable (g05kfc) is used. When the generator state is saved and restored using the argument state, 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:

10  Example

This example generates values for an autoregressive model given by
where εt is a series of independent random Normal perturbations with variance 1.0. The random number generators are initialized by nag_rand_init_repeatable (g05kfc) and then nag_rand_arma (g05phc) is called to initialize a reference vector and generate a sample of ten observations.

10.1  Program Text

Program Text (g05phce.c)

10.2  Program Data


10.3  Program Results

Program Results (g05phce.r)

nag_rand_arma (g05phc) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG Library Manual

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