PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_rand_times_mv_varma (g05pj)
Purpose
nag_rand_times_mv_varma (g05pj) generates a realization of a multivariate time series from a vector autoregressive moving average (VARMA) model. The realization may be continued or a new realization generated at subsequent calls to nag_rand_times_mv_varma (g05pj).
Syntax
[
r,
state,
x,
ifail] = g05pj(
mode,
n,
xmean,
ip,
phi,
iq,
theta,
var,
r,
state, 'k',
k, 'lr',
lr)
[
r,
state,
x,
ifail] = nag_rand_times_mv_varma(
mode,
n,
xmean,
ip,
phi,
iq,
theta,
var,
r,
state, 'k',
k, 'lr',
lr)
Description
Let the vector
, denote a
-dimensional time series which is assumed to follow a vector autoregressive moving average (VARMA) model of the form:
where
, is a vector of
residual series assumed to be Normally distributed with zero mean and covariance matrix
. The components of
are assumed to be uncorrelated at non-simultaneous lags. The
's and
's are
by
matrices of parameters.
, for
, are called the autoregressive (AR) parameter matrices, and
, for
, the moving average (MA) parameter matrices. The parameters in the model are thus the
by
-matrices, the
by
-matrices, the mean vector
and the residual error covariance matrix
. Let
where
denotes the
by
identity matrix.
The model
(1) must be both stationary and invertible. The model is said to be stationary if the eigenvalues of
lie inside the unit circle and invertible if the eigenvalues of
lie inside the unit circle.
For
the VARMA model
(1) is recast into state space form and a realization of the state vector at time zero computed. For all other cases the function computes a realization of the pre-observed vectors
,
, from
(1), see
Shea (1988). This realization is then used to generate a sequence of successive time series observations. Note that special action is taken for pure MA models, that is for
.
At your request a new realization of the time series may be generated more efficiently using the information in a reference vector created during a previous call to
nag_rand_times_mv_varma (g05pj). See the description of the argument
mode in
Arguments for details.
The function returns a realization of
. On a successful exit, the recent history is updated and saved in the array
r so that
nag_rand_times_mv_varma (g05pj) may be called again to generate a realization of
, etc. See the description of the argument
mode in
Arguments for details.
Further computational details are given in
Shea (1988). Note, however, that
nag_rand_times_mv_varma (g05pj) uses a spectral decomposition rather than a Cholesky factorization to generate the multivariate Normals. Although this method involves more multiplications than the Cholesky factorization method and is thus slightly slower it is more stable when faced with ill-conditioned covariance matrices. A method of assigning the AR and MA coefficient matrices so that the stationarity and invertibility conditions are satisfied is described in
Barone (1987).
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_mv_varma (g05pj).
References
Barone P (1987) A method for generating independent realisations of a multivariate normal stationary and invertible ARMA process J. Time Ser. Anal. 8 125–130
Shea B L (1988) A note on the generation of independent realisations of a vector autoregressive moving average process J. Time Ser. Anal. 9 403–410
Parameters
Compulsory Input Parameters
- 1:
– int64int32nag_int scalar
-
A code for selecting the operation to be performed by the function.
- Set up reference vector and compute a realization of the recent history.
- Generate terms in the time series using reference vector set up in a prior call to nag_rand_times_mv_varma (g05pj).
- Combine the operations of and .
- A new realization of the recent history is computed using information stored in the reference vector, and the following sequence of time series values are generated.
If
or
, then you must ensure that the reference vector
r and the values of
k,
ip,
iq,
xmean,
phi,
theta,
var and
ldvar have not been changed between calls to
nag_rand_times_mv_varma (g05pj).
Constraint:
, , or .
- 2:
– int64int32nag_int scalar
-
, the number of observations to be generated.
Constraint:
.
- 3:
– double array
-
, the vector of means of the multivariate time series.
- 4:
– int64int32nag_int scalar
-
, the number of autoregressive parameter matrices.
Constraint:
.
- 5:
– double array
-
Must contain the elements of the
autoregressive parameter matrices of the model,
. If
phi is considered as a three-dimensional array, dimensioned as
, then the
th element of
would be stored in
; that is,
must be set equal to the
th element of
, for
,
and
.
Constraint:
the elements of
phi must satisfy the stationarity condition.
- 6:
– int64int32nag_int scalar
-
, the number of moving average parameter matrices.
Constraint:
.
- 7:
– double array
-
Must contain the elements of the
moving average parameter matrices of the model,
. If
theta is considered as a three-dimensional array, dimensioned as
theta(
k,
k,
iq), then the
th element of
would be stored in
; that is,
must be set equal to the
th element of
, for
,
and
.
Constraint:
the elements of
theta must be within the invertibility region.
- 8:
– double array
-
ldvar, the first dimension of the array, must satisfy the constraint
.
must contain the ()th element of , for and . Only the lower triangle is required.
Constraint:
the elements of
var must be such that
is positive semidefinite.
- 9:
– double array
-
If
or
, the array
r as output from the previous call to
nag_rand_times_mv_varma (g05pj) must be input without any change.
If
or
, the contents of
r need not be set.
- 10:
– 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
xmean and the first dimension of the array
var and the second dimension of the array
var. (An error is raised if these dimensions are not equal.)
, the dimension of the multivariate time series.
Constraint:
.
- 2:
– int64int32nag_int scalar
-
Default:
the dimension of the array
r.
The dimension of the array
r.
Constraints:
- if , ;
- if , .
Where and if , , or if , .
See
Further Comments for some examples of the required size of the array
r.
Output Parameters
- 1:
– double array
-
Information required for any subsequent calls to the function with
or
. See
Further Comments.
- 2:
– int64int32nag_int array
-
Contains updated information on the state of the generator.
- 3:
– double array
-
will contain a realization of the th component of , for and .
- 4:
– 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:
Cases prefixed with W are classified as warnings and
do not generate an error of type NAG:error_n. See nag_issue_warnings.
-
-
Constraint: , , or .
-
-
Constraint: .
-
-
Constraint: .
-
-
Constraint: .
-
-
On entry, the AR parameters are outside the stationarity region.
-
-
Constraint: .
-
-
On entry, the moving average parameter matrices are such that the model is non-invertible.
-
-
On entry, the covariance matrix
var is not positive semidefinite to
machine precision.
-
-
Constraint: .
-
-
k is not the same as when
r was set up in a previous call.
-
-
On entry,
lr is not large enough,
: minimum length required .
-
-
On entry,
state vector has been corrupted or not initialized.
-
-
Constraint: .
-
-
An excessive number of iterations were required by the NAG function used to evaluate the eigenvalues of the matrices used to test for stationarity or invertibility.
-
-
The reference vector cannot be computed because the AR parameters are too close to the boundary of the stationarity region.
-
-
An excessive number of iterations were required by the NAG function used to evaluate the eigenvalues of the covariance matrix.
- W
-
An excessive number of iterations were required by the NAG function used to evaluate the eigenvalues stored in the reference vector.
-
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
The accuracy is limited by the matrix computations performed, and this is dependent on the condition of the argument and covariance matrices.
Further Comments
Note that, in reference to , nag_rand_times_mv_varma (g05pj) will permit moving average parameters on the boundary of the invertibility region.
The elements of
r contain amongst other information details of the spectral decompositions which are used to generate future multivariate Normals. Note that these eigenvectors may not be unique on different machines. For example the eigenvectors corresponding to multiple eigenvalues may be permuted. Although an effort is made to ensure that the eigenvectors have the same sign on all machines, differences in the signs may theoretically still occur.
The following table gives some examples of the required size of the array
r, specified by the argument
lr, for
or
, and for various values of
and
.
|
|
|
|
|
|
|
|
0 |
1 |
2 |
3 |
|
|
|
13 |
20 |
31 |
46 |
|
0 |
36 |
56 |
92 |
144 |
|
|
85 |
124 |
199 |
310 |
|
|
|
19 |
30 |
45 |
64 |
|
1 |
52 |
88 |
140 |
208 |
|
|
115 |
190 |
301 |
448 |
p |
|
|
35 |
50 |
69 |
92 |
|
2 |
136 |
188 |
256 |
340 |
|
|
397 |
508 |
655 |
838 |
|
|
|
57 |
76 |
99 |
126 |
|
3 |
268 |
336 |
420 |
520 |
|
|
877 |
1024 |
1207 |
1426 |
Note that
nag_tsa_uni_arma_roots (g13dx) may be used to check whether a VARMA model is stationary and invertible.
The time taken depends on the values of , and especially and .
Example
This program generates two realizations, each of length
, from the bivariate AR(1) model
with
and
The pseudorandom number generator is initialized by a call to
nag_rand_init_repeat (g05kf). Then, in the first call to
nag_rand_times_mv_varma (g05pj),
in order to set up the reference vector before generating the first realization. In the subsequent call
and a new recent history is generated and used to generate the second realization.
Open in the MATLAB editor:
g05pj_example
function g05pj_example
fprintf('g05pj example results\n\n');
seed = [int64(1762543)];
genid = int64(1);
subid = int64(1);
[state, ifail] = g05kf( ...
genid, subid, seed);
n = int64(48);
xmean = [5; 9];
ip = int64(1);
iq = int64(0);
phi = [0.8; 0; 0.07; 0.58];
theta = [];
var = [2.97, 0; 0.64, 5.38];
r = zeros(600, 1);
mode = int64(2);
[r, state, x, ifail] = g05pj( ...
mode, n, xmean, ip, phi, iq, ...
theta, var, r, state);
fprintf(' Realisation Number 1\n\n');
for i=1:2
fprintf(' Series number %d\n', i);
fprintf(' ---------------\n');
for j=1:6
fprintf(' %8.3f', x(i, (j-1)*8+1:j*8));
fprintf('\n');
end
fprintf('\n');
end
fprintf('\n');
mode = int64(3);
[r, state, x, ifail] = g05pj( ...
mode, n, xmean, ip, phi, iq, ...
theta, var, r, state);
fprintf(' Realisation Number 2\n\n');
for i=1:2
fprintf(' Series number %d\n', i);
fprintf(' ---------------\n');
for j=1:6
fprintf(' %8.3f', x(i, (j-1)*8+1:j*8));
fprintf('\n');
end
fprintf('\n');
end
fprintf('\n');
g05pj example results
Realisation Number 1
Series number 1
---------------
4.833 2.813 3.224 3.825 1.023 1.415 2.184 3.005
5.547 4.832 4.705 5.484 9.407 10.335 8.495 7.478
6.373 6.692 6.698 6.976 6.200 4.458 2.520 3.517
3.054 5.439 5.699 7.136 5.750 8.497 9.563 11.604
9.020 10.063 7.976 5.927 4.992 4.222 3.982 7.107
3.554 7.045 7.025 4.106 5.106 5.954 8.026 7.212
Series number 2
---------------
8.458 9.140 10.866 10.975 9.245 5.054 5.023 12.486
10.534 10.590 11.376 8.793 14.445 13.237 11.030 8.405
7.187 8.291 5.920 9.390 10.055 6.222 7.751 10.604
12.441 10.664 10.960 8.022 10.073 12.870 12.665 14.064
11.867 12.894 10.546 12.754 8.594 9.042 12.029 12.557
9.746 5.487 5.500 8.629 9.723 8.632 6.383 12.484
Realisation Number 2
Series number 1
---------------
5.396 4.811 2.685 5.824 2.449 3.563 5.663 6.209
3.130 4.308 4.333 4.903 1.770 1.278 1.340 -0.527
1.745 3.211 4.478 5.170 5.365 4.852 6.080 6.464
2.765 2.148 6.641 7.224 10.316 7.102 5.604 3.934
4.839 3.698 5.210 5.384 7.652 7.315 7.332 7.561
7.537 7.788 6.868 7.575 6.108 6.188 8.132 10.310
Series number 2
---------------
11.345 10.070 13.654 12.409 11.329 13.054 12.465 9.867
10.263 13.394 10.553 10.331 7.814 8.747 10.025 11.167
10.626 9.366 9.607 9.662 10.492 10.766 11.512 10.813
10.799 8.780 9.221 14.245 11.575 10.620 8.282 5.447
9.935 9.386 11.627 10.066 11.394 7.951 7.907 12.616
15.246 9.962 13.216 11.350 11.227 6.021 6.968 12.428
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015