Generalised trend component model.

Added the possibility to associate more than one trend to an endogenous
variable. The number of error correction equations is longer required to be
equal to the number of trends.
time-shift
Stéphane Adjemian (Charybdis) 2019-03-29 17:45:29 +01:00
parent d84d8af8a8
commit 7b7bca8bda
Signed by untrusted user who does not match committer: stepan
GPG Key ID: A6D44CB9C64CE77B
15 changed files with 198 additions and 12 deletions

View File

@ -1,4 +1,4 @@
function [A0, AR, B] = get_companion_matrix(auxiliary_model_name, auxiliary_model_type)
function [A0, A0star, AR, B] = get_companion_matrix(auxiliary_model_name, auxiliary_model_type)
% Gets the companion VAR representation of a PAC auxiliary model.
% Depending on the nature of this auxiliary model the output is
@ -66,6 +66,7 @@ switch auxiliary_model_type
M_.var.(auxiliary_model_name).list_of_variables_in_companion_var = M_.endo_names(M_.var.(auxiliary_model_name).lhs);
if nargout
A0 = [];
A0star = [];
B = [];
end
case 'trend_component'

@ -1 +1 @@
Subproject commit 92af6ffbe7c8f02b335bdc1e735b9e5920b70fdf
Subproject commit 8dad93964da8ed27d165073a39361901ed670e1b

View File

@ -385,6 +385,8 @@ ECB_MODFILES = \
trend-component-and-var-models/tcm6.mod \
trend-component-and-var-models/tcm7.mod \
trend-component-and-var-models/tcm8.mod \
trend-component-and-var-models/tcm9.mod \
trend-component-and-var-models/tcm10.mod \
trend-component-and-var-models/legacy/vm1.mod \
trend-component-and-var-models/legacy/vm2.mod \
trend-component-and-var-models/legacy/vm3.mod \

View File

@ -63,7 +63,7 @@ y4 = y4(-1) + e4;
end;
[EC, AR, T] = get_companion_matrix('toto');
[EC, A0star, AR, T] = get_companion_matrix('toto');
if max(max(abs(EC-B)))>1e-12
error('Error component matrix is wrong.')

View File

@ -0,0 +1,93 @@
var y1 y2 y3 y4 y5;
varexo e1 e2 e3 e4 e5;
parameters A111 A112
A121 A122
A211 A212
A221 A222
A311 A312
A321 A322
B11 B12 B21 B22;
A1 = randn(2);
A2 = randn(2);
A3 = randn(2);
A111 = A1(1,1);
A112 = A1(1,2);
A121 = A1(2,1);
A122 = A1(2,2);
A211 = A2(1,1);
A212 = A2(1,2);
A221 = A2(2,1);
A222 = A2(2,2);
A311 = A3(1,1);
A312 = A3(1,2);
A321 = A3(2,1);
A322 = A3(2,2);
B = rand(2);
B(1,1) = -B(1,1);
B(2,2) = -B(2,2);
B11 = B(1,1);
B12 = B(1,2);
B21 = B(2,1);
B22 = B(2,2);
Bstar = [B11, B12, -B11; B21, B22, -B21];
trend_component_model(model_name=toto, eqtags=['eq:y1', 'eq:y2', 'eq:y3', 'eq:y4', 'eq:y5'], targets=['eq:y3', 'eq:y4', 'eq:y5']);
model;
[name='eq:y1']
diff(y1) = B11*(y1(-1)-y3(-1)+y5(-1)) + B12*(y2(-1)-y4(-1)) +
A111*diff(y1(-1)) + A112*diff(y2(-1)) +
A211*diff(y1(-2)) + A212*diff(y2(-2)) +
A311*diff(y1(-3)) + A312*diff(y2(-3)) + e1;
[name='eq:y2']
diff(y2) = B21*(y1(-1)-y3(-1)+y5(-1)) + B22*(y2(-1)-y4(-1)) +
A121*diff(y1(-1)) + A122*diff(y2(-1)) +
A221*diff(y1(-2)) + A222*diff(y2(-2)) +
A321*diff(y1(-3)) + A322*diff(y2(-3)) + e2;
[name='eq:y3']
y3 = y3(-1) + e3;
[name='eq:y4']
y4 = y4(-1) + e4;
[name='eq:y5']
y5 = y5(-1) + e5;
end;
[A0, A0star, AR, T] = get_companion_matrix('toto');
if max(max(abs(A0-B)))>1e-12
error('Error component matrix (A0) is wrong.')
end
if max(max(abs(A0star-Bstar)))>1e-12
error('Error component matrix (A0star) is wrong.')
end
A1fake = AR(:,:,1);
if max(max(abs(A1fake-A1)))>1e-12
error('First order autoregressive matrix is wrong.')
end
if max(max(abs(AR(:,:,2)-A2)))>1e-12
error('Second order autoregressive matrix is wrong.')
end
if max(max(abs(AR(:,:,3)-A3)))>1e-12
error('Third order autoregressive matrix is wrong.')
end

View File

@ -63,7 +63,7 @@ y4 = y4(-1) + e4;
end;
[EC, AR, T] = get_companion_matrix('toto');
[EC, A0star, AR, T] = get_companion_matrix('toto');
if max(max(abs(EC-B)))>1e-12
error('Error component matrix is wrong.')

View File

@ -63,7 +63,7 @@ y4 = y4(-1) + e4;
end;
[EC, AR, T] = get_companion_matrix('toto');
[EC, A0star, AR, T] = get_companion_matrix('toto');
if max(max(abs(EC-B)))>1e-12
error('Error component matrix is wrong.')

View File

@ -64,7 +64,7 @@ y3 = y3(-1) + e3;
end;
[EC, AR, T] = get_companion_matrix('toto');
[EC, A0star, AR, T] = get_companion_matrix('toto');
if max(max(abs(EC-B)))>1e-12
error('Error component matrix is wrong.')

View File

@ -64,7 +64,7 @@ y3 = y3(-1) + e3;
end;
[EC, AR, T] = get_companion_matrix('toto');
[EC, A0star, AR, T] = get_companion_matrix('toto');
if max(max(abs(EC-B)))>1e-12
error('Error component matrix is wrong.')

View File

@ -0,0 +1,90 @@
var y1 y2 y3 y4;
varexo e1 e2 e3 e4;
parameters A111 A112
A121 A122
A211 A212
A221 A222
A311 A312
A321 A322
B11 B12 B21 B22;
A1 = randn(2);
A2 = randn(2);
A3 = randn(2);
A111 = A1(1,1);
A112 = A1(1,2);
A121 = A1(2,1);
A122 = A1(2,2);
A211 = A2(1,1);
A212 = A2(1,2);
A221 = A2(2,1);
A222 = A2(2,2);
A311 = A3(1,1);
A312 = A3(1,2);
A321 = A3(2,1);
A322 = A3(2,2);
B = rand(2);
B(1,1) = -B(1,1);
B(2,2) = -B(2,2);
B11 = B(1,1);
B12 = B(1,2);
B21 = B(2,1);
B22 = B(2,2);
Bstar = [B11, B12-B11; B21, B22];
trend_component_model(model_name=toto, eqtags=['eq:y1', 'eq:y4', 'eq:y2', 'eq:y3'], targets=['eq:y3', 'eq:y4']);
model;
[name='eq:y1']
diff(y1) = B11*(y1(-1)-y3(-1)+y4(-1)) + B12*(y2(-1)-y4(-1)) +
A111*diff(y1(-1)) + A112*diff(y2(-1)) +
A211*diff(y1(-2)) + A212*diff(y2(-2)) +
A311*diff(y1(-3)) + A312*diff(y2(-3)) + e1;
[name='eq:y2']
diff(y2) = B21*(y1(-1)-y3(-1)) + B22*(y2(-1)-y4(-1)) +
A121*diff(y1(-1)) + A122*diff(y2(-1)) +
A221*diff(y1(-2)) + A222*diff(y2(-2)) +
A321*diff(y1(-3)) + A322*diff(y2(-3)) + e2;
[name='eq:y3']
y3 = y3(-1) + e3;
[name='eq:y4']
y4 = y4(-1) + e4;
end;
[A0, A0star, AR, T] = get_companion_matrix('toto');
if max(max(abs(A0-B)))>1e-12
error('Error component matrix (A0) is wrong.')
end
if max(max(abs(A0star-Bstar)))>1e-12
error('Error component matrix (A0star) is wrong.')
end
A1fake = AR(:,:,1);
if max(max(abs(A1fake-A1)))>1e-12
error('First order autoregressive matrix is wrong.')
end
if max(max(abs(AR(:,:,2)-A2)))>1e-12
error('Second order autoregressive matrix is wrong.')
end
if max(max(abs(AR(:,:,3)-A3)))>1e-12
error('Third order autoregressive matrix is wrong.')
end

View File

@ -96,7 +96,7 @@ y4 = A141*y1(-1) + A142*y2(-1) + A143*y3(-1) + A144*y4(-1) +
end;
[A0, AR, B] = get_companion_matrix('toto');
[A0, A0star, AR, B] = get_companion_matrix('toto');
if max(max(abs(AR(:,:,1)-A1)))>1e-12
error('First order autoregressive matrix is wrong.')

View File

@ -96,7 +96,7 @@ y4 = A141*y1(-1) + A142*y2(-1) + A143*y3(-1) + A144*y4(-1) +
end;
[A0, AR, B] = get_companion_matrix('toto');
[A0, A0star, AR, B] = get_companion_matrix('toto');
if max(max(abs(AR(:,:,1)-A1)))>1e-12
error('First order autoregressive matrix is wrong.')

View File

@ -96,7 +96,7 @@ y1 = A111*y1(-1) + A112*y2(-1) + A113*y3(-1) + A114*y4(-1) +
end;
[A0, AR, B] = get_companion_matrix('toto');
[A0, A0star, AR, B] = get_companion_matrix('toto');
if max(max(abs(AR(:,:,1)-A1)))>1e-12
error('First order autoregressive matrix is wrong.')

View File

@ -45,7 +45,7 @@ end;
[~, b0, ~] = get_companion_matrix_legacy('toto');
[~, b1, ~] = get_companion_matrix('toto');
[~, ~, b1, ~] = get_companion_matrix('toto');
if any(abs(b0(:)-b1(:))>1e-9)
error('get_companion_matrix and get_comapnion_matrix_legacy do not return the same AR matrices.')

View File

@ -98,7 +98,7 @@ y4 = A141*log(y1(-1)) + A142*y2(-1) + A143*y3(-1) + A144*y4(-1) +
end;
[A0, AR, B] = get_companion_matrix('toto');
[A0, A0star, AR, B] = get_companion_matrix('toto');
if max(max(abs(AR(:,:,1)-A1)))>1e-12
error('First order autoregressive matrix is wrong.')