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_tsa_multi_varma_forecast (g13dj)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_tsa_multi_varma_forecast (g13dj) computes forecasts of a multivariate time series. It is assumed that a vector ARMA model has already been fitted to the appropriately differenced/transformed time series using nag_tsa_multi_varma_estimate (g13dd). The standard deviations of the forecast errors are also returned. A reference vector is set up so that, should future series values become available, the forecasts and their standard errors may be updated by calling nag_tsa_multi_varma_update (g13dk).

Syntax

[qq, predz, sefz, ref, ifail] = g13dj(z, tr, id, delta, ip, iq, mean_p, par, qq, v, lmax, lref, 'k', k, 'n', n, 'lpar', lpar)
[qq, predz, sefz, ref, ifail] = nag_tsa_multi_varma_forecast(z, tr, id, delta, ip, iq, mean_p, par, qq, v, lmax, lref, 'k', k, 'n', n, 'lpar', lpar)

Description

Let the vector Zt = z1t,z2t,,zktT , for t=1,2,,n, denote a k-dimensional time series for which forecasts of Zn+1,Zn+2,,Zn+lmax are required. Let Wt = w1t,w2t,,wktT  be defined as follows:
wit=δiBzit*,  i=1,2,,k,  
where δiB is the differencing operator applied to the ith series and where zit* is equal to either zit, zit or logezit depending on whether or not a transformation was required to stabilize the variance before fitting the model.
If the order of differencing required for the ith series is di, then the differencing operator for the ith series is defined by δiB=1-δi1B-δi2B2--δidiBdi where B is the backward shift operator; that is, BZt=Zt-1. The differencing parameters δij, for i=1,2,,k and j=1,2,,di, must be supplied by you. If the ith series does not require differencing, then di=0.
Wt is assumed to follow a multivariate ARMA model of the form:
Wt-μ=ϕ1Wt-1-μ+ϕ2Wt-2-μ++ϕpWt-p-μ+εt-θ1εt-1--θqεt-q, (1)
where εt = ε1t,ε2t,,εktT , for t=1,2,,n, is a vector of k residual series assumed to be Normally distributed with zero mean and positive definite covariance matrix Σ. The components of εt are assumed to be uncorrelated at non-simultaneous lags. The ϕi and θj are k by k matrices of parameters. The matrices ϕi, for i=1,2,,p, are the autoregressive (AR) parameter matrices, and the matrices θi, for i=1,2,,q, the moving average (MA) parameter matrices. The parameters in the model are thus the p (k by k) ϕ-matrices, the q (k by k) θ-matrices, the mean vector μ and the residual error covariance matrix Σ. The ARMA model (1) must be both stationary and invertible; see nag_tsa_uni_arma_roots (g13dx) for a method of checking these conditions.
The ARMA model (1) may be rewritten as
ϕBδBZt*-μ=θBεt,  
where ϕB and θB are the autoregressive and moving average polynomials and δB denotes the k by k diagonal matrix whose ith diagonal elements is δiB and Zt* = z 1t * , z2t* zkt* T .
This may be rewritten as
ϕBδBZt*=ϕBμ+θBεt  
or
Zt*=τ+ψ Bεt=τ+εt+ψ1εt- 1+ψ2εt- 2+  
where ψB=δ-1Bϕ-1BθB and τ=δ-1Bμ is a vector of length k.
Forecasts are computed using a multivariate version of the procedure described in Box and Jenkins (1976). If Z^n*l denotes the forecast of Zn+l*, then Z^n*l is taken to be that linear function of Zn*,Zn-1*, which minimizes the elements of Eenlenl where enl=Zn+l*-Z^n*l is the forecast error. Z^n*l is referred to as the linear minimum mean square error forecast of Zn+l*.
The linear predictor which minimizes the mean square error may be expressed as
Z^n*l=τ+ψlεn+ψl+1εn-1+ψl+2εn-2+.  
The forecast error at t for lead l is then
enl=Zn+l*-Z^n*l=εn+l+ψ1εn+l-1+ψ2εn+l-2++ψl-1εn+1.  
Let d=maxdi, for i=1,2,,k. Unless q=0 the function requires estimates of εt, for t=d+1,,n, which are obtainable from nag_tsa_multi_varma_estimate (g13dd). The terms εt are assumed to be zero, for t=n+1,,n+lmax. You may use nag_tsa_multi_varma_update (g13dk) to update these lmax forecasts should further observations, Zn+1,Zn+2,, become available. Note that when lmax or more further observations are available then nag_tsa_multi_varma_forecast (g13dj) must be used to produce new forecasts for Zn+lmax+1,Zn+lmax+2,, should they be required.
When a transformation has been used the forecasts and their standard errors are suitably modified to give results in terms of the original series, Zt; see Granger and Newbold (1976).

References

Box G E P and Jenkins G M (1976) Time Series Analysis: Forecasting and Control (Revised Edition) Holden–Day
Granger C W J and Newbold P (1976) Forecasting transformed series J. Roy. Statist. Soc. Ser. B 38 189–203
Wei W W S (1990) Time Series Analysis: Univariate and Multivariate Methods Addison–Wesley

Parameters

The quantities k, n, kmax, ip, iq, par, npar, qq and v from nag_tsa_multi_varma_estimate (g13dd) are suitable for input to nag_tsa_multi_varma_forecast (g13dj).

Compulsory Input Parameters

1:     zkmaxn – double array
kmax, the first dimension of the array, must satisfy the constraint kmaxk.
zit must contain, zit, the ith component of Zt, for i=1,2,,k and t=1,2,,n.
Constraints:
  • if tri='L', zit>0.0;
  • if tri='S', zit0.0, for i=1,2,,k and t=1,2,,n.
2:     trk – cell array of strings
tri indicates whether the ith time series is to be transformed, for i=1,2,,k.
tri='N'
No transformation is used.
tri='L'
A log transformation is used.
tri='S'
A square root transformation is used.
Constraint: tri='N', 'L' or 'S', for i=1,2,,k.
3:     idk int64int32nag_int array
idi must specify, di, the order of differencing required for the ith series.
Constraint: 0idi<n-maxip,iq, for i=1,2,,k.
4:     deltakmax: – double array
The first dimension of the array delta must be at least k.
The second dimension of the array delta must be at least max1,d, where d=maxidi.
If idi>0, then deltaij must be set equal to δij, for j=1,2,,di and i=1,2,,k.
If d=0, delta is not referenced.
5:     ip int64int32nag_int scalar
p, the number of AR parameter matrices.
Constraint: ip0.
6:     iq int64int32nag_int scalar
q, the number of MA parameter matrices.
Constraint: iq0.
7:     mean_p – string (length ≥ 1)
mean_p='M', if components of μ have been estimated and mean_p='Z', if all elements of μ are to be taken as zero.
Constraint: mean_p='M' or 'Z'.
8:     parlpar – double array
Must contain the parameter estimates read in row by row in the order ϕ1,ϕ2,,ϕp, θ1,θ2,,θq, μ.
Thus,
  • if ip>0, parl-1×k×k+i-1×k+j must be set equal to an estimate of the i,jth element of ϕl, for l=1,2,,p, i=1,2,,k and j=1,2,,k;
  • if iq>0, parp×k×k+l-1×k×k+i-1×k+j must be set equal to an estimate of the i,jth element of θl, for l=1,2,,q, i=1,2,,k and j=1,2,,k;
  • if mean_p='M', parp+q×k×k+i must be set equal to an estimate of the ith component of μ, for i=1,2,,k.
Constraint: the first ip×k×k elements of par must satisfy the stationarity condition and the next iq×k×k elements of par must satisfy the invertibility condition.
9:     qqkmaxk – double array
kmax, the first dimension of the array, must satisfy the constraint kmaxk.
qqij must contain an estimate of the i,jth element of Σ. The lower triangle only is needed.
Constraint: qq must be positive definite.
10:   vkmax: – double array
The first dimension of the array v must be at least k.
The second dimension of the array v must be at least max1,n-d, where d=maxidi.
vit must contain an estimate of the ith component of εt+d, for i=1,2,,k and t=1,2,,n-d.
If q=0, v is not used.
11:   lmax int64int32nag_int scalar
The number, lmax, of forecasts required.
Constraint: lmax1.
12:   lref int64int32nag_int scalar
The dimension of the array ref.
Constraint: lreflmax-1×k×k+2×k×lmax+k.

Optional Input Parameters

1:     k int64int32nag_int scalar
Default: the dimension of the arrays tr, id and the first dimension of the arrays z, delta, qq, v and the second dimension of the array qq. (An error is raised if these dimensions are not equal.)
k, the dimension of the multivariate time series.
Constraint: k1.
2:     n int64int32nag_int scalar
Default: the second dimension of the array z.
n, the number of observations in the series, Zt, prior to differencing.
Constraint: n3.
The total number of observations must exceed the total number of parameters in the model; that is
  • if mean_p='Z', n×k>ip+iq×k×k+k×k+1/2;
  • if mean_p='M', n×k>ip+iq×k×k+k+k×k+1/2,
(see the arguments ip, iq and mean_p).
3:     lpar int64int32nag_int scalar
Default: the dimension of the array par.
The dimension of the array par.
Constraints:
  • if mean_p='Z', lparmax1,ip+iq×k×k;
  • if mean_p='M', lparip+iq×k×k+k.

Output Parameters

1:     qqkmaxk – double array
If ifail1, then the upper triangle is set equal to the lower triangle.
2:     predzkmaxlmax – double array
predzil contains the forecast of zi,n+l, for i=1,2,,k and l=1,2,,lmax.
3:     sefzkmaxlmax – double array
sefzil contains an estimate of the standard error of the forecast of zi,n+l, for i=1,2,,k and l=1,2,,lmax.
4:     reflref – double array
The reference vector which may be used to update forecasts using nag_tsa_multi_varma_update (g13dk). The first lmax-1×k×k elements contain the ψ weight matrices, ψ1,ψ2,,ψlmax-1. The next k×lmax elements contain the forecasts of the transformed series Z^n+1*,Z^n+2*,, Z^n+lmax* and the next k×lmax contain the variances of the forecasts of the transformed variables. The last k elements are used to store the transformations for the 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:
   ifail=1
On entry,k<1,
orn<3,
orkmax<k,
oridi<0 for some i=1,2,,k,
oridin-maxip,iq for some i=1,2,,k,
orip<0,
oriq<0,
ormean_p'M' or 'Z',
orlpar<ip+iq×k×k+k, and mean_p='M',
orlpar<ip+iq×k×k and mean_p='Z',
orn×kip+iq×k×k+k+kk+1/2, and mean_p='M',
orn×kip+iq×k×k+kk+1/2 and mean_p='Z',
orlmax<1,
orlref<lmax-1×k×k+2×k×lmax+k,
orlwork is too small,
orliwork is too small.
   ifail=2
On entry,at least one of the first k elements of tr is not equal to 'N', 'L' or 'S'.
   ifail=3
On entry, one or more of the transformations requested cannot be computed; that is, you may be trying to log or square-root a series, some of whose values are negative.
   ifail=4
On entry, either qq is not positive definite or the autoregressive parameter matrices are extremely close to or outside the stationarity region, or the moving average parameter matrices are extremely close to or outside the invertibility region. To proceed, you must supply different parameter estimates in the arrays par and qq.
   ifail=5
This is an unlikely exit brought about by an excessive number of iterations being needed to evaluate the eigenvalues of the matrices required to check for stationarity and invertibility; see nag_tsa_uni_arma_roots (g13dx). All output arguments are undefined.
   ifail=6
This is an unlikely exit which could occur if qq is nearly non positive definite. In this case the standard deviations of the forecast errors may be non-positive. To proceed, you must supply different parameter estimates in the array qq.
   ifail=7
This is an unlikely exit. For one of the series, overflow will occur if the forecasts are computed. You should check whether the transformations requested in the array tr are sensible. All output arguments are undefined.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

The matrix computations are believed to be stable.

Further Comments

The same differencing operator does not have to be applied to all the series. For example, suppose we have k=2, and wish to apply the second order differencing operator 2 to the first series and the first-order differencing operator  to the second series:
w1t=2z1t= 1-B 2z1t=1-2B+B2Z1t,   and w2t=z2t=1-Bz2t.  
Then d1=2,d2=1, d=maxd1,d2=2, and
delta= δ11 δ12 δ21 = 2 -1 1 .  
Note:  although differencing may already have been applied prior to the model fitting stage, the differencing parameters supplied in delta are part of the model definition and are still required by this function to produce the forecasts.
nag_tsa_multi_varma_forecast (g13dj) should not be used when the moving average parameters lie close to the boundary of the invertibility region. The function does test for both invertibility and stationarity but if in doubt, you may use nag_tsa_uni_arma_roots (g13dx), before calling this function, to check that the VARMA model being used is invertible.
On a successful exit, the quantities k, lmax, kmax, ref and lref will be suitable for input to nag_tsa_multi_varma_update (g13dk).

Example

This example computes forecasts of the next five values in two series each of length 48. No transformation is to be used and no differencing is to be applied to either of the series. nag_tsa_multi_varma_estimate (g13dd) is first called to fit an AR(1) model to the series. The mean vector μ is to be estimated and ϕ12,1 constrained to be zero.
function g13dj_example


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

% Series
z = [-1.490 -1.620  5.200  6.230  6.210  5.860  4.090  3.180  ...
      2.620  1.490  1.170  0.850 -0.350  0.240  2.440  2.580  ...
      2.040  0.400  2.260  3.340  5.090  5.000  4.780  4.110  ...
      3.450  1.650  1.290  4.090  6.320  7.500  3.890  1.580  ...
      5.210  5.250  4.930  7.380  5.870  5.810  9.680  9.070  ...
      7.290  7.840  7.550  7.320  7.970  7.760  7.000  8.350;
      7.340  6.350  6.960  8.540  6.620  4.970  4.550  4.810  ...
      4.750  4.760 10.880 10.010 11.620 10.360  6.400  6.240  ...
      7.930  4.040  3.730  5.600  5.350  6.810  8.270  7.680  ...
      6.650  6.080 10.250  9.140 17.750 13.300  9.630  6.800  ...
      4.080  5.060  4.940  6.650  7.940 10.760 11.890  5.850  ...
      9.010  7.500 10.020 10.380  8.150  8.370 10.730 12.140];
[k,n] = size(z);

% Difference /transform series
tr    = {'N'; 'N'};
id    = [int64(0);0];
delta = [0;  0];
[w, nd, ifail] = g13dl( ...
			z, tr, id, delta);

% VARMA info
ip    = int64(1);
iq    = int64(0);
mean_p = true;

% Initial parameter estimates and free parameter flags
par    = zeros(6, 1);
parhld = [false;  false;  true;  false;  false;  false];

% Exact likelihood
exact  = true;
% control parameters
iprint = int64(-1);
cgetol = 0.0001;
ishow  = int64(0);

qq = [0, 0; 0, 0];

% Fit VARMA
[par, qq, ~, ~, v, ~, ~, ifail] = ...
  g13dd( ...
	 ip, iq, mean_p, par, qq, w, parhld, exact, iprint, cgetol, ...
	 ishow, 'n', nd);

% Perform forecast
lmax = int64(5);
lref = int64(150);
mean_p = 'M';
[qq, predz, sefz, ref, ifail] = ...
  g13dj( ...
	 z, tr, id, delta, ip, iq, mean_p, par, qq, v, lmax, lref);

% Display results
fprintf(' Forecast Summary Table\n');
fprintf(' ----------------------\n\n');
fprintf(' Forecast origin is set at t = %4d\n\n', n);
loop = lmax/5;
if mod(lmax,5)~=0
  loop = loop + 1;
end
for j = 1:loop
  i2 = (j-1)*5;
  l2 = min(i2+5,lmax);
  fprintf('Lead Time %14s',' ');
  fprintf('%7d', [i2+1:l2]);
  fprintf('\n\n');
  for i = 1:k
    fprintf('Series %d : Forecast       ', i);
    fprintf('%7.2f',predz(i,i2+1:l2));
    fprintf('\n%8s : Standard Error ', ' ');
    fprintf('%7.2f',sefz(i,i2+1:l2));
    fprintf('\n');
  end
end


g13dj example results

 Forecast Summary Table
 ----------------------

 Forecast origin is set at t =   48

Lead Time                     1      2      3      4      5

Series 1 : Forecast          7.82   7.28   6.77   6.33   5.95
         : Standard Error    1.72   2.23   2.51   2.68   2.79
Series 2 : Forecast         10.31   9.25   8.65   8.30   8.10
         : Standard Error    2.32   2.68   2.78   2.82   2.83

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