PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_rand_times_arma (g05ph)
Purpose
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).
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:
At Mark 23: |
ip and iq were made optional, inferred from the size of phi and theta respectively |
Description
Let the vector
, denote a time series which is assumed to follow an autoregressive moving average (ARMA) model of the form:
where
, is a residual series of independent random perturbations assumed to be Normally distributed with zero mean and variance
. The parameters
, for
, are called the autoregressive (AR) parameters, and
, for
, the moving average (MA) parameters. The parameters in the model are thus the
values, the
values, the mean
and the residual variance
.
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
. 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
, 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).
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:
– 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:
, or .
- 2:
– int64int32nag_int scalar
-
, the number of observations to be generated.
Constraint:
.
- 3:
– double scalar
-
The mean of the time series.
- 4:
– double array
-
The autoregressive coefficients of the model, .
- 5:
– double array
-
The moving average coefficients of the model, .
- 6:
– double scalar
-
, the variance of the Normal perturbations.
Constraint:
.
- 7:
– double array
-
lr, the dimension of the array, must satisfy the constraint
.
If , the reference vector from the previous call to nag_rand_times_arma (g05ph).
- 8:
– 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:
– int64int32nag_int scalar
-
Default:
the dimension of the array
phi.
, the number of autoregressive coefficients supplied.
Constraint:
.
- 2:
– int64int32nag_int scalar
-
Default:
the dimension of the array
theta.
, the number of moving average coefficients supplied.
Constraint:
.
Output Parameters
- 1:
– double array
-
.
The reference vector.
- 2:
– int64int32nag_int array
-
Contains updated information on the state of the generator.
- 3:
– 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:
– double array
-
Contains the next observations from the time series.
- 5:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
Constraint: , or .
-
-
Constraint: .
-
-
Constraint: .
-
-
On entry, the AR parameters are outside the stationarity region.
-
-
Constraint: .
-
-
Constraint: .
-
-
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, : 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.
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 .
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
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:
where
- is the observed value of the time series at time ,
- is the number of autoregressive parameters, ,
- is the number of moving average parameters, ,
- is the mean of the time series,
and
- is a series of independent random Standard Normal perturbations.
This is the form used in
nag_rand_times_arma (g05ph).
This is related to the form given in
Description by:
- ,
- ,
- ,
- ,
- ,
- .
Example
This example generates values for an autoregressive model given by
where
is a series of independent random Normal perturbations with variance
. 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.
Open in the MATLAB editor:
g05ph_example
function g05ph_example
fprintf('g05ph example results\n\n');
seed = [int64(1762543)];
genid = int64(1);
subid = int64(1);
[state, ifail] = g05kf( ...
genid, subid, seed);
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);
[r, state, var, x, ifail] = ...
g05ph( ...
mode, n, xmean, phi, theta, avar, r, state);
disp('Realizations:');
disp(x);
g05ph example results
Realizations:
-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)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015