-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcomputeMSPE.m
58 lines (47 loc) · 1.61 KB
/
computeMSPE.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function MSPE = computeMSPE(estMdl, steps, fMatrix, asMATLAB)
% Return MSPE = (steps, var kth, shock jth) at each horizon h=0..steps-1
% Syntax MSPE = computeMSPE(estMdl, steps, fMatrix, asMATLAB)
%
% Each row of squeeze(MSPE(h,:,:)) is the contribution of jth-var shock
% (j=1..K) to each kth-variable, so that sum over column is of one. That is,
%
% 1 = MSPE(h,k,j=1)/MSPE(h,k,*) + MSPE(h,k,j)/MSPE(h,k,*) +...+ MSPE(h,k,j=K)/MSPE(h,k,*)
% for k = 1..K.
%
% Syntax: MSPE = computeMSPE(estMdl, steps, fMatrix, asMATLAB)
% Input : estMdl (estimated varm object), horizon steps, factor matrix
% (default or [] = Cholesky), asMATLAB=0 (default)
%
% Output: MSPE(k,j) matrix at horizon (steps) h
%
% Reference: Lutkepohl (2005), and Kilian and Lutkepohl (2017).
% Author: Binh Thai Pham, PhD. ([email protected]). 2020.
if nargin < 4
asMATLAB = 0;
end
if nargin < 3
fMatrix = [];
end
if nargin < 2
steps = 2;
end
if isobject(estMdl) && isa(estMdl,'varm') && (~isempty(estMdl.AR))
K = estMdl.NumSeries;
MSPE = zeros(steps, K, K);
MSPEkj = zeros(K);
for i=1:steps
% Note: function computeMSPEkj returns MSPEkj for h=0..steps-1 so that
% we input the function at h = i in this function.
% MSPEkj = computeMSPEkj(estMdl, i, fMatrix);
% MSPEk = repmat(sum(MSPEkj,2), [1 K]);
%
% MSPE(i,:,:) = MSPEkj ./ MSPEk;
MSPE(i,:,:) = computeMSPEkj(estMdl, i, fMatrix);
end
if asMATLAB ~= 0
MSPE = permute(MSPE, [1,3,2]);
end
else
MSPE = [];
end
end