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)

Purpose

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

Syntax

[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:
Mark 23: ip and iq are now optional, inferred from the size of phi and theta respectively
.

Description

Let the vector xtxt, denote a time series which is assumed to follow an autoregressive moving average (ARMA) model of the form:
xtμ = φ1(xt1μ) + φ2(xt2μ) + + φp(xtpμ) +
εtθ1εt1θ2εt2θqεtq
xt-μ= ϕ1(xt-1-μ)+ϕ2(xt-2-μ)++ϕp(xt-p-μ)+ εt-θ1εt-1-θ2εt-2--θqεt-q
where εtεt, is a residual series of independent random perturbations assumed to be Normally distributed with zero mean and variance σ2σ2. The parameters {φi}{ϕi}, for i = 1,2,,pi=1,2,,p, are called the autoregressive (AR) parameters, and {θj}{θj}, for j = 1,2,,qj=1,2,,q, the moving average (MA) parameters. The parameters in the model are thus the pp φϕ values, the qq θθ values, the mean μμ and the residual variance σ2σ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 realisation of x1,x2,,xnx1,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 realisation of xn + 1,xn + 2,xn+1,xn+2,, etc. See the description of the parameter mode in Section [Parameters] 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).

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

Parameters

Compulsory Input Parameters

1:     mode – int64int32nag_int scalar
A code for selecting the operation to be performed by the function.
mode = 0mode=0
Set up reference vector only.
mode = 1mode=1
Generate terms in the time series using reference vector set up in a prior call to nag_rand_times_arma (g05ph).
mode = 2mode=2
Set up reference vector and generate terms in the time series.
Constraint: mode = 0mode=0, 11 or 22.
2:     n – int64int32nag_int scalar
nn, the number of observations to be generated.
Constraint: n0n0.
3:     xmean – double scalar
The mean of the time series.
4:     phi(ip) – double array
ip, the dimension of the array, must satisfy the constraint ip0ip0.
The autoregressive coefficients of the model, φ1,φ2,,φpϕ1,ϕ2,,ϕp.
5:     theta(iq) – double array
iq, the dimension of the array, must satisfy the constraint iq0iq0.
The moving average coefficients of the model, θ1,θ2,,θqθ1,θ2,,θq.
6:     avar – double scalar
σ2σ2, the variance of the Normal perturbations.
Constraint: avar0.0avar0.0.
7:     r(lr) – double array
lr, the dimension of the array, must satisfy the constraint lrip + iq + 6 + max (ip,iq + 1)lrip+iq+6+max(ip,iq+1).
If mode = 1mode=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.
pp, the number of autoregressive coefficients supplied.
Constraint: ip0ip0.
2:     iq – int64int32nag_int scalar
Default: The dimension of the array theta.
qq, the number of moving average coefficients supplied.
Constraint: iq0iq0.

Input Parameters Omitted from the MATLAB Interface

lr

Output Parameters

1:     r(lr) – double array
lrip + iq + 6 + max (ip,iq + 1)lrip+iq+6+max(ip,iq+1).
The reference vector.
2:     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 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:     x(n) – double array
Contains the next nn observations from the time series.
5:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry, mode0mode0, 11 or 22.
  ifail = 2ifail=2
On entry, n < 0n<0.
  ifail = 4ifail=4
On entry, ip < 0ip<0.
  ifail = 5ifail=5
phi does not define a stationary autoregressive process.
  ifail = 6ifail=6
On entry, iq < 0iq<0.
  ifail = 8ifail=8
On entry, avar < 0.0avar<0.0.
  ifail = 9ifail=9
Either r has been corrupted or the value of ip or iq is not the same as when r was set up in a previous call to nag_rand_times_arma (g05ph) with mode = 0mode=0 or 22.
  ifail = 10ifail=10
On entry, lr < ip + iq + 6 + max (ip,iq + 1)lr<ip+iq+6+max(ip,iq+1).
  ifail = 11ifail=11
On entry,state vector was not initialized or has been corrupted.

Accuracy

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 (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 = 0mode=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 parameter 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:
(xnE) = A1 (xn1E) + + ANA (xnNAE) + B1 an + + BNB anNB + 1
(xn-E) = A1 (xn-1-E) + + ANA (xn-NA-E) + B1 an + + BNB an-NB+1
where
and
This is the form used in nag_rand_times_arma (g05ph). This is related to the form given in Section [Description] by:

Example

function nag_rand_times_arma_example
% Initialize the seed
seed = [int64(1762543)];
% genid and subid identify the base generator
genid = int64(1);
subid =  int64(1);
% 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);

% Initialize the generator to a repeatable sequence
[state, ifail] = nag_rand_init_repeat(genid, subid, seed);
% Set up the reference vector and generate the N realisations
if ifail == 0
  [r, state, var, x, ifail] = ...
        nag_rand_times_arma(mode, n, xmean, phi, theta, avar, r, state);
 x
end
 

x =

   -1.7103
   -0.4042
   -0.1845
   -1.5004
   -1.1946
   -1.8184
   -1.0895
    1.6408
    1.3555
    1.1908


function g05ph_example
% Initialize the seed
seed = [int64(1762543)];
% genid and subid identify the base generator
genid = int64(1);
subid =  int64(1);
% 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);

% Initialize the generator to a repeatable sequence
[state, ifail] = g05kf(genid, subid, seed);
% Set up the reference vector and generate the N realisations
if ifail == 0
  [r, state, var, x, ifail] = ...
        g05ph(mode, n, xmean, phi, theta, avar, r, state);
 x
end
 

x =

   -1.7103
   -0.4042
   -0.1845
   -1.5004
   -1.1946
   -1.8184
   -1.0895
    1.6408
    1.3555
    1.1908



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–2013