diff --git a/matlab/+pac/initialize.m b/matlab/+pac/initialize.m index bc0e989c8..6d1b73753 100644 --- a/matlab/+pac/initialize.m +++ b/matlab/+pac/initialize.m @@ -39,4 +39,4 @@ end M_.pac.(pacmodel).auxiliary_model_type = auxiliary_model_type; -get_companion_matrix(auxiliary_model_name, auxiliary_model_type); \ No newline at end of file +get_companion_matrix_legacy(auxiliary_model_name, auxiliary_model_type); \ No newline at end of file diff --git a/matlab/+var_expectation/+update/parameters.m b/matlab/+var_expectation/+update/parameters.m index 8981686cb..b3582e294 100644 --- a/matlab/+var_expectation/+update/parameters.m +++ b/matlab/+var_expectation/+update/parameters.m @@ -59,7 +59,7 @@ auxcalib = DynareOutput.(varexpectationmodel.auxiliary_model_type).(varexpectati if ~isfield(auxcalib, 'CompanionMatrix') || any(isnan(auxcalib.CompanionMatrix(:))) message = sprintf('Auxiliary model %s has to be estimated first.', varexpectationmodel.auxiliary_model_name); - message = sprintf('%s\nPlease use get_companion_matrix command first.', message); + message = sprintf('%s\nPlease use *get_companion_matrix command first.', message); error(message); end diff --git a/matlab/+var_expectation/initialize.m b/matlab/+var_expectation/initialize.m index 06f40eab3..65b6ae6ea 100644 --- a/matlab/+var_expectation/initialize.m +++ b/matlab/+var_expectation/initialize.m @@ -42,4 +42,4 @@ end M_.var_expectation.(varexpectationmodel).auxiliary_model_type = auxiliary_model_type; -get_companion_matrix(auxiliary_model_name, auxiliary_model_type); \ No newline at end of file +get_companion_matrix_legacy(auxiliary_model_name, auxiliary_model_type); \ No newline at end of file diff --git a/matlab/get_companion_matrix.m b/matlab/get_companion_matrix.m index 825dc08b5..8e9929d87 100644 --- a/matlab/get_companion_matrix.m +++ b/matlab/get_companion_matrix.m @@ -31,7 +31,7 @@ function [A0, AR, B] = get_companion_matrix(auxiliary_model_name, auxiliary_mode global oo_ M_ -if nargin<2 +if nargin < 2 if isfield(M_, 'var') && isfield(M_.var, auxiliary_model_name) auxiliary_model_type = 'var'; elseif isfield(M_, 'trend_component') && isfield(M_.trend_component, auxiliary_model_name) @@ -41,39 +41,47 @@ if nargin<2 end end -if nargout - A0 = []; - AR = []; - B = []; +if strcmp(auxiliary_model_type, 'var') + AR = evalin('base', [M_.fname '.var_ar(''' auxiliary_model_name ''', M_.params)']); +elseif strcmp(auxiliary_model_type, 'trend_component') + [AR, A0] = evalin('base', [M_.fname '.trend_component_ar_ec(''' auxiliary_model_name ''', M_.params)']); +else + error('Unknown type of auxiliary model.') end -get_ar_ec_matrices(auxiliary_model_name, auxiliary_model_type); - % Get the number of lags -p = size(oo_.(auxiliary_model_type).(auxiliary_model_name).ar, 3); +p = size(AR, 3); % Get the number of variables -n = length(oo_.(auxiliary_model_type).(auxiliary_model_name).ar(:,:,1)); +n = length(M_.(auxiliary_model_type).(auxiliary_model_name).lhs); switch auxiliary_model_type case 'var' oo_.var.(auxiliary_model_name).CompanionMatrix = zeros(n*p); - oo_.var.(auxiliary_model_name).CompanionMatrix(1:n,1:n) = oo_.var.(auxiliary_model_name).ar(:,:,1); - for i=2:p - oo_.var.(auxiliary_model_name).CompanionMatrix(1:n,(i-1)*n+(1:n)) = oo_.var.(auxiliary_model_name).ar(:,:,i); + oo_.var.(auxiliary_model_name).CompanionMatrix(1:n,1:n) = AR(:,:,1); + for i = 2:p + oo_.var.(auxiliary_model_name).CompanionMatrix(1:n,(i-1)*n+(1:n)) = AR(:,:,i); oo_.var.(auxiliary_model_name).CompanionMatrix((i-1)*n+(1:n),(i-2)*n+(1:n)) = eye(n); end M_.var.(auxiliary_model_name).list_of_variables_in_companion_var = M_.endo_names(M_.var.(auxiliary_model_name).lhs); + if nargout + A0 = []; + B = []; + end case 'trend_component' % Get number of trends. q = sum(M_.trend_component.(auxiliary_model_name).trends); + % Get the number of equations with error correction. - m = n-q; + m = n - q; + % Get the indices of trend and EC equations in the auxiliary model. trend_eqnums_in_auxiliary_model = find(M_.trend_component.(auxiliary_model_name).trends); ecm_eqnums_in_auxiliary_model = find(~M_.trend_component.(auxiliary_model_name).trends); + % Get the indices of trend equations in model. trend_eqnums = M_.trend_component.(auxiliary_model_name).trend_eqn; + % REMARK It is assumed that the non trend equations are the error correction % equations. We assume that the model can be cast in the following form: % @@ -99,68 +107,71 @@ switch auxiliary_model_type % % where the dimensions of I and 0 matrices can easily be % deduced from the number of EC and trend equations. + % Check that the lhs of candidate ecm equations are at least first differences. - for i=1:m + for i = 1:m if ~get_difference_order(M_.trend_component.(auxiliary_model_name).lhs(ecm_eqnums_in_auxiliary_model(i))) - error('Model %s is not a Trend component model! LHS variables should be in difference', auxiliary_model_name) + error([auxiliary_model_name ' is not a trend component model. The LHS variables should be in differences']) end end + % Get the trend variables indices (lhs variables in trend equations). [~, id_trend_in_var, ~] = intersect(M_.trend_component.(auxiliary_model_name).eqn, trend_eqnums); trend_variables = reshape(M_.trend_component.(auxiliary_model_name).lhs(id_trend_in_var), q, 1); + % Get the rhs variables in trend equations. - trend_autoregressive_variables = zeros(q, 1); - for i=1:q + for i = 1:q % Check that there is only one variable on the rhs and update trend_autoregressive_variables. v = M_.trend_component.(auxiliary_model_name).rhs.vars_at_eq{id_trend_in_var(i)}.var; - if length(v)~=1 + if length(v) ~= 1 error('A trend equation (%s) must have only one variable on the RHS!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)}) end - trend_autoregressive_variables(i) = v; + % Check that the variables on lhs and rhs have the same difference orders. - if get_difference_order(trend_variables(i))~=get_difference_order(trend_autoregressive_variables(i)) + if get_difference_order(trend_variables(i)) ~= get_difference_order(v) error('In a trend equation (%s) LHS and RHS variables must have the same difference orders!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)}) end + % Check that the trend equation is autoregressive. if isdiff(v) - if ~M_.aux_vars(get_aux_variable_id(v)).type==9 + if ~M_.aux_vars(get_aux_variable_id(v)).type == 9 error('In a trend equation (%s) RHS variable must be lagged LHS variable!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)}) else - if M_.aux_vars(get_aux_variable_id(v)).orig_index~=trend_variables(i) + if M_.aux_vars(get_aux_variable_id(v)).orig_index ~= trend_variables(i) error('In a trend equation (%s) RHS variable must be lagged LHS variable!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)}) end end else - if get_aux_variable_id(v) && M_.aux_vars(get_aux_variable_id(v)).endo_index~=trend_variables(i) + if get_aux_variable_id(v) && M_.aux_vars(get_aux_variable_id(v)).endo_index ~= trend_variables(i) error('In a trend equation (%s) RHS variable must be lagged LHS variable!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)}) end end end + % Reorder trend_eqnums_in_auxiliary_model to ensure that the order of % the trend variables matches the order of the error correction % variables. [~,reorder] = ismember(M_.trend_component.toto.lhs(trend_eqnums_in_auxiliary_model), ... - M_.trend_component.toto.trend_vars(find(M_.trend_component.toto.trend_vars>0))); + M_.trend_component.toto.trend_vars(M_.trend_component.toto.trend_vars > 0)); trend_eqnums_in_auxiliary_model = trend_eqnums_in_auxiliary_model(reorder); + % Get the EC matrix (the EC term is assumend to be in t-1). % % TODO: Check that the EC term is the difference between the % endogenous variable and the trend variable. % - A0 = oo_.trend_component.(auxiliary_model_name).ec(ecm_eqnums_in_auxiliary_model,:,1); - % Get the AR matrices. - AR = oo_.trend_component.(auxiliary_model_name).ar(ecm_eqnums_in_auxiliary_model,ecm_eqnums_in_auxiliary_model,:); % Build B matrices (VAR in levels) - B(ecm_eqnums_in_auxiliary_model,ecm_eqnums_in_auxiliary_model,1) = eye(m)+A0+AR(:,:,1); - B(ecm_eqnums_in_auxiliary_model,trend_eqnums_in_auxiliary_model) = -A0; - B(trend_eqnums_in_auxiliary_model,trend_eqnums_in_auxiliary_model) = eye(q); - for i=2:p - B(ecm_eqnums_in_auxiliary_model,ecm_eqnums_in_auxiliary_model,i) = AR(:,:,i)-AR(:,:,i-1); + B(ecm_eqnums_in_auxiliary_model, ecm_eqnums_in_auxiliary_model, 1) = eye(m) + A0 + AR(:,:,1); + B(ecm_eqnums_in_auxiliary_model, trend_eqnums_in_auxiliary_model) = -A0; + B(trend_eqnums_in_auxiliary_model, trend_eqnums_in_auxiliary_model) = eye(q); + for i = 2:p + B(ecm_eqnums_in_auxiliary_model,ecm_eqnums_in_auxiliary_model,i) = AR(:,:,i) - AR(:,:,i-1); end B(ecm_eqnums_in_auxiliary_model,ecm_eqnums_in_auxiliary_model,p+1) = -AR(:,:,p); + % Write Companion matrix oo_.trend_component.(auxiliary_model_name).CompanionMatrix = zeros(size(B, 1)*size(B, 3)); - for i=1:p + for i = 1:p oo_.trend_component.(auxiliary_model_name).CompanionMatrix(1:n, (i-1)*n+(1:n)) = B(:,:,i); oo_.trend_component.(auxiliary_model_name).CompanionMatrix(i*n+(1:n),(i-1)*n+(1:n)) = eye(n); end diff --git a/matlab/get_companion_matrix_preprocessor.m b/matlab/get_companion_matrix_legacy.m similarity index 81% rename from matlab/get_companion_matrix_preprocessor.m rename to matlab/get_companion_matrix_legacy.m index e7835b473..a6a06b198 100644 --- a/matlab/get_companion_matrix_preprocessor.m +++ b/matlab/get_companion_matrix_legacy.m @@ -1,6 +1,5 @@ -function [A0, AR, B] = get_companion_matrix_preprocessor(auxiliary_model_name, auxiliary_model_type) -%function [A0, AR, B] = get_companion_matrix_preprocessor(auxiliary_model_name, auxiliary_model_type) -% +function [A0, AR, B] = get_companion_matrix_legacy(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 % saved in oo_.{var,trend_component}.(auxiliary_model_name).CompanionMatrix @@ -32,7 +31,7 @@ function [A0, AR, B] = get_companion_matrix_preprocessor(auxiliary_model_name, a global oo_ M_ -if nargin < 2 +if nargin<2 if isfield(M_, 'var') && isfield(M_.var, auxiliary_model_name) auxiliary_model_type = 'var'; elseif isfield(M_, 'trend_component') && isfield(M_.trend_component, auxiliary_model_name) @@ -42,47 +41,39 @@ if nargin < 2 end end -if strcmp(auxiliary_model_type, 'var') - AR = evalin('base', [M_.fname '.var_ar(''' auxiliary_model_name ''', M_.params)']); -elseif strcmp(auxiliary_model_type, 'trend_component') - [AR, A0] = evalin('base', [M_.fname '.trend_component_ar_ec(''' auxiliary_model_name ''', M_.params)']); -else - error('Unknown type of auxiliary model.') +if nargout + A0 = []; + AR = []; + B = []; end +get_ar_ec_matrices(auxiliary_model_name, auxiliary_model_type); + % Get the number of lags -p = size(AR, 3); +p = size(oo_.(auxiliary_model_type).(auxiliary_model_name).ar, 3); % Get the number of variables -n = length(M_.(auxiliary_model_type).(auxiliary_model_name).lhs); +n = length(oo_.(auxiliary_model_type).(auxiliary_model_name).ar(:,:,1)); switch auxiliary_model_type case 'var' oo_.var.(auxiliary_model_name).CompanionMatrix = zeros(n*p); - oo_.var.(auxiliary_model_name).CompanionMatrix(1:n,1:n) = AR(:,:,1); - for i = 2:p - oo_.var.(auxiliary_model_name).CompanionMatrix(1:n,(i-1)*n+(1:n)) = AR(:,:,i); + oo_.var.(auxiliary_model_name).CompanionMatrix(1:n,1:n) = oo_.var.(auxiliary_model_name).ar(:,:,1); + for i=2:p + oo_.var.(auxiliary_model_name).CompanionMatrix(1:n,(i-1)*n+(1:n)) = oo_.var.(auxiliary_model_name).ar(:,:,i); oo_.var.(auxiliary_model_name).CompanionMatrix((i-1)*n+(1:n),(i-2)*n+(1:n)) = eye(n); end M_.var.(auxiliary_model_name).list_of_variables_in_companion_var = M_.endo_names(M_.var.(auxiliary_model_name).lhs); - if nargout - A0 = []; - B = []; - end case 'trend_component' % Get number of trends. q = sum(M_.trend_component.(auxiliary_model_name).trends); - % Get the number of equations with error correction. - m = n - q; - + m = n-q; % Get the indices of trend and EC equations in the auxiliary model. trend_eqnums_in_auxiliary_model = find(M_.trend_component.(auxiliary_model_name).trends); ecm_eqnums_in_auxiliary_model = find(~M_.trend_component.(auxiliary_model_name).trends); - % Get the indices of trend equations in model. trend_eqnums = M_.trend_component.(auxiliary_model_name).trend_eqn; - % REMARK It is assumed that the non trend equations are the error correction % equations. We assume that the model can be cast in the following form: % @@ -108,71 +99,68 @@ switch auxiliary_model_type % % where the dimensions of I and 0 matrices can easily be % deduced from the number of EC and trend equations. - % Check that the lhs of candidate ecm equations are at least first differences. - for i = 1:m + for i=1:m if ~get_difference_order(M_.trend_component.(auxiliary_model_name).lhs(ecm_eqnums_in_auxiliary_model(i))) - error([auxiliary_model_name ' is not a trend component model. The LHS variables should be in differences']) + error('Model %s is not a Trend component model! LHS variables should be in difference', auxiliary_model_name) end end - % Get the trend variables indices (lhs variables in trend equations). [~, id_trend_in_var, ~] = intersect(M_.trend_component.(auxiliary_model_name).eqn, trend_eqnums); trend_variables = reshape(M_.trend_component.(auxiliary_model_name).lhs(id_trend_in_var), q, 1); - % Get the rhs variables in trend equations. - for i = 1:q + trend_autoregressive_variables = zeros(q, 1); + for i=1:q % Check that there is only one variable on the rhs and update trend_autoregressive_variables. v = M_.trend_component.(auxiliary_model_name).rhs.vars_at_eq{id_trend_in_var(i)}.var; - if length(v) ~= 1 + if length(v)~=1 error('A trend equation (%s) must have only one variable on the RHS!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)}) end - + trend_autoregressive_variables(i) = v; % Check that the variables on lhs and rhs have the same difference orders. - if get_difference_order(trend_variables(i)) ~= get_difference_order(v) + if get_difference_order(trend_variables(i))~=get_difference_order(trend_autoregressive_variables(i)) error('In a trend equation (%s) LHS and RHS variables must have the same difference orders!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)}) end - % Check that the trend equation is autoregressive. if isdiff(v) - if ~M_.aux_vars(get_aux_variable_id(v)).type == 9 + if ~M_.aux_vars(get_aux_variable_id(v)).type==9 error('In a trend equation (%s) RHS variable must be lagged LHS variable!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)}) else - if M_.aux_vars(get_aux_variable_id(v)).orig_index ~= trend_variables(i) + if M_.aux_vars(get_aux_variable_id(v)).orig_index~=trend_variables(i) error('In a trend equation (%s) RHS variable must be lagged LHS variable!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)}) end end else - if get_aux_variable_id(v) && M_.aux_vars(get_aux_variable_id(v)).endo_index ~= trend_variables(i) + if get_aux_variable_id(v) && M_.aux_vars(get_aux_variable_id(v)).endo_index~=trend_variables(i) error('In a trend equation (%s) RHS variable must be lagged LHS variable!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)}) end end end - % Reorder trend_eqnums_in_auxiliary_model to ensure that the order of % the trend variables matches the order of the error correction % variables. [~,reorder] = ismember(M_.trend_component.toto.lhs(trend_eqnums_in_auxiliary_model), ... - M_.trend_component.toto.trend_vars(M_.trend_component.toto.trend_vars > 0)); + M_.trend_component.toto.trend_vars(find(M_.trend_component.toto.trend_vars>0))); trend_eqnums_in_auxiliary_model = trend_eqnums_in_auxiliary_model(reorder); - % Get the EC matrix (the EC term is assumend to be in t-1). % % TODO: Check that the EC term is the difference between the % endogenous variable and the trend variable. % + A0 = oo_.trend_component.(auxiliary_model_name).ec(ecm_eqnums_in_auxiliary_model,:,1); + % Get the AR matrices. + AR = oo_.trend_component.(auxiliary_model_name).ar(ecm_eqnums_in_auxiliary_model,ecm_eqnums_in_auxiliary_model,:); % Build B matrices (VAR in levels) - B(ecm_eqnums_in_auxiliary_model, ecm_eqnums_in_auxiliary_model, 1) = eye(m) + A0 + AR(:,:,1); - B(ecm_eqnums_in_auxiliary_model, trend_eqnums_in_auxiliary_model) = -A0; - B(trend_eqnums_in_auxiliary_model, trend_eqnums_in_auxiliary_model) = eye(q); - for i = 2:p - B(ecm_eqnums_in_auxiliary_model,ecm_eqnums_in_auxiliary_model,i) = AR(:,:,i) - AR(:,:,i-1); + B(ecm_eqnums_in_auxiliary_model,ecm_eqnums_in_auxiliary_model,1) = eye(m)+A0+AR(:,:,1); + B(ecm_eqnums_in_auxiliary_model,trend_eqnums_in_auxiliary_model) = -A0; + B(trend_eqnums_in_auxiliary_model,trend_eqnums_in_auxiliary_model) = eye(q); + for i=2:p + B(ecm_eqnums_in_auxiliary_model,ecm_eqnums_in_auxiliary_model,i) = AR(:,:,i)-AR(:,:,i-1); end B(ecm_eqnums_in_auxiliary_model,ecm_eqnums_in_auxiliary_model,p+1) = -AR(:,:,p); - % Write Companion matrix oo_.trend_component.(auxiliary_model_name).CompanionMatrix = zeros(size(B, 1)*size(B, 3)); - for i = 1:p + for i=1:p oo_.trend_component.(auxiliary_model_name).CompanionMatrix(1:n, (i-1)*n+(1:n)) = B(:,:,i); oo_.trend_component.(auxiliary_model_name).CompanionMatrix(i*n+(1:n),(i-1)*n+(1:n)) = eye(n); end diff --git a/tests/Makefile.am b/tests/Makefile.am index ed28d6349..8c378f995 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -361,20 +361,21 @@ MODFILES = \ trend-component-and-var-models/vm1.mod \ trend-component-and-var-models/vm2.mod \ trend-component-and-var-models/vm3.mod \ + trend-component-and-var-models/vm4.mod \ trend-component-and-var-models/tcm1.mod \ trend-component-and-var-models/tcm2.mod \ trend-component-and-var-models/tcm3.mod \ trend-component-and-var-models/tcm4.mod \ trend-component-and-var-models/tcm5.mod \ trend-component-and-var-models/tcm6.mod \ - trend-component-and-var-models/vm1p.mod \ - trend-component-and-var-models/vm2p.mod \ - trend-component-and-var-models/vm3p.mod \ - trend-component-and-var-models/tcm1p.mod \ - trend-component-and-var-models/tcm2p.mod \ - trend-component-and-var-models/tcm3p.mod \ - trend-component-and-var-models/tcm4p.mod \ - trend-component-and-var-models/tcm5p.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 \ + trend-component-and-var-models/legacy/tcm1.mod \ + trend-component-and-var-models/legacy/tcm2.mod \ + trend-component-and-var-models/legacy/tcm3.mod \ + trend-component-and-var-models/legacy/tcm4.mod \ + trend-component-and-var-models/legacy/tcm5.mod \ pac/var-1/example.mod \ pac/var-2/example.mod \ pac/var-3/example.mod \ diff --git a/tests/trend-component-and-var-models/legacy/tcm1.mod b/tests/trend-component-and-var-models/legacy/tcm1.mod new file mode 100644 index 000000000..a85366fb3 --- /dev/null +++ b/tests/trend-component-and-var-models/legacy/tcm1.mod @@ -0,0 +1,138 @@ +var y1 y2 y3 y4; + +varexo e1 e2 e3 e4; + +parameters A111 A112 A113 A114 + A121 A122 A123 A124 + A131 A132 A133 A134 + A141 A142 A143 A144 + A211 A212 A213 A214 + A221 A222 A223 A224 + A231 A232 A233 A234 + A241 A242 A243 A244 + A311 A312 A313 A314 + A321 A322 A323 A324 + A331 A332 A333 A334 + A341 A342 A343 A344 + B11 B12 B21 B22; + +A1 = randn(4); +A2 = randn(4); +A3 = randn(4); + +A1(3:4,:) = 0; +A2(3:4,:) = 0; +A3(3:4,:) = 0; + +A1(1:2,3:4) = 0; +A2(1:2,3:4) = 0; +A3(1:2,3:4) = 0; + +A1(3:4,3:4) = eye(2); // y3 and y4 are pure random walks. + + +A111 = A1(1,1); +A112 = A1(1,2); +A113 = A1(1,3); +A114 = A1(1,4); +A121 = A1(2,1); +A122 = A1(2,2); +A123 = A1(2,3); +A124 = A1(2,4); +A131 = A1(3,1); +A132 = A1(3,2); +A133 = A1(3,3); +A134 = A1(3,4); +A141 = A1(4,1); +A142 = A1(4,2); +A143 = A1(4,3); +A144 = A1(4,4); + +A211 = A2(1,1); +A212 = A2(1,2); +A213 = A2(1,3); +A214 = A2(1,4); +A221 = A2(2,1); +A222 = A2(2,2); +A223 = A2(2,3); +A224 = A2(2,4); +A231 = A2(3,1); +A232 = A2(3,2); +A233 = A2(3,3); +A234 = A2(3,4); +A241 = A2(4,1); +A242 = A2(4,2); +A243 = A2(4,3); +A244 = A2(4,4); + +A311 = A3(1,1); +A312 = A3(1,2); +A313 = A3(1,3); +A314 = A3(1,4); +A321 = A3(2,1); +A322 = A3(2,2); +A323 = A3(2,3); +A324 = A3(2,4); +A331 = A3(3,1); +A332 = A3(3,2); +A333 = A3(3,3); +A334 = A3(3,4); +A341 = A3(4,1); +A342 = A3(4,2); +A343 = A3(4,3); +A344 = A3(4,4); + +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); + +trend_component_model(model_name=toto, eqtags=['eq:y1', 'eq:y2', 'eq:y3', 'eq:y4'], trends=['eq:y3', 'eq:y4']); + +model; + +[name='eq:y1'] +diff(y1) = B11*(y1(-1)-y3(-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; + +[EC, AR, T] = get_companion_matrix_legacy('toto'); + +if max(max(abs(EC-B)))>1e-12 + error('Error component matrix is wrong.') +end + +A1fake = oo_.trend_component.toto.ar(:,:,1); +A1fake(1:2,3:4) = .0; + +if max(max(abs(A1fake-A1)))>1e-12 + error('First order autoregressive matrix is wrong.') +end + +if max(max(abs(oo_.trend_component.toto.ar(:,:,2)-A2)))>1e-12 + error('Second order autoregressive matrix is wrong.') +end + +if max(max(abs(oo_.trend_component.toto.ar(:,:,3)-A3)))>1e-12 + error('Third order autoregressive matrix is wrong.') +end \ No newline at end of file diff --git a/tests/trend-component-and-var-models/legacy/tcm2.mod b/tests/trend-component-and-var-models/legacy/tcm2.mod new file mode 100644 index 000000000..15c1c2f14 --- /dev/null +++ b/tests/trend-component-and-var-models/legacy/tcm2.mod @@ -0,0 +1,135 @@ +var y1 y2 y3 y4; + +varexo e1 e2 e3 e4; + +parameters A111 A112 A113 A114 + A121 A122 A123 A124 + A131 A132 A133 A134 + A141 A142 A143 A144 + A211 A212 A213 A214 + A221 A222 A223 A224 + A231 A232 A233 A234 + A241 A242 A243 A244 + A311 A312 A313 A314 + A321 A322 A323 A324 + A331 A332 A333 A334 + A341 A342 A343 A344 + B11 B12 B21 B22; + +A1 = randn(4); +A2 = randn(4); +A3 = randn(4); + +A1(3:4,:) = 0; +A2(3:4,:) = 0; +A3(3:4,:) = 0; + +A1(1:2,3:4) = 0; +A2(1:2,3:4) = 0; +A3(1:2,3:4) = 0; + +A1(3:4,3:4) = eye(2); // y3 and y4 are pure random walks. + + +A111 = A1(1,1); +A112 = A1(1,2); +A113 = A1(1,3); +A114 = A1(1,4); +A121 = A1(2,1); +A122 = A1(2,2); +A123 = A1(2,3); +A124 = A1(2,4); +A131 = A1(3,1); +A132 = A1(3,2); +A133 = A1(3,3); +A134 = A1(3,4); +A141 = A1(4,1); +A142 = A1(4,2); +A143 = A1(4,3); +A144 = A1(4,4); + +A211 = A2(1,1); +A212 = A2(1,2); +A213 = A2(1,3); +A214 = A2(1,4); +A221 = A2(2,1); +A222 = A2(2,2); +A223 = A2(2,3); +A224 = A2(2,4); +A231 = A2(3,1); +A232 = A2(3,2); +A233 = A2(3,3); +A234 = A2(3,4); +A241 = A2(4,1); +A242 = A2(4,2); +A243 = A2(4,3); +A244 = A2(4,4); + +A311 = A3(1,1); +A312 = A3(1,2); +A313 = A3(1,3); +A314 = A3(1,4); +A321 = A3(2,1); +A322 = A3(2,2); +A323 = A3(2,3); +A324 = A3(2,4); +A331 = A3(3,1); +A332 = A3(3,2); +A333 = A3(3,3); +A334 = A3(3,4); +A341 = A3(4,1); +A342 = A3(4,2); +A343 = A3(4,3); +A344 = A3(4,4); + +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); + +trend_component_model(model_name=toto, eqtags=['eq:y1', 'eq:y4', 'eq:y2', 'eq:y3'], trends=['eq:y3', 'eq:y4']); + +model; + +[name='eq:y1'] +diff(y1) = B11*(y1(-1)-y3(-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; + +[EC, AR, T] = get_companion_matrix_legacy('toto'); + +if max(max(abs(EC-B)))>1e-12 + error('Error component matrix is wrong.') +end + +if max(max(abs(AR(:,:,1)-A1(1:2,1:2))))>1e-12 + error('First order autoregressive matrix is wrong.') +end + +if max(max(abs(AR(:,:,2)-A2(1:2,1:2))))>1e-12 + error('Second order autoregressive matrix is wrong.') +end + +if max(max(abs(AR(:,:,3)-A3(1:2,1:2))))>1e-12 + error('Third order autoregressive matrix is wrong.') +end \ No newline at end of file diff --git a/tests/trend-component-and-var-models/legacy/tcm3.mod b/tests/trend-component-and-var-models/legacy/tcm3.mod new file mode 100644 index 000000000..c81bf65bf --- /dev/null +++ b/tests/trend-component-and-var-models/legacy/tcm3.mod @@ -0,0 +1,135 @@ +var y1 y2 y3 y4; + +varexo e1 e2 e3 e4; + +parameters A111 A112 A113 A114 + A121 A122 A123 A124 + A131 A132 A133 A134 + A141 A142 A143 A144 + A211 A212 A213 A214 + A221 A222 A223 A224 + A231 A232 A233 A234 + A241 A242 A243 A244 + A311 A312 A313 A314 + A321 A322 A323 A324 + A331 A332 A333 A334 + A341 A342 A343 A344 + B11 B12 B21 B22; + +A1 = randn(4); +A2 = randn(4); +A3 = randn(4); + +A1(3:4,:) = 0; +A2(3:4,:) = 0; +A3(3:4,:) = 0; + +A1(1:2,3:4) = 0; +A2(1:2,3:4) = 0; +A3(1:2,3:4) = 0; + +A1(3:4,3:4) = eye(2); // y3 and y4 are pure random walks. + + +A111 = A1(1,1); +A112 = A1(1,2); +A113 = A1(1,3); +A114 = A1(1,4); +A121 = A1(2,1); +A122 = A1(2,2); +A123 = A1(2,3); +A124 = A1(2,4); +A131 = A1(3,1); +A132 = A1(3,2); +A133 = A1(3,3); +A134 = A1(3,4); +A141 = A1(4,1); +A142 = A1(4,2); +A143 = A1(4,3); +A144 = A1(4,4); + +A211 = A2(1,1); +A212 = A2(1,2); +A213 = A2(1,3); +A214 = A2(1,4); +A221 = A2(2,1); +A222 = A2(2,2); +A223 = A2(2,3); +A224 = A2(2,4); +A231 = A2(3,1); +A232 = A2(3,2); +A233 = A2(3,3); +A234 = A2(3,4); +A241 = A2(4,1); +A242 = A2(4,2); +A243 = A2(4,3); +A244 = A2(4,4); + +A311 = A3(1,1); +A312 = A3(1,2); +A313 = A3(1,3); +A314 = A3(1,4); +A321 = A3(2,1); +A322 = A3(2,2); +A323 = A3(2,3); +A324 = A3(2,4); +A331 = A3(3,1); +A332 = A3(3,2); +A333 = A3(3,3); +A334 = A3(3,4); +A341 = A3(4,1); +A342 = A3(4,2); +A343 = A3(4,3); +A344 = A3(4,4); + +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); + +trend_component_model(model_name=toto, eqtags=['eq:y1', 'eq:y2', 'eq:y3', 'eq:y4'], trends=['eq:y4', 'eq:y3']); + +model; + +[name='eq:y1'] +diff(y1) = B11*(y1(-1)-y3(-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; + +[EC, AR, T] = get_companion_matrix_legacy('toto'); + +if max(max(abs(EC-B)))>1e-12 + error('Error component matrix is wrong.') +end + +if max(max(abs(AR(:,:,1)-A1(1:2,1:2))))>1e-12 + error('First order autoregressive matrix is wrong.') +end + +if max(max(abs(AR(:,:,2)-A2(1:2,1:2))))>1e-12 + error('Second order autoregressive matrix is wrong.') +end + +if max(max(abs(AR(:,:,3)-A3(1:2,1:2))))>1e-12 + error('Third order autoregressive matrix is wrong.') +end \ No newline at end of file diff --git a/tests/trend-component-and-var-models/legacy/tcm4.mod b/tests/trend-component-and-var-models/legacy/tcm4.mod new file mode 100644 index 000000000..ba848f0f8 --- /dev/null +++ b/tests/trend-component-and-var-models/legacy/tcm4.mod @@ -0,0 +1,136 @@ +var y1 y2 y3 y4; + +varexo e1 e2 e3 e4; + +parameters A111 A112 A113 A114 + A121 A122 A123 A124 + A131 A132 A133 A134 + A141 A142 A143 A144 + A211 A212 A213 A214 + A221 A222 A223 A224 + A231 A232 A233 A234 + A241 A242 A243 A244 + A311 A312 A313 A314 + A321 A322 A323 A324 + A331 A332 A333 A334 + A341 A342 A343 A344 + B11 B12 B21 B22; + +A1 = randn(4); +A2 = randn(4); +A3 = randn(4); + +A1(3:4,:) = 0; +A2(3:4,:) = 0; +A3(3:4,:) = 0; + +A1(1:2,3:4) = 0; +A2(1:2,3:4) = 0; +A3(1:2,3:4) = 0; + +A1(3:4,3:4) = eye(2); // y3 and y4 are pure random walks. + + +A111 = A1(1,1); +A112 = A1(1,2); +A113 = A1(1,3); +A114 = A1(1,4); +A121 = A1(2,1); +A122 = A1(2,2); +A123 = A1(2,3); +A124 = A1(2,4); +A131 = A1(3,1); +A132 = A1(3,2); +A133 = A1(3,3); +A134 = A1(3,4); +A141 = A1(4,1); +A142 = A1(4,2); +A143 = A1(4,3); +A144 = A1(4,4); + +A211 = A2(1,1); +A212 = A2(1,2); +A213 = A2(1,3); +A214 = A2(1,4); +A221 = A2(2,1); +A222 = A2(2,2); +A223 = A2(2,3); +A224 = A2(2,4); +A231 = A2(3,1); +A232 = A2(3,2); +A233 = A2(3,3); +A234 = A2(3,4); +A241 = A2(4,1); +A242 = A2(4,2); +A243 = A2(4,3); +A244 = A2(4,4); + +A311 = A3(1,1); +A312 = A3(1,2); +A313 = A3(1,3); +A314 = A3(1,4); +A321 = A3(2,1); +A322 = A3(2,2); +A323 = A3(2,3); +A324 = A3(2,4); +A331 = A3(3,1); +A332 = A3(3,2); +A333 = A3(3,3); +A334 = A3(3,4); +A341 = A3(4,1); +A342 = A3(4,2); +A343 = A3(4,3); +A344 = A3(4,4); + +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); + +trend_component_model(model_name=toto, eqtags=['eq:y1', 'eq:y2', 'eq:y3', 'eq:y4'], trends=['eq:y3', 'eq:y4']); + +model; + +[name='eq:y1'] +diff(y1) = B11*(y1(-1)-y3(-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:y4'] +y4 = y4(-1) + e4; + + +[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; + +end; + +[EC, AR, T] = get_companion_matrix_legacy('toto'); + +if max(max(abs(EC-B)))>1e-12 + error('Error component matrix is wrong.') +end + +if max(max(abs(AR(:,:,1)-A1(1:2,1:2))))>1e-12 + error('First order autoregressive matrix is wrong.') +end + +if max(max(abs(AR(:,:,2)-A2(1:2,1:2))))>1e-12 + error('Second order autoregressive matrix is wrong.') +end + +if max(max(abs(AR(:,:,3)-A3(1:2,1:2))))>1e-12 + error('Third order autoregressive matrix is wrong.') +end \ No newline at end of file diff --git a/tests/trend-component-and-var-models/legacy/tcm5.mod b/tests/trend-component-and-var-models/legacy/tcm5.mod new file mode 100644 index 000000000..b972f08ab --- /dev/null +++ b/tests/trend-component-and-var-models/legacy/tcm5.mod @@ -0,0 +1,136 @@ +var y1 y2 y3 y4; + +varexo e1 e2 e3 e4; + +parameters A111 A112 A113 A114 + A121 A122 A123 A124 + A131 A132 A133 A134 + A141 A142 A143 A144 + A211 A212 A213 A214 + A221 A222 A223 A224 + A231 A232 A233 A234 + A241 A242 A243 A244 + A311 A312 A313 A314 + A321 A322 A323 A324 + A331 A332 A333 A334 + A341 A342 A343 A344 + B11 B12 B21 B22; + +A1 = randn(4); +A2 = randn(4); +A3 = randn(4); + +A1(3:4,:) = 0; +A2(3:4,:) = 0; +A3(3:4,:) = 0; + +A1(1:2,3:4) = 0; +A2(1:2,3:4) = 0; +A3(1:2,3:4) = 0; + +A1(3:4,3:4) = eye(2); // y3 and y4 are pure random walks. + + +A111 = A1(1,1); +A112 = A1(1,2); +A113 = A1(1,3); +A114 = A1(1,4); +A121 = A1(2,1); +A122 = A1(2,2); +A123 = A1(2,3); +A124 = A1(2,4); +A131 = A1(3,1); +A132 = A1(3,2); +A133 = A1(3,3); +A134 = A1(3,4); +A141 = A1(4,1); +A142 = A1(4,2); +A143 = A1(4,3); +A144 = A1(4,4); + +A211 = A2(1,1); +A212 = A2(1,2); +A213 = A2(1,3); +A214 = A2(1,4); +A221 = A2(2,1); +A222 = A2(2,2); +A223 = A2(2,3); +A224 = A2(2,4); +A231 = A2(3,1); +A232 = A2(3,2); +A233 = A2(3,3); +A234 = A2(3,4); +A241 = A2(4,1); +A242 = A2(4,2); +A243 = A2(4,3); +A244 = A2(4,4); + +A311 = A3(1,1); +A312 = A3(1,2); +A313 = A3(1,3); +A314 = A3(1,4); +A321 = A3(2,1); +A322 = A3(2,2); +A323 = A3(2,3); +A324 = A3(2,4); +A331 = A3(3,1); +A332 = A3(3,2); +A333 = A3(3,3); +A334 = A3(3,4); +A341 = A3(4,1); +A342 = A3(4,2); +A343 = A3(4,3); +A344 = A3(4,4); + +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); + +trend_component_model(model_name=toto, eqtags=['eq:y4', 'eq:y1', 'eq:y2', 'eq:y3'], trends=['eq:y3', 'eq:y4']); + +model; + +[name='eq:y1'] +diff(y1) = B11*(y1(-1)-y3(-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:y4'] +y4 = y4(-1) + e4; + + +[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; + +end; + +[EC, AR, T] = get_companion_matrix_legacy('toto'); + +if max(max(abs(EC-B)))>1e-12 + error('Error component matrix is wrong.') +end + +if max(max(abs(AR(:,:,1)-A1(1:2,1:2))))>1e-12 + error('First order autoregressive matrix is wrong.') +end + +if max(max(abs(AR(:,:,2)-A2(1:2,1:2))))>1e-12 + error('Second order autoregressive matrix is wrong.') +end + +if max(max(abs(AR(:,:,3)-A3(1:2,1:2))))>1e-12 + error('Third order autoregressive matrix is wrong.') +end \ No newline at end of file diff --git a/tests/trend-component-and-var-models/vm1p.mod b/tests/trend-component-and-var-models/legacy/vm1.mod similarity index 93% rename from tests/trend-component-and-var-models/vm1p.mod rename to tests/trend-component-and-var-models/legacy/vm1.mod index d78641753..1869e3a05 100644 --- a/tests/trend-component-and-var-models/vm1p.mod +++ b/tests/trend-component-and-var-models/legacy/vm1.mod @@ -96,17 +96,17 @@ y4 = A141*y1(-1) + A142*y2(-1) + A143*y3(-1) + A144*y4(-1) + end; -[A0, AR, B] = get_companion_matrix_preprocessor('toto'); +get_companion_matrix_legacy('toto'); -if max(max(abs(AR(:,:,1)-A1)))>1e-12 +if max(max(abs(oo_.var.toto.ar(:,:,1)-A1)))>1e-12 error('First order autoregressive matrix is wrong.') end -if max(max(abs(AR(:,:,2)-A2)))>1e-12 +if max(max(abs(oo_.var.toto.ar(:,:,2)-A2)))>1e-12 error('Second order autoregressive matrix is wrong.') end -if max(max(abs(AR(:,:,3)-A3)))>1e-12 +if max(max(abs(oo_.var.toto.ar(:,:,3)-A3)))>1e-12 error('Third order autoregressive matrix is wrong.') end @@ -116,4 +116,4 @@ CompanionMatrix = [A1, A2, A3; if max(max(abs(CompanionMatrix-oo_.var.toto.CompanionMatrix)))>1e-12 error('Companion matrix is wrong.') -end +end \ No newline at end of file diff --git a/tests/trend-component-and-var-models/vm2p.mod b/tests/trend-component-and-var-models/legacy/vm2.mod similarity index 93% rename from tests/trend-component-and-var-models/vm2p.mod rename to tests/trend-component-and-var-models/legacy/vm2.mod index 6fe6d18ae..a241b9290 100644 --- a/tests/trend-component-and-var-models/vm2p.mod +++ b/tests/trend-component-and-var-models/legacy/vm2.mod @@ -96,17 +96,17 @@ y4 = A141*y1(-1) + A142*y2(-1) + A143*y3(-1) + A144*y4(-1) + end; -[A0, AR, B] = get_companion_matrix_preprocessor('toto'); +get_companion_matrix_legacy('toto'); -if max(max(abs(AR(:,:,1)-A1)))>1e-12 +if max(max(abs(oo_.var.toto.ar(:,:,1)-A1)))>1e-12 error('First order autoregressive matrix is wrong.') end -if max(max(abs(AR(:,:,2)-A2)))>1e-12 +if max(max(abs(oo_.var.toto.ar(:,:,2)-A2)))>1e-12 error('Second order autoregressive matrix is wrong.') end -if max(max(abs(AR(:,:,3)-A3)))>1e-12 +if max(max(abs(oo_.var.toto.ar(:,:,3)-A3)))>1e-12 error('Third order autoregressive matrix is wrong.') end @@ -116,4 +116,4 @@ CompanionMatrix = [A1, A2, A3; if max(max(abs(CompanionMatrix-oo_.var.toto.CompanionMatrix)))>1e-12 error('Companion matrix is wrong.') -end +end \ No newline at end of file diff --git a/tests/trend-component-and-var-models/vm3p.mod b/tests/trend-component-and-var-models/legacy/vm3.mod similarity index 93% rename from tests/trend-component-and-var-models/vm3p.mod rename to tests/trend-component-and-var-models/legacy/vm3.mod index 53667744c..0585f78a9 100644 --- a/tests/trend-component-and-var-models/vm3p.mod +++ b/tests/trend-component-and-var-models/legacy/vm3.mod @@ -96,17 +96,17 @@ y1 = A111*y1(-1) + A112*y2(-1) + A113*y3(-1) + A114*y4(-1) + end; -[A0, AR, B] = get_companion_matrix_preprocessor('toto'); +get_companion_matrix_legacy('toto'); -if max(max(abs(AR(:,:,1)-A1)))>1e-12 +if max(max(abs(oo_.var.toto.ar(:,:,1)-A1)))>1e-12 error('First order autoregressive matrix is wrong.') end -if max(max(abs(AR(:,:,2)-A2)))>1e-12 +if max(max(abs(oo_.var.toto.ar(:,:,2)-A2)))>1e-12 error('Second order autoregressive matrix is wrong.') end -if max(max(abs(AR(:,:,3)-A3)))>1e-12 +if max(max(abs(oo_.var.toto.ar(:,:,3)-A3)))>1e-12 error('Third order autoregressive matrix is wrong.') end @@ -116,4 +116,4 @@ CompanionMatrix = [A1, A2, A3; if max(max(abs(CompanionMatrix-oo_.var.toto.CompanionMatrix)))>1e-12 error('Companion matrix is wrong.') -end +end \ No newline at end of file diff --git a/tests/trend-component-and-var-models/tcm1.mod b/tests/trend-component-and-var-models/tcm1.mod index 3805207e9..dfec6aff4 100644 --- a/tests/trend-component-and-var-models/tcm1.mod +++ b/tests/trend-component-and-var-models/tcm1.mod @@ -2,85 +2,32 @@ var y1 y2 y3 y4; varexo e1 e2 e3 e4; -parameters A111 A112 A113 A114 - A121 A122 A123 A124 - A131 A132 A133 A134 - A141 A142 A143 A144 - A211 A212 A213 A214 - A221 A222 A223 A224 - A231 A232 A233 A234 - A241 A242 A243 A244 - A311 A312 A313 A314 - A321 A322 A323 A324 - A331 A332 A333 A334 - A341 A342 A343 A344 +parameters A111 A112 + A121 A122 + A211 A212 + A221 A222 + A311 A312 + A321 A322 B11 B12 B21 B22; -A1 = randn(4); -A2 = randn(4); -A3 = randn(4); - -A1(3:4,:) = 0; -A2(3:4,:) = 0; -A3(3:4,:) = 0; - -A1(1:2,3:4) = 0; -A2(1:2,3:4) = 0; -A3(1:2,3:4) = 0; - -A1(3:4,3:4) = eye(2); // y3 and y4 are pure random walks. - +A1 = randn(2); +A2 = randn(2); +A3 = randn(2); A111 = A1(1,1); A112 = A1(1,2); -A113 = A1(1,3); -A114 = A1(1,4); A121 = A1(2,1); A122 = A1(2,2); -A123 = A1(2,3); -A124 = A1(2,4); -A131 = A1(3,1); -A132 = A1(3,2); -A133 = A1(3,3); -A134 = A1(3,4); -A141 = A1(4,1); -A142 = A1(4,2); -A143 = A1(4,3); -A144 = A1(4,4); A211 = A2(1,1); A212 = A2(1,2); -A213 = A2(1,3); -A214 = A2(1,4); A221 = A2(2,1); A222 = A2(2,2); -A223 = A2(2,3); -A224 = A2(2,4); -A231 = A2(3,1); -A232 = A2(3,2); -A233 = A2(3,3); -A234 = A2(3,4); -A241 = A2(4,1); -A242 = A2(4,2); -A243 = A2(4,3); -A244 = A2(4,4); A311 = A3(1,1); A312 = A3(1,2); -A313 = A3(1,3); -A314 = A3(1,4); A321 = A3(2,1); A322 = A3(2,2); -A323 = A3(2,3); -A324 = A3(2,4); -A331 = A3(3,1); -A332 = A3(3,2); -A333 = A3(3,3); -A334 = A3(3,4); -A341 = A3(4,1); -A342 = A3(4,2); -A343 = A3(4,3); -A344 = A3(4,4); B = rand(2); B(1,1) = -B(1,1); @@ -122,17 +69,16 @@ if max(max(abs(EC-B)))>1e-12 error('Error component matrix is wrong.') end -A1fake = oo_.trend_component.toto.ar(:,:,1); -A1fake(1:2,3:4) = .0; +A1fake = AR(:,:,1); if max(max(abs(A1fake-A1)))>1e-12 error('First order autoregressive matrix is wrong.') end -if max(max(abs(oo_.trend_component.toto.ar(:,:,2)-A2)))>1e-12 +if max(max(abs(AR(:,:,2)-A2)))>1e-12 error('Second order autoregressive matrix is wrong.') end -if max(max(abs(oo_.trend_component.toto.ar(:,:,3)-A3)))>1e-12 +if max(max(abs(AR(:,:,3)-A3)))>1e-12 error('Third order autoregressive matrix is wrong.') -end \ No newline at end of file +end diff --git a/tests/trend-component-and-var-models/tcm1p.mod b/tests/trend-component-and-var-models/tcm1p.mod deleted file mode 100644 index 4ad46cfe5..000000000 --- a/tests/trend-component-and-var-models/tcm1p.mod +++ /dev/null @@ -1,84 +0,0 @@ -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); - -trend_component_model(model_name=toto, eqtags=['eq:y1', 'eq:y2', 'eq:y3', 'eq:y4'], trends=['eq:y3', 'eq:y4']); - -model; - -[name='eq:y1'] -diff(y1) = B11*(y1(-1)-y3(-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; - -[EC, AR, T] = get_companion_matrix_preprocessor('toto'); - -if max(max(abs(EC-B)))>1e-12 - error('Error component matrix 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 diff --git a/tests/trend-component-and-var-models/tcm2.mod b/tests/trend-component-and-var-models/tcm2.mod index c9f12d810..f0d700cd1 100644 --- a/tests/trend-component-and-var-models/tcm2.mod +++ b/tests/trend-component-and-var-models/tcm2.mod @@ -2,85 +2,32 @@ var y1 y2 y3 y4; varexo e1 e2 e3 e4; -parameters A111 A112 A113 A114 - A121 A122 A123 A124 - A131 A132 A133 A134 - A141 A142 A143 A144 - A211 A212 A213 A214 - A221 A222 A223 A224 - A231 A232 A233 A234 - A241 A242 A243 A244 - A311 A312 A313 A314 - A321 A322 A323 A324 - A331 A332 A333 A334 - A341 A342 A343 A344 +parameters A111 A112 + A121 A122 + A211 A212 + A221 A222 + A311 A312 + A321 A322 B11 B12 B21 B22; -A1 = randn(4); -A2 = randn(4); -A3 = randn(4); - -A1(3:4,:) = 0; -A2(3:4,:) = 0; -A3(3:4,:) = 0; - -A1(1:2,3:4) = 0; -A2(1:2,3:4) = 0; -A3(1:2,3:4) = 0; - -A1(3:4,3:4) = eye(2); // y3 and y4 are pure random walks. - +A1 = randn(2); +A2 = randn(2); +A3 = randn(2); A111 = A1(1,1); A112 = A1(1,2); -A113 = A1(1,3); -A114 = A1(1,4); A121 = A1(2,1); A122 = A1(2,2); -A123 = A1(2,3); -A124 = A1(2,4); -A131 = A1(3,1); -A132 = A1(3,2); -A133 = A1(3,3); -A134 = A1(3,4); -A141 = A1(4,1); -A142 = A1(4,2); -A143 = A1(4,3); -A144 = A1(4,4); A211 = A2(1,1); A212 = A2(1,2); -A213 = A2(1,3); -A214 = A2(1,4); A221 = A2(2,1); A222 = A2(2,2); -A223 = A2(2,3); -A224 = A2(2,4); -A231 = A2(3,1); -A232 = A2(3,2); -A233 = A2(3,3); -A234 = A2(3,4); -A241 = A2(4,1); -A242 = A2(4,2); -A243 = A2(4,3); -A244 = A2(4,4); A311 = A3(1,1); A312 = A3(1,2); -A313 = A3(1,3); -A314 = A3(1,4); A321 = A3(2,1); A322 = A3(2,2); -A323 = A3(2,3); -A324 = A3(2,4); -A331 = A3(3,1); -A332 = A3(3,2); -A333 = A3(3,3); -A334 = A3(3,4); -A341 = A3(4,1); -A342 = A3(4,2); -A343 = A3(4,3); -A344 = A3(4,4); B = rand(2); B(1,1) = -B(1,1); @@ -122,14 +69,16 @@ if max(max(abs(EC-B)))>1e-12 error('Error component matrix is wrong.') end -if max(max(abs(AR(:,:,1)-A1(1:2,1:2))))>1e-12 +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(1:2,1:2))))>1e-12 +if max(max(abs(AR(:,:,2)-A2)))>1e-12 error('Second order autoregressive matrix is wrong.') end -if max(max(abs(AR(:,:,3)-A3(1:2,1:2))))>1e-12 +if max(max(abs(AR(:,:,3)-A3)))>1e-12 error('Third order autoregressive matrix is wrong.') -end \ No newline at end of file +end diff --git a/tests/trend-component-and-var-models/tcm2p.mod b/tests/trend-component-and-var-models/tcm2p.mod deleted file mode 100644 index db7b91263..000000000 --- a/tests/trend-component-and-var-models/tcm2p.mod +++ /dev/null @@ -1,84 +0,0 @@ -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); - -trend_component_model(model_name=toto, eqtags=['eq:y1', 'eq:y4', 'eq:y2', 'eq:y3'], trends=['eq:y3', 'eq:y4']); - -model; - -[name='eq:y1'] -diff(y1) = B11*(y1(-1)-y3(-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; - -[EC, AR, T] = get_companion_matrix_preprocessor('toto'); - -if max(max(abs(EC-B)))>1e-12 - error('Error component matrix 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 diff --git a/tests/trend-component-and-var-models/tcm3.mod b/tests/trend-component-and-var-models/tcm3.mod index 05dbd7c39..470aa9390 100644 --- a/tests/trend-component-and-var-models/tcm3.mod +++ b/tests/trend-component-and-var-models/tcm3.mod @@ -2,85 +2,32 @@ var y1 y2 y3 y4; varexo e1 e2 e3 e4; -parameters A111 A112 A113 A114 - A121 A122 A123 A124 - A131 A132 A133 A134 - A141 A142 A143 A144 - A211 A212 A213 A214 - A221 A222 A223 A224 - A231 A232 A233 A234 - A241 A242 A243 A244 - A311 A312 A313 A314 - A321 A322 A323 A324 - A331 A332 A333 A334 - A341 A342 A343 A344 +parameters A111 A112 + A121 A122 + A211 A212 + A221 A222 + A311 A312 + A321 A322 B11 B12 B21 B22; -A1 = randn(4); -A2 = randn(4); -A3 = randn(4); - -A1(3:4,:) = 0; -A2(3:4,:) = 0; -A3(3:4,:) = 0; - -A1(1:2,3:4) = 0; -A2(1:2,3:4) = 0; -A3(1:2,3:4) = 0; - -A1(3:4,3:4) = eye(2); // y3 and y4 are pure random walks. - +A1 = randn(2); +A2 = randn(2); +A3 = randn(2); A111 = A1(1,1); A112 = A1(1,2); -A113 = A1(1,3); -A114 = A1(1,4); A121 = A1(2,1); A122 = A1(2,2); -A123 = A1(2,3); -A124 = A1(2,4); -A131 = A1(3,1); -A132 = A1(3,2); -A133 = A1(3,3); -A134 = A1(3,4); -A141 = A1(4,1); -A142 = A1(4,2); -A143 = A1(4,3); -A144 = A1(4,4); A211 = A2(1,1); A212 = A2(1,2); -A213 = A2(1,3); -A214 = A2(1,4); A221 = A2(2,1); A222 = A2(2,2); -A223 = A2(2,3); -A224 = A2(2,4); -A231 = A2(3,1); -A232 = A2(3,2); -A233 = A2(3,3); -A234 = A2(3,4); -A241 = A2(4,1); -A242 = A2(4,2); -A243 = A2(4,3); -A244 = A2(4,4); A311 = A3(1,1); A312 = A3(1,2); -A313 = A3(1,3); -A314 = A3(1,4); A321 = A3(2,1); A322 = A3(2,2); -A323 = A3(2,3); -A324 = A3(2,4); -A331 = A3(3,1); -A332 = A3(3,2); -A333 = A3(3,3); -A334 = A3(3,4); -A341 = A3(4,1); -A342 = A3(4,2); -A343 = A3(4,3); -A344 = A3(4,4); B = rand(2); B(1,1) = -B(1,1); @@ -122,14 +69,16 @@ if max(max(abs(EC-B)))>1e-12 error('Error component matrix is wrong.') end -if max(max(abs(AR(:,:,1)-A1(1:2,1:2))))>1e-12 +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(1:2,1:2))))>1e-12 +if max(max(abs(AR(:,:,2)-A2)))>1e-12 error('Second order autoregressive matrix is wrong.') end -if max(max(abs(AR(:,:,3)-A3(1:2,1:2))))>1e-12 +if max(max(abs(AR(:,:,3)-A3)))>1e-12 error('Third order autoregressive matrix is wrong.') -end \ No newline at end of file +end diff --git a/tests/trend-component-and-var-models/tcm3p.mod b/tests/trend-component-and-var-models/tcm3p.mod deleted file mode 100644 index 8376a48ae..000000000 --- a/tests/trend-component-and-var-models/tcm3p.mod +++ /dev/null @@ -1,84 +0,0 @@ -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); - -trend_component_model(model_name=toto, eqtags=['eq:y1', 'eq:y2', 'eq:y3', 'eq:y4'], trends=['eq:y4', 'eq:y3']); - -model; - -[name='eq:y1'] -diff(y1) = B11*(y1(-1)-y3(-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; - -[EC, AR, T] = get_companion_matrix_preprocessor('toto'); - -if max(max(abs(EC-B)))>1e-12 - error('Error component matrix 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 diff --git a/tests/trend-component-and-var-models/tcm4.mod b/tests/trend-component-and-var-models/tcm4.mod index 691c1f5fe..2d99b8bcf 100644 --- a/tests/trend-component-and-var-models/tcm4.mod +++ b/tests/trend-component-and-var-models/tcm4.mod @@ -2,85 +2,32 @@ var y1 y2 y3 y4; varexo e1 e2 e3 e4; -parameters A111 A112 A113 A114 - A121 A122 A123 A124 - A131 A132 A133 A134 - A141 A142 A143 A144 - A211 A212 A213 A214 - A221 A222 A223 A224 - A231 A232 A233 A234 - A241 A242 A243 A244 - A311 A312 A313 A314 - A321 A322 A323 A324 - A331 A332 A333 A334 - A341 A342 A343 A344 +parameters A111 A112 + A121 A122 + A211 A212 + A221 A222 + A311 A312 + A321 A322 B11 B12 B21 B22; -A1 = randn(4); -A2 = randn(4); -A3 = randn(4); - -A1(3:4,:) = 0; -A2(3:4,:) = 0; -A3(3:4,:) = 0; - -A1(1:2,3:4) = 0; -A2(1:2,3:4) = 0; -A3(1:2,3:4) = 0; - -A1(3:4,3:4) = eye(2); // y3 and y4 are pure random walks. - +A1 = randn(2); +A2 = randn(2); +A3 = randn(2); A111 = A1(1,1); A112 = A1(1,2); -A113 = A1(1,3); -A114 = A1(1,4); A121 = A1(2,1); A122 = A1(2,2); -A123 = A1(2,3); -A124 = A1(2,4); -A131 = A1(3,1); -A132 = A1(3,2); -A133 = A1(3,3); -A134 = A1(3,4); -A141 = A1(4,1); -A142 = A1(4,2); -A143 = A1(4,3); -A144 = A1(4,4); A211 = A2(1,1); A212 = A2(1,2); -A213 = A2(1,3); -A214 = A2(1,4); A221 = A2(2,1); A222 = A2(2,2); -A223 = A2(2,3); -A224 = A2(2,4); -A231 = A2(3,1); -A232 = A2(3,2); -A233 = A2(3,3); -A234 = A2(3,4); -A241 = A2(4,1); -A242 = A2(4,2); -A243 = A2(4,3); -A244 = A2(4,4); A311 = A3(1,1); A312 = A3(1,2); -A313 = A3(1,3); -A314 = A3(1,4); A321 = A3(2,1); A322 = A3(2,2); -A323 = A3(2,3); -A324 = A3(2,4); -A331 = A3(3,1); -A332 = A3(3,2); -A333 = A3(3,3); -A334 = A3(3,4); -A341 = A3(4,1); -A342 = A3(4,2); -A343 = A3(4,3); -A344 = A3(4,4); B = rand(2); B(1,1) = -B(1,1); @@ -123,14 +70,16 @@ if max(max(abs(EC-B)))>1e-12 error('Error component matrix is wrong.') end -if max(max(abs(AR(:,:,1)-A1(1:2,1:2))))>1e-12 +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(1:2,1:2))))>1e-12 +if max(max(abs(AR(:,:,2)-A2)))>1e-12 error('Second order autoregressive matrix is wrong.') end -if max(max(abs(AR(:,:,3)-A3(1:2,1:2))))>1e-12 +if max(max(abs(AR(:,:,3)-A3)))>1e-12 error('Third order autoregressive matrix is wrong.') -end \ No newline at end of file +end diff --git a/tests/trend-component-and-var-models/tcm4p.mod b/tests/trend-component-and-var-models/tcm4p.mod deleted file mode 100644 index ea911c275..000000000 --- a/tests/trend-component-and-var-models/tcm4p.mod +++ /dev/null @@ -1,85 +0,0 @@ -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); - -trend_component_model(model_name=toto, eqtags=['eq:y1', 'eq:y2', 'eq:y3', 'eq:y4'], trends=['eq:y3', 'eq:y4']); - -model; - -[name='eq:y1'] -diff(y1) = B11*(y1(-1)-y3(-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:y4'] -y4 = y4(-1) + e4; - - -[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; - -end; - -[EC, AR, T] = get_companion_matrix_preprocessor('toto'); - -if max(max(abs(EC-B)))>1e-12 - error('Error component matrix 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 diff --git a/tests/trend-component-and-var-models/tcm5.mod b/tests/trend-component-and-var-models/tcm5.mod index 9dc1ebe5d..810267da5 100644 --- a/tests/trend-component-and-var-models/tcm5.mod +++ b/tests/trend-component-and-var-models/tcm5.mod @@ -2,85 +2,32 @@ var y1 y2 y3 y4; varexo e1 e2 e3 e4; -parameters A111 A112 A113 A114 - A121 A122 A123 A124 - A131 A132 A133 A134 - A141 A142 A143 A144 - A211 A212 A213 A214 - A221 A222 A223 A224 - A231 A232 A233 A234 - A241 A242 A243 A244 - A311 A312 A313 A314 - A321 A322 A323 A324 - A331 A332 A333 A334 - A341 A342 A343 A344 +parameters A111 A112 + A121 A122 + A211 A212 + A221 A222 + A311 A312 + A321 A322 B11 B12 B21 B22; -A1 = randn(4); -A2 = randn(4); -A3 = randn(4); - -A1(3:4,:) = 0; -A2(3:4,:) = 0; -A3(3:4,:) = 0; - -A1(1:2,3:4) = 0; -A2(1:2,3:4) = 0; -A3(1:2,3:4) = 0; - -A1(3:4,3:4) = eye(2); // y3 and y4 are pure random walks. - +A1 = randn(2); +A2 = randn(2); +A3 = randn(2); A111 = A1(1,1); A112 = A1(1,2); -A113 = A1(1,3); -A114 = A1(1,4); A121 = A1(2,1); A122 = A1(2,2); -A123 = A1(2,3); -A124 = A1(2,4); -A131 = A1(3,1); -A132 = A1(3,2); -A133 = A1(3,3); -A134 = A1(3,4); -A141 = A1(4,1); -A142 = A1(4,2); -A143 = A1(4,3); -A144 = A1(4,4); A211 = A2(1,1); A212 = A2(1,2); -A213 = A2(1,3); -A214 = A2(1,4); A221 = A2(2,1); A222 = A2(2,2); -A223 = A2(2,3); -A224 = A2(2,4); -A231 = A2(3,1); -A232 = A2(3,2); -A233 = A2(3,3); -A234 = A2(3,4); -A241 = A2(4,1); -A242 = A2(4,2); -A243 = A2(4,3); -A244 = A2(4,4); A311 = A3(1,1); A312 = A3(1,2); -A313 = A3(1,3); -A314 = A3(1,4); A321 = A3(2,1); A322 = A3(2,2); -A323 = A3(2,3); -A324 = A3(2,4); -A331 = A3(3,1); -A332 = A3(3,2); -A333 = A3(3,3); -A334 = A3(3,4); -A341 = A3(4,1); -A342 = A3(4,2); -A343 = A3(4,3); -A344 = A3(4,4); B = rand(2); B(1,1) = -B(1,1); @@ -123,14 +70,16 @@ if max(max(abs(EC-B)))>1e-12 error('Error component matrix is wrong.') end -if max(max(abs(AR(:,:,1)-A1(1:2,1:2))))>1e-12 +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(1:2,1:2))))>1e-12 +if max(max(abs(AR(:,:,2)-A2)))>1e-12 error('Second order autoregressive matrix is wrong.') end -if max(max(abs(AR(:,:,3)-A3(1:2,1:2))))>1e-12 +if max(max(abs(AR(:,:,3)-A3)))>1e-12 error('Third order autoregressive matrix is wrong.') -end \ No newline at end of file +end diff --git a/tests/trend-component-and-var-models/tcm5p.mod b/tests/trend-component-and-var-models/tcm5p.mod deleted file mode 100644 index 80e6ce7a4..000000000 --- a/tests/trend-component-and-var-models/tcm5p.mod +++ /dev/null @@ -1,85 +0,0 @@ -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); - -trend_component_model(model_name=toto, eqtags=['eq:y4', 'eq:y1', 'eq:y2', 'eq:y3'], trends=['eq:y3', 'eq:y4']); - -model; - -[name='eq:y1'] -diff(y1) = B11*(y1(-1)-y3(-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:y4'] -y4 = y4(-1) + e4; - - -[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; - -end; - -[EC, AR, T] = get_companion_matrix_preprocessor('toto'); - -if max(max(abs(EC-B)))>1e-12 - error('Error component matrix 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 diff --git a/tests/trend-component-and-var-models/vm1.mod b/tests/trend-component-and-var-models/vm1.mod index 032c90f2e..900484ed3 100644 --- a/tests/trend-component-and-var-models/vm1.mod +++ b/tests/trend-component-and-var-models/vm1.mod @@ -96,17 +96,17 @@ y4 = A141*y1(-1) + A142*y2(-1) + A143*y3(-1) + A144*y4(-1) + end; -get_companion_matrix('toto'); +[A0, AR, B] = get_companion_matrix('toto'); -if max(max(abs(oo_.var.toto.ar(:,:,1)-A1)))>1e-12 +if max(max(abs(AR(:,:,1)-A1)))>1e-12 error('First order autoregressive matrix is wrong.') end -if max(max(abs(oo_.var.toto.ar(:,:,2)-A2)))>1e-12 +if max(max(abs(AR(:,:,2)-A2)))>1e-12 error('Second order autoregressive matrix is wrong.') end -if max(max(abs(oo_.var.toto.ar(:,:,3)-A3)))>1e-12 +if max(max(abs(AR(:,:,3)-A3)))>1e-12 error('Third order autoregressive matrix is wrong.') end @@ -116,4 +116,4 @@ CompanionMatrix = [A1, A2, A3; if max(max(abs(CompanionMatrix-oo_.var.toto.CompanionMatrix)))>1e-12 error('Companion matrix is wrong.') -end \ No newline at end of file +end diff --git a/tests/trend-component-and-var-models/vm2.mod b/tests/trend-component-and-var-models/vm2.mod index b76990747..41d07f819 100644 --- a/tests/trend-component-and-var-models/vm2.mod +++ b/tests/trend-component-and-var-models/vm2.mod @@ -96,17 +96,17 @@ y4 = A141*y1(-1) + A142*y2(-1) + A143*y3(-1) + A144*y4(-1) + end; -get_companion_matrix('toto'); +[A0, AR, B] = get_companion_matrix('toto'); -if max(max(abs(oo_.var.toto.ar(:,:,1)-A1)))>1e-12 +if max(max(abs(AR(:,:,1)-A1)))>1e-12 error('First order autoregressive matrix is wrong.') end -if max(max(abs(oo_.var.toto.ar(:,:,2)-A2)))>1e-12 +if max(max(abs(AR(:,:,2)-A2)))>1e-12 error('Second order autoregressive matrix is wrong.') end -if max(max(abs(oo_.var.toto.ar(:,:,3)-A3)))>1e-12 +if max(max(abs(AR(:,:,3)-A3)))>1e-12 error('Third order autoregressive matrix is wrong.') end @@ -116,4 +116,4 @@ CompanionMatrix = [A1, A2, A3; if max(max(abs(CompanionMatrix-oo_.var.toto.CompanionMatrix)))>1e-12 error('Companion matrix is wrong.') -end \ No newline at end of file +end diff --git a/tests/trend-component-and-var-models/vm3.mod b/tests/trend-component-and-var-models/vm3.mod index 454dba96d..d73a25ce3 100644 --- a/tests/trend-component-and-var-models/vm3.mod +++ b/tests/trend-component-and-var-models/vm3.mod @@ -96,17 +96,17 @@ y1 = A111*y1(-1) + A112*y2(-1) + A113*y3(-1) + A114*y4(-1) + end; -get_companion_matrix('toto'); +[A0, AR, B] = get_companion_matrix('toto'); -if max(max(abs(oo_.var.toto.ar(:,:,1)-A1)))>1e-12 +if max(max(abs(AR(:,:,1)-A1)))>1e-12 error('First order autoregressive matrix is wrong.') end -if max(max(abs(oo_.var.toto.ar(:,:,2)-A2)))>1e-12 +if max(max(abs(AR(:,:,2)-A2)))>1e-12 error('Second order autoregressive matrix is wrong.') end -if max(max(abs(oo_.var.toto.ar(:,:,3)-A3)))>1e-12 +if max(max(abs(AR(:,:,3)-A3)))>1e-12 error('Third order autoregressive matrix is wrong.') end @@ -116,4 +116,4 @@ CompanionMatrix = [A1, A2, A3; if max(max(abs(CompanionMatrix-oo_.var.toto.CompanionMatrix)))>1e-12 error('Companion matrix is wrong.') -end \ No newline at end of file +end diff --git a/tests/trend-component-and-var-models/vm4.mod b/tests/trend-component-and-var-models/vm4.mod new file mode 100644 index 000000000..4f1877260 --- /dev/null +++ b/tests/trend-component-and-var-models/vm4.mod @@ -0,0 +1,52 @@ +// --+ options: json=compute, stochastic +-- + +var y x z; + +varexo ex ey ez; + +parameters a_y_1 a_y_2 b_y_1 b_y_2 b_x_1 b_x_2 ; // VAR parameters + +parameters beta e_c_m c_z_1 c_z_2; // PAC equation parameters + +a_y_1 = .2; +a_y_2 = .3; +b_y_1 = .1; +b_y_2 = .4; +b_x_1 = -.1; +b_x_2 = -.2; + +beta = .9; +e_c_m = .1; +c_z_1 = .7; +c_z_2 = -.3; + +var_model(model_name=toto, eqtags=['eq:x', 'eq:y']); + +pac_model(auxiliary_model_name=toto, discount=beta, model_name=pacman); + +model; + +[name='eq:y'] +y = a_y_1*y(-1) + a_y_2*diff(x(-1)) + b_y_1*y(-2) + b_y_2*diff(x(-2)) + ey ; + +[name='eq:x', data_type='nonstationary'] +diff(x) = b_x_1*y(-2) + b_x_2*diff(x(-1)) + ex ; + +[name='eq:pac'] +diff(z) = e_c_m*(x(-1)-z(-1)) + c_z_1*diff(z(-1)) + c_z_2*diff(z(-2)) + pac_expectation(pacman) + ez; + +end; + +shocks; + var ex = 1.0; + var ey = 1.0; + var ez = 1.0; +end; + +[~, b0, ~] = get_companion_matrix_legacy('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.'). +end \ No newline at end of file