hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_rand_times_arma (g05ph)


    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example


nag_rand_times_arma (g05ph) 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_times_arma (g05ph).


[r, state, var, x, ifail] = g05ph(mode, n, xmean, phi, theta, avar, r, state, 'ip', ip, 'iq', iq)
[r, state, var, x, ifail] = nag_rand_times_arma(mode, n, xmean, phi, theta, avar, r, state, 'ip', ip, 'iq', iq)
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 23: ip and iq were made optional, inferred from the size of phi and theta respectively


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_times_arma (g05ph) 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_times_arma (g05ph) may be called again to generate a realization of xn+1,xn+2,, etc. See the description of the argument mode in Arguments for details.
One of the initialization functions nag_rand_init_repeat (g05kf) (for a repeatable sequence if computed sequentially) or nag_rand_init_nonrepeat (g05kg) (for a non-repeatable sequence) must be called prior to the first call to nag_rand_times_arma (g05ph).


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


Compulsory Input Parameters

1:     mode int64int32nag_int scalar
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_times_arma (g05ph).
Set up reference vector and generate terms in the time series.
Constraint: mode=0, 1 or 2.
2:     n int64int32nag_int scalar
n, the number of observations to be generated.
Constraint: n0.
3:     xmean – double scalar
The mean of the time series.
4:     phiip – double array
The autoregressive coefficients of the model, ϕ1,ϕ2,,ϕp.
5:     thetaiq – double array
The moving average coefficients of the model, θ1,θ2,,θq.
6:     avar – double scalar
σ2, the variance of the Normal perturbations.
Constraint: avar0.0.
7:     rlr – double array
lr, the dimension of the array, must satisfy the constraint lrip+iq+6+maxip,iq+1.
If mode=1, the reference vector from the previous call to nag_rand_times_arma (g05ph).
8:     state: int64int32nag_int array
Note: the actual argument supplied must be the array state supplied to the initialization routines nag_rand_init_repeat (g05kf) or nag_rand_init_nonrepeat (g05kg).
Contains information on the selected base generator and its current state.

Optional Input Parameters

1:     ip int64int32nag_int scalar
Default: the dimension of the array phi.
p, the number of autoregressive coefficients supplied.
Constraint: ip0.
2:     iq int64int32nag_int scalar
Default: the dimension of the array theta.
q, the number of moving average coefficients supplied.
Constraint: iq0.

Output Parameters

1:     rlr – double array
The reference vector.
2:     state: int64int32nag_int array
Contains updated information on the state of the generator.
3:     var – double scalar
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.
4:     xn – double array
Contains the next n observations from the time series.
5:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
Constraint: mode=0, 1 or 2.
Constraint: n0.
Constraint: ip0.
On entry, the AR parameters are outside the stationarity region.
Constraint: iq0.
Constraint: avar0.0.
ip or iq is not the same as when r was set up in a previous call.
Reference vector r has been corrupted or not initialized correctly.
On entry, lr is not large enough, lr=_: minimum length required .
On entry, state vector has been corrupted or not initialized.
An unexpected error has been triggered by this routine. Please contact NAG.
Your licence key may have expired or may not have been installed correctly.
Dynamic memory allocation failed.


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

Further Comments

The time taken by nag_rand_times_arma (g05ph) 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_repeat (g05kf) or nag_rand_init_nonrepeat (g05kg) a call to nag_rand_times_arma (g05ph) with mode=0 must also be made. In the repeatable case the calls to nag_rand_times_arma (g05ph) should be performed in the same order (at the same point(s) in simulation) every time nag_rand_init_repeat (g05kf) 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 the form used in nag_rand_times_arma (g05ph). This is related to the form given in Description by:


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_repeat (g05kf) and then nag_rand_times_arma (g05ph) is called to initialize a reference vector and generate a sample of ten observations.
function g05ph_example

fprintf('g05ph example results\n\n');

% Initialize the generator to a repeatable sequence
seed  = [int64(1762543)];
genid = int64(1);
subid = int64(1);
[state, ifail] = g05kf( ...
                        genid, subid, seed);

% Set the ARMA model parameters
xmean = 0;
phi   = [0.4; 0.2];
avar  = 1;

mode  = int64(2);
n     = int64(10);
theta = [0];
r     = zeros(2*numel(phi)+numel(theta)+6, 1);

% Set up the reference vector and generate the N realisations
[r, state, var, x, ifail] = ...
  g05ph( ...
         mode, n, xmean, phi, theta, avar, r, state);


g05ph example results


PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015