Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_tsa_multi_varma_update (g13dk)

## Purpose

nag_tsa_multi_varma_update (g13dk) accepts a sequence of new observations in a multivariate time series and updates both the forecasts and the standard deviations of the forecast errors. A call to nag_tsa_multi_varma_forecast (g13dj) must be made prior to calling this function in order to calculate the elements of a reference vector together with a set of forecasts and their standard errors. On a successful exit from nag_tsa_multi_varma_update (g13dk) the reference vector is updated so that should future series values become available these forecasts may be updated by recalling nag_tsa_multi_varma_update (g13dk).

## Syntax

[mlast, ref, v, predz, sefz, ifail] = g13dk(k, mlast, z, ref, predz, sefz, 'lmax', lmax, 'm', m, 'lref', lref)
[mlast, ref, v, predz, sefz, ifail] = nag_tsa_multi_varma_update(k, mlast, z, ref, predz, sefz, 'lmax', lmax, 'm', m, 'lref', lref)

## Description

Let ${Z}_{\mathit{t}}={\left({z}_{1\mathit{t}},{z}_{2\mathit{t}},\dots ,{z}_{k\mathit{t}}\right)}^{\mathrm{T}}$, for $\mathit{t}=1,2,\dots ,n$, denote a $k$-dimensional time series for which forecasts of ${\stackrel{^}{Z}}_{n+1},{\stackrel{^}{Z}}_{n+2},\dots ,{\stackrel{^}{Z}}_{n+{l}_{\mathrm{max}}}$ have been computed using nag_tsa_multi_varma_forecast (g13dj). Given $m$ further observations ${Z}_{n+1},{Z}_{n+2},\dots ,{Z}_{n+m}$, where $m<{l}_{\mathrm{max}}$, nag_tsa_multi_varma_update (g13dk) updates the forecasts of ${Z}_{n+m+1},{Z}_{n+m+2},\dots ,{Z}_{n+{l}_{\mathrm{max}}}$ and their corresponding standard errors.
nag_tsa_multi_varma_update (g13dk) uses a multivariate version of the procedure described in Box and Jenkins (1976). The forecasts are updated using the $\psi$ weights, computed in nag_tsa_multi_varma_forecast (g13dj). If ${Z}_{t}^{*}$ denotes the transformed value of ${Z}_{t}$ and ${\stackrel{^}{Z}}_{t}^{*}\left(l\right)$ denotes the forecast of ${Z}_{t+l}^{*}$ from time $t$ with a lead of $l$ (that is the forecast of ${Z}_{t+l}^{*}$ given observations ${Z}_{t}^{*},{Z}_{t-1}^{*},\dots \text{}$), then
 $Z^t+1*l=τ+ψlεt+1+ψl+1εt+ψl+2εt-1+⋯$
and
 $Z^t*l+ 1=τ+ψl+ 1εt+ψl+ 2εt- 1+⋯$
where $\tau$ is a constant vector of length $k$ involving the differencing parameters and the mean vector $\mu$. By subtraction we obtain
 $Z^t+1*l=Z^t*l+1+ψlεt+1.$
Estimates of the residuals corresponding to the new observations are also computed as ${\epsilon }_{n+\mathit{l}}={Z}_{n+\mathit{l}}^{*}-{\stackrel{^}{Z}}_{n}^{*}\left(\mathit{l}\right)$, for $\mathit{l}=1,2,\dots ,m$. These may be of use in checking that the new observations conform to the previously fitted model.
On a successful exit, the reference array is updated so that nag_tsa_multi_varma_update (g13dk) may be called again should future series values become available, see Further Comments.
When a transformation has been used the forecasts and their standard errors are suitably modified to give results in terms of the original series ${Z}_{t}$; 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, lmax, kmax, ref and lref from nag_tsa_multi_varma_forecast (g13dj) are suitable for input to nag_tsa_multi_varma_update (g13dk).

### Compulsory Input Parameters

1:     $\mathrm{k}$int64int32nag_int scalar
$k$, the dimension of the multivariate time series.
Constraint: ${\mathbf{k}}\ge 1$.
2:     $\mathrm{mlast}$int64int32nag_int scalar
On the first call to nag_tsa_multi_varma_update (g13dk), since calling nag_tsa_multi_varma_forecast (g13dj), mlast must be set to $0$ to indicate that no new observations have yet been used to update the forecasts; on subsequent calls mlast must contain the value of mlast as output on the previous call to nag_tsa_multi_varma_update (g13dk).
Constraint: $0\le {\mathbf{mlast}}<{\mathbf{lmax}}-{\mathbf{m}}$.
3:     $\mathrm{z}\left(\mathit{kmax},{\mathbf{m}}\right)$ – double array
kmax, the first dimension of the array, must satisfy the constraint $\mathit{kmax}\ge {\mathbf{k}}$.
${\mathbf{z}}\left(\mathit{i},\mathit{j}\right)$ must contain the value of ${z}_{\mathit{i},n+{\mathbf{mlast}}+\mathit{j}}$, for $\mathit{i}=1,2,\dots ,k$ and $\mathit{j}=1,2,\dots ,m$, and where $n$ is the number of observations in the time series in the last call made to nag_tsa_multi_varma_forecast (g13dj).
Constraint: if the transformation defined in tr in nag_tsa_multi_varma_forecast (g13dj) for the $\mathit{i}$th series is the log transformation, then ${\mathbf{z}}\left(\mathit{i},\mathit{j}\right)>0.0$, and if it is the square-root transformation, then ${\mathbf{z}}\left(\mathit{i},\mathit{j}\right)\ge 0.0$, for $\mathit{j}=1,2,\dots ,m$ and $\mathit{i}=1,2,\dots ,k$.
4:     $\mathrm{ref}\left({\mathbf{lref}}\right)$ – double array
Must contain the first $\left({\mathbf{lmax}}-1\right)×{\mathbf{k}}×{\mathbf{k}}+2×{\mathbf{k}}×{\mathbf{lmax}}+{\mathbf{k}}$ elements of the reference vector as returned on a successful exit from nag_tsa_multi_varma_forecast (g13dj) (or a previous call to nag_tsa_multi_varma_update (g13dk)).
5:     $\mathrm{predz}\left(\mathit{kmax},{\mathbf{lmax}}\right)$ – double array
kmax, the first dimension of the array, must satisfy the constraint $\mathit{kmax}\ge {\mathbf{k}}$.
Nonupdated values are kept intact.
6:     $\mathrm{sefz}\left(\mathit{kmax},{\mathbf{lmax}}\right)$ – double array
kmax, the first dimension of the array, must satisfy the constraint $\mathit{kmax}\ge {\mathbf{k}}$.
Nonupdated values are kept intact.

### Optional Input Parameters

1:     $\mathrm{lmax}$int64int32nag_int scalar
Default: the second dimension of the arrays predz, sefz. (An error is raised if these dimensions are not equal.)
The number, ${l}_{\mathrm{max}}$, of forecasts requested in the call to nag_tsa_multi_varma_forecast (g13dj).
Constraint: ${\mathbf{lmax}}\ge 2$.
2:     $\mathrm{m}$int64int32nag_int scalar
Default: the second dimension of the array z.
$m$, the number of new observations available since the last call to either nag_tsa_multi_varma_forecast (g13dj) or nag_tsa_multi_varma_update (g13dk). The number of new observations since the last call to nag_tsa_multi_varma_forecast (g13dj) is then ${\mathbf{m}}+{\mathbf{mlast}}$.
Constraint: $0<{\mathbf{m}}<{\mathbf{lmax}}-{\mathbf{mlast}}$.
3:     $\mathrm{lref}$int64int32nag_int scalar
Default: the dimension of the array ref.
The dimension of the array ref.
Constraint: ${\mathbf{lref}}\ge \left({\mathbf{lmax}}-1\right)×{\mathbf{k}}×{\mathbf{k}}+2×{\mathbf{k}}×{\mathbf{lmax}}+{\mathbf{k}}$.

### Output Parameters

1:     $\mathrm{mlast}$int64int32nag_int scalar
Is incremented by $m$ to indicate that ${\mathbf{mlast}}+{\mathbf{m}}$ observations have now been used to update the forecasts since the last call to nag_tsa_multi_varma_forecast (g13dj).
mlast must not be changed between calls to nag_tsa_multi_varma_update (g13dk), unless a call to nag_tsa_multi_varma_forecast (g13dj) has been made between the calls in which case mlast should be reset to $0$.
2:     $\mathrm{ref}\left({\mathbf{lref}}\right)$ – double array
The elements of ref are updated. The first $\left({\mathbf{lmax}}-1\right)×{\mathbf{k}}×{\mathbf{k}}$ elements store the $\psi$ weights ${\psi }_{1},{\psi }_{2},\dots ,{\psi }_{{l}_{\mathrm{max}}-1}$. The next ${\mathbf{k}}×{\mathbf{lmax}}$ elements contain the forecasts of the transformed series and the next ${\mathbf{k}}×{\mathbf{lmax}}$ elements contain the variances of the forecasts of the transformed variables; see nag_tsa_multi_varma_forecast (g13dj). The last k elements are not updated.
3:     $\mathrm{v}\left(\mathit{kmax},{\mathbf{m}}\right)$ – double array
${\mathbf{v}}\left(\mathit{i},\mathit{j}\right)$ contains an estimate of the $\mathit{i}$th component of ${\epsilon }_{n+{\mathbf{mlast}}+\mathit{j}}$, for $\mathit{i}=1,2,\dots ,k$ and $\mathit{j}=1,2,\dots ,m$.
4:     $\mathrm{predz}\left(\mathit{kmax},{\mathbf{lmax}}\right)$ – double array
${\mathbf{predz}}\left(\mathit{i},\mathit{j}\right)$ contains the updated forecast of ${z}_{\mathit{i},n+\mathit{j}}$, for $\mathit{i}=1,2,\dots ,k$ and $\mathit{j}={\mathbf{mlast}}+{\mathbf{m}}+1,\dots ,{l}_{\mathrm{max}}$.
The columns of predz corresponding to the new observations since the last call to either nag_tsa_multi_varma_forecast (g13dj) or nag_tsa_multi_varma_update (g13dk) are set equal to the corresponding columns of z.
5:     $\mathrm{sefz}\left(\mathit{kmax},{\mathbf{lmax}}\right)$ – double array
${\mathbf{sefz}}\left(\mathit{i},\mathit{j}\right)$ contains an estimate of the standard error of the corresponding element of predz, for $\mathit{i}=1,2,\dots ,k$ and $\mathit{j}={\mathbf{mlast}}+{\mathbf{m}}+1,\dots ,{l}_{\mathrm{max}}$.
The columns of sefz corresponding to the new observations since the last call to either nag_tsa_multi_varma_forecast (g13dj) or nag_tsa_multi_varma_update (g13dk) are set equal to zero.
6:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{k}}<1$, or ${\mathbf{lmax}}<2$, or ${\mathbf{m}}\le 0$, or ${\mathbf{mlast}}+{\mathbf{m}}\ge {\mathbf{lmax}}$, or ${\mathbf{mlast}}<0$, or $\mathit{kmax}<{\mathbf{k}}$, or ${\mathbf{lref}}<\left({\mathbf{lmax}}-1\right)×{\mathbf{k}}×{\mathbf{k}}+2×{\mathbf{k}}×{\mathbf{lmax}}+{\mathbf{k}}$.
${\mathbf{ifail}}=2$
On entry, some of the elements of the reference vector, ref, have been corrupted since the most recent call to nag_tsa_multi_varma_forecast (g13dj) (or nag_tsa_multi_varma_update (g13dk)).
${\mathbf{ifail}}=3$
On entry, one or more of the elements of z is invalid, for the transformation being used; that is you may be trying to log or square root a series, some of whose values are negative.
${\mathbf{ifail}}=4$
This is an unlikely exit. For one of the series, overflow will occur if the forecasts are updated. You should check whether the elements of ref have been corrupted.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

The matrix computations are believed to be stable.

If a further ${m}^{*}$ observations, ${Z}_{n+{\mathbf{mlast}}+1},{Z}_{n+{\mathbf{mlast}}+2},\dots ,{Z}_{n+{\mathbf{mlast}}+{m}^{*}}$, become available, then forecasts of ${Z}_{n+{\mathbf{mlast}}+{m}^{*}+1},{Z}_{n+{\mathbf{mlast}}+{m}^{*}+2},\dots ,{Z}_{n+{l}_{\mathrm{max}}}$ may be updated by recalling nag_tsa_multi_varma_update (g13dk) with ${\mathbf{m}}={m}^{*}$. Note that m and the contents of the array z are the only quantities which need updating; mlast is updated on exit from the previous call. On a successful exit, v contains estimates of ${\epsilon }_{n+{\mathbf{mlast}}+1},{\epsilon }_{n+{\mathbf{mlast}}+2},\dots ,{\epsilon }_{n+{\mathbf{mlast}}+{m}^{*}}$; columns ${\mathbf{mlast}}+1,{\mathbf{mlast}}+2,\dots ,{\mathbf{mlast}}+{m}^{*}$ of predz contain the new observed values ${Z}_{n+{\mathbf{mlast}}+1},{Z}_{n+{\mathbf{mlast}}+2},\dots ,{Z}_{n+{\mathbf{mlast}}+{m}^{*}}$ and columns ${\mathbf{mlast}}+1,{\mathbf{mlast}}+2,\dots ,{\mathbf{mlast}}+{m}^{*}$ of sefz are set to zero.

## Example

This example shows how to update the forecasts of two series each of length $48$. No transformation has been used and no differencing applied to either of the series. nag_tsa_multi_varma_estimate (g13dd) is first called to fit an AR(1) model to the series. $\mu$ is to be estimated and ${\varphi }_{1}\left(2,1\right)$ constrained to be zero. A call to nag_tsa_multi_varma_forecast (g13dj) is then made in order to compute forecasts of the next five series values. After one new observation becomes available the four forecasts are updated. A further observation becomes available and the three forecasts are updated.
```function g13dk_example

fprintf('g13dk 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
g13dk_print(k,n,lmax,predz,sefz);

% Update forecasts
m = int64([1; 1]);
z = [ 8.1  8.5;
10.2 10.0];
mlast = int64(0);
for j = 1:numel(m)
[mlast, ref, ~, predz, sefz, ifail] = ...
g13dk( ...
int64(k), mlast, z(:,j), ref, predz, sefz);
% Display results
g13dk_print(k,n+mlast,lmax,predz,sefz);
end

function g13dk_print(k,n,lmax,predz,sefz)
fprintf('\n 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('%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
```
```g13dk 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

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

Forecast origin is set at t =   49

Lead Time                     1      2      3      4      5

Series 1 : Forecast          8.10   7.49   6.94   6.46   6.06
: Standard Error    0.00   1.72   2.23   2.51   2.68
Series 2 : Forecast         10.20   9.19   8.61   8.28   8.08
: Standard Error    0.00   2.32   2.68   2.78   2.82

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

Forecast origin is set at t =   50

Lead Time                     1      2      3      4      5

Series 1 : Forecast          8.10   8.50   7.80   7.18   6.65
: Standard Error    0.00   0.00   1.72   2.23   2.51
Series 2 : Forecast         10.20  10.00   9.08   8.54   8.24
: Standard Error    0.00   0.00   2.32   2.68   2.78
```