New version of get_companion_matrix + new integration test.
The routine is still buggy. In PAC and VAR_EXPECTATION models we use get_companion_matrix_legacy routine instead.time-shift
parent
c588544b13
commit
031e2c87c6
|
@ -39,4 +39,4 @@ end
|
||||||
|
|
||||||
M_.pac.(pacmodel).auxiliary_model_type = auxiliary_model_type;
|
M_.pac.(pacmodel).auxiliary_model_type = auxiliary_model_type;
|
||||||
|
|
||||||
get_companion_matrix(auxiliary_model_name, auxiliary_model_type);
|
get_companion_matrix_legacy(auxiliary_model_name, auxiliary_model_type);
|
|
@ -59,7 +59,7 @@ auxcalib = DynareOutput.(varexpectationmodel.auxiliary_model_type).(varexpectati
|
||||||
|
|
||||||
if ~isfield(auxcalib, 'CompanionMatrix') || any(isnan(auxcalib.CompanionMatrix(:)))
|
if ~isfield(auxcalib, 'CompanionMatrix') || any(isnan(auxcalib.CompanionMatrix(:)))
|
||||||
message = sprintf('Auxiliary model %s has to be estimated first.', varexpectationmodel.auxiliary_model_name);
|
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);
|
error(message);
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -42,4 +42,4 @@ end
|
||||||
|
|
||||||
M_.var_expectation.(varexpectationmodel).auxiliary_model_type = auxiliary_model_type;
|
M_.var_expectation.(varexpectationmodel).auxiliary_model_type = auxiliary_model_type;
|
||||||
|
|
||||||
get_companion_matrix(auxiliary_model_name, auxiliary_model_type);
|
get_companion_matrix_legacy(auxiliary_model_name, auxiliary_model_type);
|
|
@ -31,7 +31,7 @@ function [A0, AR, B] = get_companion_matrix(auxiliary_model_name, auxiliary_mode
|
||||||
|
|
||||||
global oo_ M_
|
global oo_ M_
|
||||||
|
|
||||||
if nargin<2
|
if nargin < 2
|
||||||
if isfield(M_, 'var') && isfield(M_.var, auxiliary_model_name)
|
if isfield(M_, 'var') && isfield(M_.var, auxiliary_model_name)
|
||||||
auxiliary_model_type = 'var';
|
auxiliary_model_type = 'var';
|
||||||
elseif isfield(M_, 'trend_component') && isfield(M_.trend_component, auxiliary_model_name)
|
elseif isfield(M_, 'trend_component') && isfield(M_.trend_component, auxiliary_model_name)
|
||||||
|
@ -41,39 +41,47 @@ if nargin<2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if nargout
|
if strcmp(auxiliary_model_type, 'var')
|
||||||
A0 = [];
|
AR = evalin('base', [M_.fname '.var_ar(''' auxiliary_model_name ''', M_.params)']);
|
||||||
AR = [];
|
elseif strcmp(auxiliary_model_type, 'trend_component')
|
||||||
B = [];
|
[AR, A0] = evalin('base', [M_.fname '.trend_component_ar_ec(''' auxiliary_model_name ''', M_.params)']);
|
||||||
|
else
|
||||||
|
error('Unknown type of auxiliary model.')
|
||||||
end
|
end
|
||||||
|
|
||||||
get_ar_ec_matrices(auxiliary_model_name, auxiliary_model_type);
|
|
||||||
|
|
||||||
% Get the number of lags
|
% 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
|
% 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
|
switch auxiliary_model_type
|
||||||
case 'var'
|
case 'var'
|
||||||
oo_.var.(auxiliary_model_name).CompanionMatrix = zeros(n*p);
|
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);
|
oo_.var.(auxiliary_model_name).CompanionMatrix(1:n,1:n) = AR(:,:,1);
|
||||||
for i=2:p
|
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,(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);
|
oo_.var.(auxiliary_model_name).CompanionMatrix((i-1)*n+(1:n),(i-2)*n+(1:n)) = eye(n);
|
||||||
end
|
end
|
||||||
M_.var.(auxiliary_model_name).list_of_variables_in_companion_var = M_.endo_names(M_.var.(auxiliary_model_name).lhs);
|
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'
|
case 'trend_component'
|
||||||
% Get number of trends.
|
% Get number of trends.
|
||||||
q = sum(M_.trend_component.(auxiliary_model_name).trends);
|
q = sum(M_.trend_component.(auxiliary_model_name).trends);
|
||||||
|
|
||||||
% Get the number of equations with error correction.
|
% 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.
|
% 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);
|
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);
|
ecm_eqnums_in_auxiliary_model = find(~M_.trend_component.(auxiliary_model_name).trends);
|
||||||
|
|
||||||
% Get the indices of trend equations in model.
|
% Get the indices of trend equations in model.
|
||||||
trend_eqnums = M_.trend_component.(auxiliary_model_name).trend_eqn;
|
trend_eqnums = M_.trend_component.(auxiliary_model_name).trend_eqn;
|
||||||
|
|
||||||
% REMARK It is assumed that the non trend equations are the error correction
|
% 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:
|
% 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
|
% where the dimensions of I and 0 matrices can easily be
|
||||||
% deduced from the number of EC and trend equations.
|
% deduced from the number of EC and trend equations.
|
||||||
|
|
||||||
% Check that the lhs of candidate ecm equations are at least first differences.
|
% 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)))
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
% Get the trend variables indices (lhs variables in trend equations).
|
% Get the trend variables indices (lhs variables in trend equations).
|
||||||
[~, id_trend_in_var, ~] = intersect(M_.trend_component.(auxiliary_model_name).eqn, trend_eqnums);
|
[~, 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);
|
trend_variables = reshape(M_.trend_component.(auxiliary_model_name).lhs(id_trend_in_var), q, 1);
|
||||||
|
|
||||||
% Get the rhs variables in trend equations.
|
% 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.
|
% 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;
|
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)})
|
error('A trend equation (%s) must have only one variable on the RHS!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)})
|
||||||
end
|
end
|
||||||
trend_autoregressive_variables(i) = v;
|
|
||||||
% Check that the variables on lhs and rhs have the same difference orders.
|
% 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)})
|
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
|
end
|
||||||
|
|
||||||
% Check that the trend equation is autoregressive.
|
% Check that the trend equation is autoregressive.
|
||||||
if isdiff(v)
|
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)})
|
error('In a trend equation (%s) RHS variable must be lagged LHS variable!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)})
|
||||||
else
|
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)})
|
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
|
end
|
||||||
else
|
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)})
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
% Reorder trend_eqnums_in_auxiliary_model to ensure that the order of
|
% Reorder trend_eqnums_in_auxiliary_model to ensure that the order of
|
||||||
% the trend variables matches the order of the error correction
|
% the trend variables matches the order of the error correction
|
||||||
% variables.
|
% variables.
|
||||||
[~,reorder] = ismember(M_.trend_component.toto.lhs(trend_eqnums_in_auxiliary_model), ...
|
[~,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);
|
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).
|
% 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
|
% TODO: Check that the EC term is the difference between the
|
||||||
% endogenous variable and the trend variable.
|
% 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)
|
% 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, ecm_eqnums_in_auxiliary_model, 1) = eye(m) + A0 + AR(:,:,1);
|
||||||
B(ecm_eqnums_in_auxiliary_model,trend_eqnums_in_auxiliary_model) = -A0;
|
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);
|
B(trend_eqnums_in_auxiliary_model, trend_eqnums_in_auxiliary_model) = eye(q);
|
||||||
for i=2:p
|
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,i) = AR(:,:,i) - AR(:,:,i-1);
|
||||||
end
|
end
|
||||||
B(ecm_eqnums_in_auxiliary_model,ecm_eqnums_in_auxiliary_model,p+1) = -AR(:,:,p);
|
B(ecm_eqnums_in_auxiliary_model,ecm_eqnums_in_auxiliary_model,p+1) = -AR(:,:,p);
|
||||||
|
|
||||||
% Write Companion matrix
|
% Write Companion matrix
|
||||||
oo_.trend_component.(auxiliary_model_name).CompanionMatrix = zeros(size(B, 1)*size(B, 3));
|
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(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);
|
oo_.trend_component.(auxiliary_model_name).CompanionMatrix(i*n+(1:n),(i-1)*n+(1:n)) = eye(n);
|
||||||
end
|
end
|
||||||
|
|
|
@ -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_legacy(auxiliary_model_name, auxiliary_model_type)
|
||||||
%function [A0, AR, B] = get_companion_matrix_preprocessor(auxiliary_model_name, auxiliary_model_type)
|
|
||||||
%
|
|
||||||
% Gets the companion VAR representation of a PAC auxiliary model.
|
% Gets the companion VAR representation of a PAC auxiliary model.
|
||||||
% Depending on the nature of this auxiliary model the output is
|
% Depending on the nature of this auxiliary model the output is
|
||||||
% saved in oo_.{var,trend_component}.(auxiliary_model_name).CompanionMatrix
|
% 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_
|
global oo_ M_
|
||||||
|
|
||||||
if nargin < 2
|
if nargin<2
|
||||||
if isfield(M_, 'var') && isfield(M_.var, auxiliary_model_name)
|
if isfield(M_, 'var') && isfield(M_.var, auxiliary_model_name)
|
||||||
auxiliary_model_type = 'var';
|
auxiliary_model_type = 'var';
|
||||||
elseif isfield(M_, 'trend_component') && isfield(M_.trend_component, auxiliary_model_name)
|
elseif isfield(M_, 'trend_component') && isfield(M_.trend_component, auxiliary_model_name)
|
||||||
|
@ -42,47 +41,39 @@ if nargin < 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if strcmp(auxiliary_model_type, 'var')
|
if nargout
|
||||||
AR = evalin('base', [M_.fname '.var_ar(''' auxiliary_model_name ''', M_.params)']);
|
A0 = [];
|
||||||
elseif strcmp(auxiliary_model_type, 'trend_component')
|
AR = [];
|
||||||
[AR, A0] = evalin('base', [M_.fname '.trend_component_ar_ec(''' auxiliary_model_name ''', M_.params)']);
|
B = [];
|
||||||
else
|
|
||||||
error('Unknown type of auxiliary model.')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get_ar_ec_matrices(auxiliary_model_name, auxiliary_model_type);
|
||||||
|
|
||||||
% Get the number of lags
|
% 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
|
% 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
|
switch auxiliary_model_type
|
||||||
case 'var'
|
case 'var'
|
||||||
oo_.var.(auxiliary_model_name).CompanionMatrix = zeros(n*p);
|
oo_.var.(auxiliary_model_name).CompanionMatrix = zeros(n*p);
|
||||||
oo_.var.(auxiliary_model_name).CompanionMatrix(1:n,1:n) = AR(:,:,1);
|
oo_.var.(auxiliary_model_name).CompanionMatrix(1:n,1:n) = oo_.var.(auxiliary_model_name).ar(:,:,1);
|
||||||
for i = 2:p
|
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,(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);
|
oo_.var.(auxiliary_model_name).CompanionMatrix((i-1)*n+(1:n),(i-2)*n+(1:n)) = eye(n);
|
||||||
end
|
end
|
||||||
M_.var.(auxiliary_model_name).list_of_variables_in_companion_var = M_.endo_names(M_.var.(auxiliary_model_name).lhs);
|
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'
|
case 'trend_component'
|
||||||
% Get number of trends.
|
% Get number of trends.
|
||||||
q = sum(M_.trend_component.(auxiliary_model_name).trends);
|
q = sum(M_.trend_component.(auxiliary_model_name).trends);
|
||||||
|
|
||||||
% Get the number of equations with error correction.
|
% 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.
|
% 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);
|
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);
|
ecm_eqnums_in_auxiliary_model = find(~M_.trend_component.(auxiliary_model_name).trends);
|
||||||
|
|
||||||
% Get the indices of trend equations in model.
|
% Get the indices of trend equations in model.
|
||||||
trend_eqnums = M_.trend_component.(auxiliary_model_name).trend_eqn;
|
trend_eqnums = M_.trend_component.(auxiliary_model_name).trend_eqn;
|
||||||
|
|
||||||
% REMARK It is assumed that the non trend equations are the error correction
|
% 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:
|
% 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
|
% where the dimensions of I and 0 matrices can easily be
|
||||||
% deduced from the number of EC and trend equations.
|
% deduced from the number of EC and trend equations.
|
||||||
|
|
||||||
% Check that the lhs of candidate ecm equations are at least first differences.
|
% 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)))
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
% Get the trend variables indices (lhs variables in trend equations).
|
% Get the trend variables indices (lhs variables in trend equations).
|
||||||
[~, id_trend_in_var, ~] = intersect(M_.trend_component.(auxiliary_model_name).eqn, trend_eqnums);
|
[~, 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);
|
trend_variables = reshape(M_.trend_component.(auxiliary_model_name).lhs(id_trend_in_var), q, 1);
|
||||||
|
|
||||||
% Get the rhs variables in trend equations.
|
% 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.
|
% 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;
|
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)})
|
error('A trend equation (%s) must have only one variable on the RHS!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)})
|
||||||
end
|
end
|
||||||
|
trend_autoregressive_variables(i) = v;
|
||||||
% Check that the variables on lhs and rhs have the same difference orders.
|
% 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)})
|
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
|
end
|
||||||
|
|
||||||
% Check that the trend equation is autoregressive.
|
% Check that the trend equation is autoregressive.
|
||||||
if isdiff(v)
|
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)})
|
error('In a trend equation (%s) RHS variable must be lagged LHS variable!', M_.trend_component.(auxiliary_model_name).eqtags{trend_eqnums(i)})
|
||||||
else
|
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)})
|
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
|
end
|
||||||
else
|
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)})
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
% Reorder trend_eqnums_in_auxiliary_model to ensure that the order of
|
% Reorder trend_eqnums_in_auxiliary_model to ensure that the order of
|
||||||
% the trend variables matches the order of the error correction
|
% the trend variables matches the order of the error correction
|
||||||
% variables.
|
% variables.
|
||||||
[~,reorder] = ismember(M_.trend_component.toto.lhs(trend_eqnums_in_auxiliary_model), ...
|
[~,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);
|
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).
|
% 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
|
% TODO: Check that the EC term is the difference between the
|
||||||
% endogenous variable and the trend variable.
|
% 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)
|
% 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,ecm_eqnums_in_auxiliary_model,1) = eye(m)+A0+AR(:,:,1);
|
||||||
B(ecm_eqnums_in_auxiliary_model, trend_eqnums_in_auxiliary_model) = -A0;
|
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);
|
B(trend_eqnums_in_auxiliary_model,trend_eqnums_in_auxiliary_model) = eye(q);
|
||||||
for i = 2:p
|
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,i) = AR(:,:,i)-AR(:,:,i-1);
|
||||||
end
|
end
|
||||||
B(ecm_eqnums_in_auxiliary_model,ecm_eqnums_in_auxiliary_model,p+1) = -AR(:,:,p);
|
B(ecm_eqnums_in_auxiliary_model,ecm_eqnums_in_auxiliary_model,p+1) = -AR(:,:,p);
|
||||||
|
|
||||||
% Write Companion matrix
|
% Write Companion matrix
|
||||||
oo_.trend_component.(auxiliary_model_name).CompanionMatrix = zeros(size(B, 1)*size(B, 3));
|
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(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);
|
oo_.trend_component.(auxiliary_model_name).CompanionMatrix(i*n+(1:n),(i-1)*n+(1:n)) = eye(n);
|
||||||
end
|
end
|
|
@ -361,20 +361,21 @@ MODFILES = \
|
||||||
trend-component-and-var-models/vm1.mod \
|
trend-component-and-var-models/vm1.mod \
|
||||||
trend-component-and-var-models/vm2.mod \
|
trend-component-and-var-models/vm2.mod \
|
||||||
trend-component-and-var-models/vm3.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/tcm1.mod \
|
||||||
trend-component-and-var-models/tcm2.mod \
|
trend-component-and-var-models/tcm2.mod \
|
||||||
trend-component-and-var-models/tcm3.mod \
|
trend-component-and-var-models/tcm3.mod \
|
||||||
trend-component-and-var-models/tcm4.mod \
|
trend-component-and-var-models/tcm4.mod \
|
||||||
trend-component-and-var-models/tcm5.mod \
|
trend-component-and-var-models/tcm5.mod \
|
||||||
trend-component-and-var-models/tcm6.mod \
|
trend-component-and-var-models/tcm6.mod \
|
||||||
trend-component-and-var-models/vm1p.mod \
|
trend-component-and-var-models/legacy/vm1.mod \
|
||||||
trend-component-and-var-models/vm2p.mod \
|
trend-component-and-var-models/legacy/vm2.mod \
|
||||||
trend-component-and-var-models/vm3p.mod \
|
trend-component-and-var-models/legacy/vm3.mod \
|
||||||
trend-component-and-var-models/tcm1p.mod \
|
trend-component-and-var-models/legacy/tcm1.mod \
|
||||||
trend-component-and-var-models/tcm2p.mod \
|
trend-component-and-var-models/legacy/tcm2.mod \
|
||||||
trend-component-and-var-models/tcm3p.mod \
|
trend-component-and-var-models/legacy/tcm3.mod \
|
||||||
trend-component-and-var-models/tcm4p.mod \
|
trend-component-and-var-models/legacy/tcm4.mod \
|
||||||
trend-component-and-var-models/tcm5p.mod \
|
trend-component-and-var-models/legacy/tcm5.mod \
|
||||||
pac/var-1/example.mod \
|
pac/var-1/example.mod \
|
||||||
pac/var-2/example.mod \
|
pac/var-2/example.mod \
|
||||||
pac/var-3/example.mod \
|
pac/var-3/example.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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -96,17 +96,17 @@ y4 = A141*y1(-1) + A142*y2(-1) + A143*y3(-1) + A144*y4(-1) +
|
||||||
|
|
||||||
end;
|
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.')
|
error('First order autoregressive matrix is wrong.')
|
||||||
end
|
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.')
|
error('Second order autoregressive matrix is wrong.')
|
||||||
end
|
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.')
|
error('Third order autoregressive matrix is wrong.')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -116,4 +116,4 @@ CompanionMatrix = [A1, A2, A3;
|
||||||
|
|
||||||
if max(max(abs(CompanionMatrix-oo_.var.toto.CompanionMatrix)))>1e-12
|
if max(max(abs(CompanionMatrix-oo_.var.toto.CompanionMatrix)))>1e-12
|
||||||
error('Companion matrix is wrong.')
|
error('Companion matrix is wrong.')
|
||||||
end
|
end
|
|
@ -96,17 +96,17 @@ y4 = A141*y1(-1) + A142*y2(-1) + A143*y3(-1) + A144*y4(-1) +
|
||||||
|
|
||||||
end;
|
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.')
|
error('First order autoregressive matrix is wrong.')
|
||||||
end
|
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.')
|
error('Second order autoregressive matrix is wrong.')
|
||||||
end
|
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.')
|
error('Third order autoregressive matrix is wrong.')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -116,4 +116,4 @@ CompanionMatrix = [A1, A2, A3;
|
||||||
|
|
||||||
if max(max(abs(CompanionMatrix-oo_.var.toto.CompanionMatrix)))>1e-12
|
if max(max(abs(CompanionMatrix-oo_.var.toto.CompanionMatrix)))>1e-12
|
||||||
error('Companion matrix is wrong.')
|
error('Companion matrix is wrong.')
|
||||||
end
|
end
|
|
@ -96,17 +96,17 @@ y1 = A111*y1(-1) + A112*y2(-1) + A113*y3(-1) + A114*y4(-1) +
|
||||||
|
|
||||||
end;
|
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.')
|
error('First order autoregressive matrix is wrong.')
|
||||||
end
|
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.')
|
error('Second order autoregressive matrix is wrong.')
|
||||||
end
|
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.')
|
error('Third order autoregressive matrix is wrong.')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -116,4 +116,4 @@ CompanionMatrix = [A1, A2, A3;
|
||||||
|
|
||||||
if max(max(abs(CompanionMatrix-oo_.var.toto.CompanionMatrix)))>1e-12
|
if max(max(abs(CompanionMatrix-oo_.var.toto.CompanionMatrix)))>1e-12
|
||||||
error('Companion matrix is wrong.')
|
error('Companion matrix is wrong.')
|
||||||
end
|
end
|
|
@ -2,85 +2,32 @@ var y1 y2 y3 y4;
|
||||||
|
|
||||||
varexo e1 e2 e3 e4;
|
varexo e1 e2 e3 e4;
|
||||||
|
|
||||||
parameters A111 A112 A113 A114
|
parameters A111 A112
|
||||||
A121 A122 A123 A124
|
A121 A122
|
||||||
A131 A132 A133 A134
|
A211 A212
|
||||||
A141 A142 A143 A144
|
A221 A222
|
||||||
A211 A212 A213 A214
|
A311 A312
|
||||||
A221 A222 A223 A224
|
A321 A322
|
||||||
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;
|
B11 B12 B21 B22;
|
||||||
|
|
||||||
A1 = randn(4);
|
A1 = randn(2);
|
||||||
A2 = randn(4);
|
A2 = randn(2);
|
||||||
A3 = randn(4);
|
A3 = randn(2);
|
||||||
|
|
||||||
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);
|
A111 = A1(1,1);
|
||||||
A112 = A1(1,2);
|
A112 = A1(1,2);
|
||||||
A113 = A1(1,3);
|
|
||||||
A114 = A1(1,4);
|
|
||||||
A121 = A1(2,1);
|
A121 = A1(2,1);
|
||||||
A122 = A1(2,2);
|
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);
|
A211 = A2(1,1);
|
||||||
A212 = A2(1,2);
|
A212 = A2(1,2);
|
||||||
A213 = A2(1,3);
|
|
||||||
A214 = A2(1,4);
|
|
||||||
A221 = A2(2,1);
|
A221 = A2(2,1);
|
||||||
A222 = A2(2,2);
|
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);
|
A311 = A3(1,1);
|
||||||
A312 = A3(1,2);
|
A312 = A3(1,2);
|
||||||
A313 = A3(1,3);
|
|
||||||
A314 = A3(1,4);
|
|
||||||
A321 = A3(2,1);
|
A321 = A3(2,1);
|
||||||
A322 = A3(2,2);
|
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 = rand(2);
|
||||||
B(1,1) = -B(1,1);
|
B(1,1) = -B(1,1);
|
||||||
|
@ -122,17 +69,16 @@ if max(max(abs(EC-B)))>1e-12
|
||||||
error('Error component matrix is wrong.')
|
error('Error component matrix is wrong.')
|
||||||
end
|
end
|
||||||
|
|
||||||
A1fake = oo_.trend_component.toto.ar(:,:,1);
|
A1fake = AR(:,:,1);
|
||||||
A1fake(1:2,3:4) = .0;
|
|
||||||
|
|
||||||
if max(max(abs(A1fake-A1)))>1e-12
|
if max(max(abs(A1fake-A1)))>1e-12
|
||||||
error('First order autoregressive matrix is wrong.')
|
error('First order autoregressive matrix is wrong.')
|
||||||
end
|
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.')
|
error('Second order autoregressive matrix is wrong.')
|
||||||
end
|
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.')
|
error('Third order autoregressive matrix is wrong.')
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
|
|
@ -2,85 +2,32 @@ var y1 y2 y3 y4;
|
||||||
|
|
||||||
varexo e1 e2 e3 e4;
|
varexo e1 e2 e3 e4;
|
||||||
|
|
||||||
parameters A111 A112 A113 A114
|
parameters A111 A112
|
||||||
A121 A122 A123 A124
|
A121 A122
|
||||||
A131 A132 A133 A134
|
A211 A212
|
||||||
A141 A142 A143 A144
|
A221 A222
|
||||||
A211 A212 A213 A214
|
A311 A312
|
||||||
A221 A222 A223 A224
|
A321 A322
|
||||||
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;
|
B11 B12 B21 B22;
|
||||||
|
|
||||||
A1 = randn(4);
|
A1 = randn(2);
|
||||||
A2 = randn(4);
|
A2 = randn(2);
|
||||||
A3 = randn(4);
|
A3 = randn(2);
|
||||||
|
|
||||||
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);
|
A111 = A1(1,1);
|
||||||
A112 = A1(1,2);
|
A112 = A1(1,2);
|
||||||
A113 = A1(1,3);
|
|
||||||
A114 = A1(1,4);
|
|
||||||
A121 = A1(2,1);
|
A121 = A1(2,1);
|
||||||
A122 = A1(2,2);
|
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);
|
A211 = A2(1,1);
|
||||||
A212 = A2(1,2);
|
A212 = A2(1,2);
|
||||||
A213 = A2(1,3);
|
|
||||||
A214 = A2(1,4);
|
|
||||||
A221 = A2(2,1);
|
A221 = A2(2,1);
|
||||||
A222 = A2(2,2);
|
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);
|
A311 = A3(1,1);
|
||||||
A312 = A3(1,2);
|
A312 = A3(1,2);
|
||||||
A313 = A3(1,3);
|
|
||||||
A314 = A3(1,4);
|
|
||||||
A321 = A3(2,1);
|
A321 = A3(2,1);
|
||||||
A322 = A3(2,2);
|
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 = rand(2);
|
||||||
B(1,1) = -B(1,1);
|
B(1,1) = -B(1,1);
|
||||||
|
@ -122,14 +69,16 @@ if max(max(abs(EC-B)))>1e-12
|
||||||
error('Error component matrix is wrong.')
|
error('Error component matrix is wrong.')
|
||||||
end
|
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.')
|
error('First order autoregressive matrix is wrong.')
|
||||||
end
|
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.')
|
error('Second order autoregressive matrix is wrong.')
|
||||||
end
|
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.')
|
error('Third order autoregressive matrix is wrong.')
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
|
|
@ -2,85 +2,32 @@ var y1 y2 y3 y4;
|
||||||
|
|
||||||
varexo e1 e2 e3 e4;
|
varexo e1 e2 e3 e4;
|
||||||
|
|
||||||
parameters A111 A112 A113 A114
|
parameters A111 A112
|
||||||
A121 A122 A123 A124
|
A121 A122
|
||||||
A131 A132 A133 A134
|
A211 A212
|
||||||
A141 A142 A143 A144
|
A221 A222
|
||||||
A211 A212 A213 A214
|
A311 A312
|
||||||
A221 A222 A223 A224
|
A321 A322
|
||||||
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;
|
B11 B12 B21 B22;
|
||||||
|
|
||||||
A1 = randn(4);
|
A1 = randn(2);
|
||||||
A2 = randn(4);
|
A2 = randn(2);
|
||||||
A3 = randn(4);
|
A3 = randn(2);
|
||||||
|
|
||||||
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);
|
A111 = A1(1,1);
|
||||||
A112 = A1(1,2);
|
A112 = A1(1,2);
|
||||||
A113 = A1(1,3);
|
|
||||||
A114 = A1(1,4);
|
|
||||||
A121 = A1(2,1);
|
A121 = A1(2,1);
|
||||||
A122 = A1(2,2);
|
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);
|
A211 = A2(1,1);
|
||||||
A212 = A2(1,2);
|
A212 = A2(1,2);
|
||||||
A213 = A2(1,3);
|
|
||||||
A214 = A2(1,4);
|
|
||||||
A221 = A2(2,1);
|
A221 = A2(2,1);
|
||||||
A222 = A2(2,2);
|
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);
|
A311 = A3(1,1);
|
||||||
A312 = A3(1,2);
|
A312 = A3(1,2);
|
||||||
A313 = A3(1,3);
|
|
||||||
A314 = A3(1,4);
|
|
||||||
A321 = A3(2,1);
|
A321 = A3(2,1);
|
||||||
A322 = A3(2,2);
|
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 = rand(2);
|
||||||
B(1,1) = -B(1,1);
|
B(1,1) = -B(1,1);
|
||||||
|
@ -122,14 +69,16 @@ if max(max(abs(EC-B)))>1e-12
|
||||||
error('Error component matrix is wrong.')
|
error('Error component matrix is wrong.')
|
||||||
end
|
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.')
|
error('First order autoregressive matrix is wrong.')
|
||||||
end
|
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.')
|
error('Second order autoregressive matrix is wrong.')
|
||||||
end
|
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.')
|
error('Third order autoregressive matrix is wrong.')
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
|
|
@ -2,85 +2,32 @@ var y1 y2 y3 y4;
|
||||||
|
|
||||||
varexo e1 e2 e3 e4;
|
varexo e1 e2 e3 e4;
|
||||||
|
|
||||||
parameters A111 A112 A113 A114
|
parameters A111 A112
|
||||||
A121 A122 A123 A124
|
A121 A122
|
||||||
A131 A132 A133 A134
|
A211 A212
|
||||||
A141 A142 A143 A144
|
A221 A222
|
||||||
A211 A212 A213 A214
|
A311 A312
|
||||||
A221 A222 A223 A224
|
A321 A322
|
||||||
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;
|
B11 B12 B21 B22;
|
||||||
|
|
||||||
A1 = randn(4);
|
A1 = randn(2);
|
||||||
A2 = randn(4);
|
A2 = randn(2);
|
||||||
A3 = randn(4);
|
A3 = randn(2);
|
||||||
|
|
||||||
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);
|
A111 = A1(1,1);
|
||||||
A112 = A1(1,2);
|
A112 = A1(1,2);
|
||||||
A113 = A1(1,3);
|
|
||||||
A114 = A1(1,4);
|
|
||||||
A121 = A1(2,1);
|
A121 = A1(2,1);
|
||||||
A122 = A1(2,2);
|
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);
|
A211 = A2(1,1);
|
||||||
A212 = A2(1,2);
|
A212 = A2(1,2);
|
||||||
A213 = A2(1,3);
|
|
||||||
A214 = A2(1,4);
|
|
||||||
A221 = A2(2,1);
|
A221 = A2(2,1);
|
||||||
A222 = A2(2,2);
|
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);
|
A311 = A3(1,1);
|
||||||
A312 = A3(1,2);
|
A312 = A3(1,2);
|
||||||
A313 = A3(1,3);
|
|
||||||
A314 = A3(1,4);
|
|
||||||
A321 = A3(2,1);
|
A321 = A3(2,1);
|
||||||
A322 = A3(2,2);
|
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 = rand(2);
|
||||||
B(1,1) = -B(1,1);
|
B(1,1) = -B(1,1);
|
||||||
|
@ -123,14 +70,16 @@ if max(max(abs(EC-B)))>1e-12
|
||||||
error('Error component matrix is wrong.')
|
error('Error component matrix is wrong.')
|
||||||
end
|
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.')
|
error('First order autoregressive matrix is wrong.')
|
||||||
end
|
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.')
|
error('Second order autoregressive matrix is wrong.')
|
||||||
end
|
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.')
|
error('Third order autoregressive matrix is wrong.')
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
|
|
@ -2,85 +2,32 @@ var y1 y2 y3 y4;
|
||||||
|
|
||||||
varexo e1 e2 e3 e4;
|
varexo e1 e2 e3 e4;
|
||||||
|
|
||||||
parameters A111 A112 A113 A114
|
parameters A111 A112
|
||||||
A121 A122 A123 A124
|
A121 A122
|
||||||
A131 A132 A133 A134
|
A211 A212
|
||||||
A141 A142 A143 A144
|
A221 A222
|
||||||
A211 A212 A213 A214
|
A311 A312
|
||||||
A221 A222 A223 A224
|
A321 A322
|
||||||
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;
|
B11 B12 B21 B22;
|
||||||
|
|
||||||
A1 = randn(4);
|
A1 = randn(2);
|
||||||
A2 = randn(4);
|
A2 = randn(2);
|
||||||
A3 = randn(4);
|
A3 = randn(2);
|
||||||
|
|
||||||
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);
|
A111 = A1(1,1);
|
||||||
A112 = A1(1,2);
|
A112 = A1(1,2);
|
||||||
A113 = A1(1,3);
|
|
||||||
A114 = A1(1,4);
|
|
||||||
A121 = A1(2,1);
|
A121 = A1(2,1);
|
||||||
A122 = A1(2,2);
|
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);
|
A211 = A2(1,1);
|
||||||
A212 = A2(1,2);
|
A212 = A2(1,2);
|
||||||
A213 = A2(1,3);
|
|
||||||
A214 = A2(1,4);
|
|
||||||
A221 = A2(2,1);
|
A221 = A2(2,1);
|
||||||
A222 = A2(2,2);
|
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);
|
A311 = A3(1,1);
|
||||||
A312 = A3(1,2);
|
A312 = A3(1,2);
|
||||||
A313 = A3(1,3);
|
|
||||||
A314 = A3(1,4);
|
|
||||||
A321 = A3(2,1);
|
A321 = A3(2,1);
|
||||||
A322 = A3(2,2);
|
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 = rand(2);
|
||||||
B(1,1) = -B(1,1);
|
B(1,1) = -B(1,1);
|
||||||
|
@ -123,14 +70,16 @@ if max(max(abs(EC-B)))>1e-12
|
||||||
error('Error component matrix is wrong.')
|
error('Error component matrix is wrong.')
|
||||||
end
|
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.')
|
error('First order autoregressive matrix is wrong.')
|
||||||
end
|
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.')
|
error('Second order autoregressive matrix is wrong.')
|
||||||
end
|
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.')
|
error('Third order autoregressive matrix is wrong.')
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
|
|
@ -96,17 +96,17 @@ y4 = A141*y1(-1) + A142*y2(-1) + A143*y3(-1) + A144*y4(-1) +
|
||||||
|
|
||||||
end;
|
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.')
|
error('First order autoregressive matrix is wrong.')
|
||||||
end
|
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.')
|
error('Second order autoregressive matrix is wrong.')
|
||||||
end
|
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.')
|
error('Third order autoregressive matrix is wrong.')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -116,4 +116,4 @@ CompanionMatrix = [A1, A2, A3;
|
||||||
|
|
||||||
if max(max(abs(CompanionMatrix-oo_.var.toto.CompanionMatrix)))>1e-12
|
if max(max(abs(CompanionMatrix-oo_.var.toto.CompanionMatrix)))>1e-12
|
||||||
error('Companion matrix is wrong.')
|
error('Companion matrix is wrong.')
|
||||||
end
|
end
|
||||||
|
|
|
@ -96,17 +96,17 @@ y4 = A141*y1(-1) + A142*y2(-1) + A143*y3(-1) + A144*y4(-1) +
|
||||||
|
|
||||||
end;
|
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.')
|
error('First order autoregressive matrix is wrong.')
|
||||||
end
|
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.')
|
error('Second order autoregressive matrix is wrong.')
|
||||||
end
|
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.')
|
error('Third order autoregressive matrix is wrong.')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -116,4 +116,4 @@ CompanionMatrix = [A1, A2, A3;
|
||||||
|
|
||||||
if max(max(abs(CompanionMatrix-oo_.var.toto.CompanionMatrix)))>1e-12
|
if max(max(abs(CompanionMatrix-oo_.var.toto.CompanionMatrix)))>1e-12
|
||||||
error('Companion matrix is wrong.')
|
error('Companion matrix is wrong.')
|
||||||
end
|
end
|
||||||
|
|
|
@ -96,17 +96,17 @@ y1 = A111*y1(-1) + A112*y2(-1) + A113*y3(-1) + A114*y4(-1) +
|
||||||
|
|
||||||
end;
|
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.')
|
error('First order autoregressive matrix is wrong.')
|
||||||
end
|
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.')
|
error('Second order autoregressive matrix is wrong.')
|
||||||
end
|
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.')
|
error('Third order autoregressive matrix is wrong.')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -116,4 +116,4 @@ CompanionMatrix = [A1, A2, A3;
|
||||||
|
|
||||||
if max(max(abs(CompanionMatrix-oo_.var.toto.CompanionMatrix)))>1e-12
|
if max(max(abs(CompanionMatrix-oo_.var.toto.CompanionMatrix)))>1e-12
|
||||||
error('Companion matrix is wrong.')
|
error('Companion matrix is wrong.')
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue