NAG Library Routine Document

g13djf (multi_varma_forecast)


g13djf 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 g13ddf. 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 g13dkf.


Fortran Interface
Subroutine g13djf ( k, n, z, kmax, tr, id, delta, ip, iq, mean, par, lpar, qq, v, lmax, predz, sefz, ref, lref, work, lwork, iwork, liwork, ifail)
Integer, Intent (In):: k, n, kmax, id(k), ip, iq, lpar, lmax, lref, lwork, liwork
Integer, Intent (Inout):: ifail
Integer, Intent (Out):: iwork(liwork)
Real (Kind=nag_wp), Intent (In):: z(kmax,n), delta(kmax,*), par(lpar), v(kmax,*)
Real (Kind=nag_wp), Intent (Inout):: qq(kmax,k), predz(kmax,lmax), sefz(kmax,lmax)
Real (Kind=nag_wp), Intent (Out):: ref(lref), work(lwork)
Character (1), Intent (In):: tr(k), mean
C Header Interface
#include <nagmk26.h>
void  g13djf_ (const Integer *k, const Integer *n, const double z[], const Integer *kmax, const char tr[], const Integer id[], const double delta[], const Integer *ip, const Integer *iq, const char *mean, const double par[], const Integer *lpar, double qq[], const double v[], const Integer *lmax, double predz[], double sefz[], double ref[], const Integer *lref, double work[], const Integer *lwork, Integer iwork[], const Integer *liwork, Integer *ifail, const Charlen length_tr, const Charlen length_mean)


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 g13dxf for a method of checking these conditions.
The ARMA model (1) may be rewritten as
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
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
The forecast error at t for lead l is then
Let d=maxdi, for i=1,2,,k. Unless q=0 the routine requires estimates of εt, for t=d+1,,n, which are obtainable from g13ddf. The terms εt are assumed to be zero, for t=n+1,,n+lmax. You may use g13dkf 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 g13djf 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).


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


The quantities k, n, kmax, ip, iq, par, npar, qq and v from g13ddf are suitable for input to g13djf.
1:     k – IntegerInput
On entry: k, the dimension of the multivariate time series.
Constraint: k1.
2:     n – IntegerInput
On entry: 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='Z', n×k>ip+iq×k×k+k×k+1/2;
  • if mean='M', n×k>ip+iq×k×k+k+k×k+1/2,
(see the arguments ip, iq and mean).
3:     zkmaxn – Real (Kind=nag_wp) arrayInput
On entry: zit must contain, zit, the ith component of Zt, for i=1,2,,k and t=1,2,,n.
  • if tri='L', zit>0.0;
  • if tri='S', zit0.0, for i=1,2,,k and t=1,2,,n.
4:     kmax – IntegerInput
On entry: the first dimension of the arrays z, delta, qq, v, predz and sefz as declared in the (sub)program from which g13djf is called.
Constraint: kmaxk.
5:     trk – Character(1) arrayInput
On entry: tri indicates whether the ith time series is to be transformed, for i=1,2,,k.
No transformation is used.
A log transformation is used.
A square root transformation is used.
Constraint: tri='N', 'L' or 'S', for i=1,2,,k.
6:     idk – Integer arrayInput
On entry: idi must specify, di, the order of differencing required for the ith series.
Constraint: 0idi<n-maxip,iq, for i=1,2,,k.
7:     deltakmax* – Real (Kind=nag_wp) arrayInput
Note: the second dimension of the array delta must be at least max1,d, where d=maxidi.
On entry: 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.
8:     ip – IntegerInput
On entry: p, the number of AR parameter matrices.
Constraint: ip0.
9:     iq – IntegerInput
On entry: q, the number of MA parameter matrices.
Constraint: iq0.
10:   mean – Character(1)Input
On entry: mean='M', if components of μ have been estimated and mean='Z', if all elements of μ are to be taken as zero.
Constraint: mean='M' or 'Z'.
11:   parlpar – Real (Kind=nag_wp) arrayInput
On entry: must contain the parameter estimates read in row by row in the order ϕ1,ϕ2,,ϕp, θ1,θ2,,θq, μ.
  • 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='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.
12:   lpar – IntegerInput
On entry: the dimension of the array par as declared in the (sub)program from which g13djf is called.
  • if mean='Z', lparmax1,ip+iq×k×k;
  • if mean='M', lparip+iq×k×k+k.
13:   qqkmaxk – Real (Kind=nag_wp) arrayInput/Output
On entry: qqij must contain an estimate of the i,jth element of Σ. The lower triangle only is needed.
Constraint: qq must be positive definite.
On exit: if ifail1, then the upper triangle is set equal to the lower triangle.
14:   vkmax* – Real (Kind=nag_wp) arrayInput
Note: the second dimension of the array v must be at least max1,n-d, where d=maxidi.
On entry: 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.
15:   lmax – IntegerInput
On entry: the number, lmax, of forecasts required.
Constraint: lmax1.
16:   predzkmaxlmax – Real (Kind=nag_wp) arrayOutput
On exit: predzil contains the forecast of zi,n+l, for i=1,2,,k and l=1,2,,lmax.
17:   sefzkmaxlmax – Real (Kind=nag_wp) arrayOutput
On exit: 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.
18:   reflref – Real (Kind=nag_wp) arrayOutput
On exit: the reference vector which may be used to update forecasts using g13dkf. 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.
19:   lref – IntegerInput
On entry: the dimension of the array ref as declared in the (sub)program from which g13djf is called.
Constraint: lreflmax-1×k×k+2×k×lmax+k.
20:   worklwork – Real (Kind=nag_wp) arrayWorkspace
21:   lwork – IntegerInput
On entry: the dimension of the array work as declared in the (sub)program from which g13djf is called.
Constraint: if r=maxip,iq and d=maxidi, for i=1,2,,k, lworkmaxkrkr+2, ip+d+2k2+n+lmaxk.
22:   iworkliwork – Integer arrayWorkspace
23:   liwork – IntegerInput
On entry: the dimension of the array iwork as declared in the (sub)program from which g13djf is called.
Constraint: liworkk×maxip,iq.
24:   ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1 or 1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1 or 1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this argument, the recommended value is 0. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

Error Indicators and Warnings

If on entry ifail=0 or -1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
On entry, i=value, idi=value and n-maxip,iq=value.
Constraint: 0idi<n-maxip,iq.
On entry, ip=value.
Constraint: ip0.
On entry, iq=value.
Constraint: iq0.
On entry, k=value.
Constraint: k1.
On entry, kmax=value and k=value.
Constraint: kmaxk.
On entry, liwork=value and the minimum size required=value.
Constraint: liworkk×maxip,iq.
On entry, lmax=value.
Constraint: lmax1.
On entry, lpar is too small: lpar=value and the minimum size required=value.
On entry, lref=value and the minimum size required=value.
Constraint: lreflmax-1×k×k+2×k×lmax+k.
On entry, lwork is too small: lwork=value and the minimum size required=value.
On entry, mean is an invalid character.
Constraint: mean='M' or 'Z'.
On entry, n=value.
Constraint: n3.
On entry, number of observations =value and number of parameters =value.
Constraint: number of observationsnumber of parameters.
On entry, i=value and tri is invalid.
Constraint: tri='N', 'L' or 'S'.
On entry, one (or more) of the transformations requested is invalid. Check that you are not trying to log or square-root a series, some of whose values are negative.
On entry, the AR parameter matrices are outside the stationarity region. To proceed you must supply different parameter estimates in the arrays par and qq.
On entry, the covariance matrix qq is not positive definite. To proceed you must supply different parameter estimates in the arrays par and qq.
On entry, the MA parameter matrices are outside the invertibility region. To proceed you must supply different parameter estimates in the arrays par and qq.
An excessive number of iterations were needed to evaluate the eigenvalues of the matrices used to test for stationarity and invertibility.
The covariance matrix may be 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.
The forecasts will overflow if computed. You should check whether the transformations requested in the array tr are sensible.
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.


The matrix computations are believed to be stable.

Parallelism and Performance

g13djf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g13djf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

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 routine to produce the forecasts.
g13djf should not be used when the moving average parameters lie close to the boundary of the invertibility region. The routine does test for both invertibility and stationarity but if in doubt, you may use g13dxf, before calling this routine, 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 g13dkf.


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. g13ddf 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.

Program Text

Program Text (g13djfe.f90)

Program Data

Program Data (g13djfe.d)

Program Results

Program Results (g13djfe.r)