- new Incidence_Matrix class
- lead and lag on exogenous variables - corrections in dr1_sparse and dr11_sparse - minor corrections in simulate git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@2255 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
a02e66e12c
commit
f904a1a19d
|
@ -0,0 +1,234 @@
|
|||
function disp_dr_sparse(dr,order,var_list)
|
||||
|
||||
% Copyright (C) 2001 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
global M_
|
||||
nx = 0;
|
||||
nu = 0;
|
||||
k = [];
|
||||
klag = [];
|
||||
k1 = [];
|
||||
nspred = 0;
|
||||
for i=1:length(M_.block_structure.block)
|
||||
nspred = nspred + M_.block_structure.block(i).dr.nspred;
|
||||
end;
|
||||
ghu = zeros(M_.endo_nbr, M_.exo_nbr*(M_.maximum_exo_lag+M_.maximum_exo_lead+1));
|
||||
ghx = zeros(M_.endo_nbr, nspred);
|
||||
for i=1:length(M_.block_structure.block)
|
||||
nx = nx + size(M_.block_structure.block(i).dr.ghx,2);
|
||||
% M_.block_structure.block(i).dr.ghx
|
||||
% M_.block_structure.block(i).equation
|
||||
% M_.block_structure.block(i).variable
|
||||
ghx(M_.block_structure.block(i).equation, M_.block_structure.block(i).variable(find(M_.block_structure.block(i).lead_lag_incidence(1: M_.block_structure.block(i).maximum_endo_lag,:))) ) = M_.block_structure.block(i).dr.ghx;
|
||||
if(M_.block_structure.block(i).exo_nbr)
|
||||
nu = nu + size(M_.block_structure.block(i).dr.ghu,2);
|
||||
ghu(M_.block_structure.block(i).equation, M_.block_structure.block(i).exogenous) = M_.block_structure.block(i).dr.ghu;
|
||||
end
|
||||
k_tmp = find(M_.block_structure.block(i).dr.kstate(:,2) <= M_.block_structure.block(i).maximum_lag+1);
|
||||
k = [k ; k_tmp];
|
||||
klag = [klag ; M_.block_structure.block(i).dr.kstate(k_tmp,[1 2])];
|
||||
k1 = [k1 ; M_.block_structure.block(i).variable(M_.block_structure.block(i).dr.order_var)'];
|
||||
end
|
||||
nvar = size(var_list,1);
|
||||
if nvar == 0
|
||||
nvar = length(k1);
|
||||
ivar = [1:nvar];
|
||||
else
|
||||
ivar=zeros(nvar,1);
|
||||
for i=1:nvar
|
||||
i_tmp = strmatch(var_list(i,:),M_.endo_names(k1,:),'exact');
|
||||
if isempty(i_tmp)
|
||||
disp(var_list(i,:));
|
||||
error (['One of the variable specified does not exist']) ;
|
||||
else
|
||||
ivar(i) = i_tmp;
|
||||
end
|
||||
end
|
||||
end
|
||||
disp('POLICY AND TRANSITION FUNCTIONS')
|
||||
% variable names
|
||||
str = ' ';
|
||||
for i=1:nvar
|
||||
str = [str sprintf('%16s',M_.endo_names(k1(ivar(i)),:))];
|
||||
end
|
||||
disp(str);
|
||||
%
|
||||
% constant
|
||||
%
|
||||
str = 'Constant ';
|
||||
flag = 0;
|
||||
for i=1:nvar
|
||||
x = dr.ys(k1(ivar(i)));
|
||||
if order > 1
|
||||
x = x + dr.ghs2(ivar(i))/2;
|
||||
end
|
||||
if abs(x) > 1e-6
|
||||
flag = 1;
|
||||
str = [str sprintf('%16.6f',x)];
|
||||
else
|
||||
str = [str ' 0'];
|
||||
end
|
||||
end
|
||||
if flag
|
||||
disp(str)
|
||||
end
|
||||
if order > 1
|
||||
str = '(correction) ';
|
||||
flag = 0;
|
||||
for i=1:nvar
|
||||
x = dr.ghs2(ivar(i))/2;
|
||||
if abs(x) > 1e-6
|
||||
flag = 1;
|
||||
str = [str sprintf('%16.6f',x)];
|
||||
else
|
||||
str = [str ' 0'];
|
||||
end
|
||||
end
|
||||
if flag
|
||||
disp(str)
|
||||
end
|
||||
end
|
||||
%
|
||||
% ghx
|
||||
%
|
||||
for k=1:nx
|
||||
flag = 0;
|
||||
str1 = sprintf('%s(%d)',M_.endo_names(k1(klag(k,1)),:),klag(k,2)-M_.maximum_lag-2);
|
||||
str = sprintf('%-20s',str1);
|
||||
for i=1:nvar
|
||||
x = ghx(ivar(i),k);
|
||||
if abs(x) > 1e-6
|
||||
flag = 1;
|
||||
str = [str sprintf('%16.6f',x)];
|
||||
else
|
||||
str = [str ' 0'];
|
||||
end
|
||||
end
|
||||
if flag
|
||||
disp(str)
|
||||
end
|
||||
end
|
||||
%
|
||||
% ghu
|
||||
%
|
||||
for k=1:nu
|
||||
flag = 0;
|
||||
str = sprintf('%-20s',M_.exo_names(k,:));
|
||||
for i=1:nvar
|
||||
x = ghu(ivar(i),k);
|
||||
if abs(x) > 1e-6
|
||||
flag = 1;
|
||||
str = [str sprintf('%16.6f',x)];
|
||||
else
|
||||
str = [str ' 0'];
|
||||
end
|
||||
end
|
||||
if flag
|
||||
disp(str)
|
||||
end
|
||||
end
|
||||
|
||||
if order > 1
|
||||
% ghxx
|
||||
for k = 1:nx
|
||||
for j = 1:k
|
||||
flag = 0;
|
||||
str1 = sprintf('%s(%d),%s(%d)',M_.endo_names(k1(klag(k,1)),:),klag(k,2)-M_.maximum_lag-2, ...
|
||||
M_.endo_names(k1(klag(j,1)),:),klag(j,2)-M_.maximum_lag-2);
|
||||
str = sprintf('%-20s',str1);
|
||||
for i=1:nvar
|
||||
if k == j
|
||||
x = dr.ghxx(ivar(i),(k-1)*nx+j)/2;
|
||||
else
|
||||
x = dr.ghxx(ivar(i),(k-1)*nx+j);
|
||||
end
|
||||
if abs(x) > 1e-6
|
||||
flag = 1;
|
||||
str = [str sprintf('%16.6f',x)];
|
||||
else
|
||||
str = [str ' 0'];
|
||||
end
|
||||
end
|
||||
if flag
|
||||
disp(str)
|
||||
end
|
||||
end
|
||||
end
|
||||
%
|
||||
% ghuu
|
||||
%
|
||||
for k = 1:nu
|
||||
for j = 1:k
|
||||
flag = 0;
|
||||
str = sprintf('%-20s',[M_.exo_names(k,:) ',' M_.exo_names(j,:)] );
|
||||
for i=1:nvar
|
||||
if k == j
|
||||
x = dr.ghuu(ivar(i),(k-1)*nu+j)/2;
|
||||
else
|
||||
x = dr.ghuu(ivar(i),(k-1)*nu+j);
|
||||
end
|
||||
if abs(x) > 1e-6
|
||||
flag = 1;
|
||||
str = [str sprintf('%16.6f',x)];
|
||||
else
|
||||
str = [str ' 0'];
|
||||
end
|
||||
end
|
||||
if flag
|
||||
disp(str)
|
||||
end
|
||||
end
|
||||
end
|
||||
%
|
||||
% ghxu
|
||||
%
|
||||
for k = 1:nx
|
||||
for j = 1:nu
|
||||
flag = 0;
|
||||
str1 = sprintf('%s(%d),%s',M_.endo_names(k1(klag(k,1)),:),klag(k,2)-M_.maximum_lag-2, ...
|
||||
M_.exo_names(j,:));
|
||||
str = sprintf('%-20s',str1);
|
||||
for i=1:nvar
|
||||
x = dr.ghxu(ivar(i),(k-1)*nu+j);
|
||||
if abs(x) > 1e-6
|
||||
flag = 1;
|
||||
str = [str sprintf('%16.6f',x)];
|
||||
else
|
||||
str = [str ' 0'];
|
||||
end
|
||||
end
|
||||
if flag
|
||||
disp(str)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
% $$$ dr.ghx
|
||||
% $$$ dr.ghu
|
||||
% $$$ dr.ghxx
|
||||
% $$$ dr.ghuu
|
||||
% $$$ dr.ghxu
|
||||
|
||||
% 01/08/2001 MJ added test for order in printing quadratic terms
|
||||
% 02/21/2001 MJ pass all variable names through deblank()
|
||||
% 02/21/2001 MJ changed from f to g format to write numbers
|
||||
% 10/09/2002 MJ corrected error on constant whith subset of variables
|
||||
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ function [dr,info,M_,options_,oo_] = dr11_sparse(dr,task,M_,options_,oo_, jacobi
|
|||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
%task
|
||||
info = 0;
|
||||
klen = M_.maximum_endo_lag + M_.maximum_endo_lead + 1;
|
||||
kstate = dr.kstate;
|
||||
|
@ -46,7 +46,12 @@ function [dr,info,M_,options_,oo_] = dr11_sparse(dr,task,M_,options_,oo_, jacobi
|
|||
m = m+length(k);
|
||||
end
|
||||
if M_.exo_nbr & task~=1
|
||||
jacobia_
|
||||
jacobia_(:,nz+1:end)
|
||||
b
|
||||
dr.ghu = -b\jacobia_(:,nz+1:end);
|
||||
disp(['nz=' int2str(nz) ]);
|
||||
dr.ghu
|
||||
end
|
||||
dr.eigval = eig(transition_matrix(dr,M_));
|
||||
dr.rank = 0;
|
||||
|
@ -156,12 +161,15 @@ function [dr,info,M_,options_,oo_] = dr11_sparse(dr,task,M_,options_,oo_, jacobi
|
|||
|
||||
k1 = find(kstate(n4:nd,2) == M_.maximum_endo_lag+1);
|
||||
k2 = find(kstate(1:n3,2) == M_.maximum_endo_lag+2);
|
||||
hx(k1,:)
|
||||
gx(k2(nboth+1:end),:)
|
||||
dr.ghx = [hx(k1,:); gx(k2(nboth+1:end),:)];
|
||||
|
||||
dr.ghx
|
||||
%lead variables actually present in the model
|
||||
j3 = nonzeros(kstate(:,3));
|
||||
j4 = find(kstate(:,3));
|
||||
% derivatives with respect to exogenous variables
|
||||
disp(['M_.exo_nbr=' int2str(M_.exo_nbr)]);
|
||||
if M_.exo_nbr
|
||||
fu = aa(:,nz+(1:M_.exo_nbr));
|
||||
a1 = b;
|
||||
|
@ -216,7 +224,6 @@ function [dr,info,M_,options_,oo_] = dr11_sparse(dr,task,M_,options_,oo_, jacobi
|
|||
dr.ghud{i} = -M2*dr.ghud{i-1}(end-nyf+1:end,:);
|
||||
end
|
||||
end
|
||||
disp('end0');
|
||||
if options_.order == 1
|
||||
return
|
||||
end
|
||||
|
@ -479,5 +486,4 @@ function [dr,info,M_,options_,oo_] = dr11_sparse(dr,task,M_,options_,oo_, jacobi
|
|||
end
|
||||
|
||||
end
|
||||
disp('end');
|
||||
end
|
|
@ -210,23 +210,47 @@ function [dr,info,M_,options_,oo_] = dr1_sparse(dr,task,M_,options_,oo_)
|
|||
if options_.order == 1
|
||||
[junk,jacobia_] = feval([M_.fname '_dynamic'],ones(M_.maximum_lag+M_.maximum_lead+1,1)*dr.ys',[oo_.exo_simul ...
|
||||
oo_.exo_det_simul], it_);
|
||||
%full(jacobia_)
|
||||
dr.eigval = [];
|
||||
dr.nyf = 0;
|
||||
dr.rank = 0;
|
||||
first_col_exo = M_.endo_nbr * (M_.maximum_endo_lag + M_.maximum_endo_lead + 1);
|
||||
for i=1:length(M_.block_structure.block)
|
||||
%disp(['block = ' int2str(i)]);
|
||||
M_.block_structure.block(i).dr.Null=0;
|
||||
M_.block_structure.block(i).dr=set_state_space(M_.block_structure.block(i).dr,M_.block_structure.block(i));
|
||||
col_selector=repmat(M_.block_structure.block(i).variable,1,M_.block_structure.block(i).maximum_endo_lag+M_.block_structure.block(i).maximum_endo_lead+1)+kron([M_.maximum_endo_lag-M_.block_structure.block(i).maximum_endo_lag:M_.maximum_endo_lag+M_.block_structure.block(i).maximum_endo_lead],M_.endo_nbr*ones(1,M_.block_structure.block(i).endo_nbr));
|
||||
row_selector = M_.block_structure.block(i).equation;
|
||||
%col_selector
|
||||
jcb_=jacobia_(row_selector,col_selector);
|
||||
jcb_ = jcb_(:,find(M_.block_structure.block(i).lead_lag_incidence')) ;
|
||||
jcb_ = jcb_(:,find(M_.block_structure.block(i).lead_lag_incidence')) ;
|
||||
if M_.block_structure.block(i).exo_nbr>0
|
||||
col_selector = [ first_col_exo + ...
|
||||
repmat(M_.block_structure.block(i).exogenous,1,M_.block_structure.block(i).maximum_exo_lag+M_.block_structure.block(i).maximum_exo_lead+1)+kron([M_.maximum_exo_lag-M_.block_structure.block(i).maximum_exo_lag:M_.maximum_exo_lag+M_.block_structure.block(i).maximum_exo_lead],M_.exo_nbr*ones(1,M_.block_structure.block(i).exo_nbr))];
|
||||
end
|
||||
%col_selector
|
||||
jcb_ = [ jcb_ jacobia_(row_selector,col_selector)];
|
||||
%full(jcb_)
|
||||
|
||||
hss_=0; %hessian(M_.block_structure.block(i).equation,M_.block_structure.block(i).variable);
|
||||
dra = M_.block_structure.block(i).dr;
|
||||
M_.block_structure.block(i).exo_nbr=M_.exo_nbr;
|
||||
%M_.block_structure.block(i).exo_nbr=M_.exo_nbr;
|
||||
[dra ,info,M_.block_structure.block(i),options_,oo_] = dr11_sparse(dra ,task,M_.block_structure.block(i),options_,oo_, jcb_, hss_);
|
||||
M_.block_structure.block(i).dr = dra;
|
||||
dr.eigval = [dr.eigval; dra.eigval];
|
||||
dr.nyf = dr.nyf + nnz(dra.kstate(:,2)>M_.block_structure.block(i).maximum_endo_lag+1);
|
||||
nyf = nnz(dra.kstate(:,2)>M_.block_structure.block(i).maximum_endo_lag+1);
|
||||
n_explod = nnz(abs(dra.eigval) > options_.qz_criterium);
|
||||
if nyf ~= n_explod
|
||||
disp(['EIGENVALUES in block ' int2str(i) ':']);
|
||||
[m_lambda,ii]=sort(abs(dra.eigval));
|
||||
disp(sprintf('%16s %16s %16s\n','Modulus','Real','Imaginary'))
|
||||
z=[m_lambda real(dra.eigval(ii)) imag(dra.eigval(ii))]';
|
||||
disp(sprintf('%16.4g %16.4g %16.4g\n',z))
|
||||
disp(['The rank condition is not satisfy in block ' int2str(i) ' :']);
|
||||
disp([' ' int2str(nyf) ' forward-looking variable(s) for ' ...
|
||||
int2str(n_explod) ' eigenvalue(s) larger than 1 in modulus']);
|
||||
end
|
||||
dr.nyf = dr.nyf + nyf;
|
||||
dr.rank = dr.rank + dra.rank;
|
||||
end;
|
||||
end
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,295 @@
|
|||
function info=stoch_simul(var_list)
|
||||
|
||||
% Copyright (C) 2001-2008 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
global M_ options_ oo_ it_
|
||||
|
||||
options_old = options_;
|
||||
if options_.linear
|
||||
options_.order = 1;
|
||||
end
|
||||
if (options_.order == 1)
|
||||
options_.replic = 1;
|
||||
end
|
||||
|
||||
|
||||
TeX = options_.TeX;
|
||||
|
||||
iter_ = max(options_.periods,1);
|
||||
if M_.exo_nbr > 0
|
||||
oo_.exo_simul= ones(iter_ + M_.maximum_lag + M_.maximum_lead,1) * oo_.exo_steady_state';
|
||||
end
|
||||
|
||||
check_model;
|
||||
|
||||
[oo_.dr, info] = resol(oo_.steady_state,0);
|
||||
|
||||
if info(1)
|
||||
options_ = options_old;
|
||||
print_info(info);
|
||||
return
|
||||
end
|
||||
|
||||
oo_dr_kstate = [];
|
||||
oo_dr_nstatic = 0;
|
||||
for i=1:length(M_.block_structure.block)
|
||||
oo_dr_kstate = [ oo_dr_kstate ; M_.block_structure.block(i).dr.kstate];
|
||||
oo_dr_nstatic = oo_dr_nstatic + M_.block_structure.block(i).dr.nstatic;
|
||||
end
|
||||
|
||||
if ~options_.noprint
|
||||
disp(' ')
|
||||
disp('MODEL SUMMARY')
|
||||
disp(' ')
|
||||
disp([' Number of variables: ' int2str(M_.endo_nbr)])
|
||||
disp([' Number of stochastic shocks: ' int2str(M_.exo_nbr)])
|
||||
disp([' Number of state variables: ' ...
|
||||
int2str(length(find(oo_dr_kstate(:,2) <= M_.maximum_lag+1)))])
|
||||
disp([' Number of jumpers: ' ...
|
||||
int2str(length(find(oo_dr_kstate(:,2) == M_.maximum_lag+2)))])
|
||||
disp([' Number of static variables: ' int2str(oo_dr_nstatic)])
|
||||
my_title='MATRIX OF COVARIANCE OF EXOGENOUS SHOCKS';
|
||||
labels = deblank(M_.exo_names);
|
||||
headers = strvcat('Variables',labels);
|
||||
lh = size(labels,2)+2;
|
||||
table(my_title,headers,labels,M_.Sigma_e,lh,10,6);
|
||||
disp(' ')
|
||||
disp_dr_sparse(oo_.dr,options_.order,var_list);
|
||||
end
|
||||
|
||||
if options_.simul == 0 & options_.nomoments == 0
|
||||
disp_th_moments(oo_.dr,var_list);
|
||||
elseif options_.simul == 1
|
||||
if options_.periods == 0
|
||||
error('STOCH_SIMUL error: number of periods for the simulation isn''t specified')
|
||||
end
|
||||
if options_.periods < options_.drop
|
||||
disp(['STOCH_SIMUL error: The horizon of simulation is shorter' ...
|
||||
' than the number of observations to be DROPed'])
|
||||
options_ =options_old;
|
||||
return
|
||||
end
|
||||
oo_.endo_simul = simult(repmat(oo_.dr.ys,1,M_.maximum_lag),oo_.dr);
|
||||
dyn2vec;
|
||||
if options_.nomoments == 0
|
||||
disp_moments(oo_.endo_simul,var_list);
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
if options_.irf
|
||||
n = size(var_list,1);
|
||||
if n == 0
|
||||
n = M_.endo_nbr;
|
||||
ivar = [1:n]';
|
||||
var_list = M_.endo_names;
|
||||
if TeX
|
||||
var_listTeX = M_.endo_names_tex;
|
||||
end
|
||||
else
|
||||
ivar=zeros(n,1);
|
||||
if TeX
|
||||
var_listTeX = [];
|
||||
end
|
||||
for i=1:n
|
||||
i_tmp = strmatch(var_list(i,:),M_.endo_names,'exact');
|
||||
if isempty(i_tmp)
|
||||
error (['One of the specified variables does not exist']) ;
|
||||
else
|
||||
ivar(i) = i_tmp;
|
||||
if TeX
|
||||
var_listTeX = strvcat(var_listTeX,deblank(M_.endo_names_tex(i_tmp,:)));
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if TeX
|
||||
fidTeX = fopen([M_.fname '_IRF.TeX'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by stoch_simul.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
|
||||
fprintf(fidTeX,' \n');
|
||||
end
|
||||
olditer = iter_;% Est-ce vraiment utile ? Il y a la même ligne dans irf...
|
||||
SS(M_.exo_names_orig_ord,M_.exo_names_orig_ord)=M_.Sigma_e+1e-14*eye(M_.exo_nbr);
|
||||
cs = transpose(chol(SS));
|
||||
tit(M_.exo_names_orig_ord,:) = M_.exo_names;
|
||||
if TeX
|
||||
titTeX(M_.exo_names_orig_ord,:) = M_.exo_names_tex;
|
||||
end
|
||||
for i=1:M_.exo_nbr
|
||||
if SS(i,i) > 1e-13
|
||||
y=irf(oo_.dr,cs(M_.exo_names_orig_ord,i), options_.irf, options_.drop, ...
|
||||
options_.replic, options_.order);
|
||||
if options_.relative_irf
|
||||
y = 100*y/cs(i,i);
|
||||
end
|
||||
irfs = [];
|
||||
mylist = [];
|
||||
if TeX
|
||||
mylistTeX = [];
|
||||
end
|
||||
for j = 1:n
|
||||
assignin('base',[deblank(M_.endo_names(ivar(j),:)) '_' deblank(M_.exo_names(i,:))],...
|
||||
y(ivar(j),:)');
|
||||
eval(['oo_.irfs.' deblank(M_.endo_names(ivar(j),:)) '_' ...
|
||||
deblank(M_.exo_names(i,:)) ' = y(ivar(j),:);']);
|
||||
if max(y(ivar(j),:)) - min(y(ivar(j),:)) > 1e-10
|
||||
irfs = cat(1,irfs,y(ivar(j),:));
|
||||
mylist = strvcat(mylist,deblank(var_list(j,:)));
|
||||
if TeX
|
||||
mylistTeX = strvcat(mylistTeX,deblank(var_listTeX(j,:)));
|
||||
end
|
||||
end
|
||||
end
|
||||
if options_.nograph == 0
|
||||
number_of_plots_to_draw = size(irfs,1);
|
||||
[nbplt,nr,nc,lr,lc,nstar] = pltorg(number_of_plots_to_draw);
|
||||
if nbplt == 0
|
||||
elseif nbplt == 1
|
||||
if options_.relative_irf
|
||||
hh = figure('Name',['Relative response to' ...
|
||||
' orthogonalized shock to ' tit(i,:)]);
|
||||
else
|
||||
hh = figure('Name',['Orthogonalized shock to' ...
|
||||
' ' tit(i,:)]);
|
||||
end
|
||||
for j = 1:number_of_plots_to_draw
|
||||
subplot(nr,nc,j);
|
||||
plot(1:options_.irf,transpose(irfs(j,:)),'-k','linewidth',1);
|
||||
hold on
|
||||
plot([1 options_.irf],[0 0],'-r','linewidth',0.5);
|
||||
hold off
|
||||
xlim([1 options_.irf]);
|
||||
title(deblank(mylist(j,:)),'Interpreter','none');
|
||||
end
|
||||
eval(['print -depsc2 ' M_.fname '_IRF_' deblank(tit(i,:)) '.eps']);
|
||||
if ~exist('OCTAVE_VERSION')
|
||||
eval(['print -dpdf ' M_.fname '_IRF_' deblank(tit(i,:))]);
|
||||
saveas(hh,[M_.fname '_IRF_' deblank(tit(i,:)) '.fig']);
|
||||
end
|
||||
if TeX
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
for j = 1:number_of_plots_to_draw
|
||||
fprintf(fidTeX,['\\psfrag{%s}[1][][0.5][0]{$%s$}\n'],deblank(mylist(j,:)),deblank(mylistTeX(j,:)));
|
||||
end
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_IRF_%s}\n',M_.fname,deblank(tit(i,:)));
|
||||
fprintf(fidTeX,'\\caption{Impulse response functions (orthogonalized shock to $%s$).}',titTeX(i,:));
|
||||
fprintf(fidTeX,'\\label{Fig:IRF:%s}\n',deblank(tit(i,:)));
|
||||
fprintf(fidTeX,'\\end{figure}\n');
|
||||
fprintf(fidTeX,' \n');
|
||||
end
|
||||
% close(hh)
|
||||
else
|
||||
for fig = 1:nbplt-1
|
||||
if options_.relative_irf == 1
|
||||
hh = figure('Name',['Relative response to orthogonalized shock' ...
|
||||
' to ' tit(i,:) ' figure ' int2str(fig)]);
|
||||
else
|
||||
hh = figure('Name',['Orthogonalized shock to ' tit(i,:) ...
|
||||
' figure ' int2str(fig)]);
|
||||
end
|
||||
for plt = 1:nstar
|
||||
subplot(nr,nc,plt);
|
||||
plot(1:options_.irf,transpose(irfs((fig-1)*nstar+plt,:)),'-k','linewidth',1);
|
||||
hold on
|
||||
plot([1 options_.irf],[0 0],'-r','linewidth',0.5);
|
||||
hold off
|
||||
xlim([1 options_.irf]);
|
||||
title(deblank(mylist((fig-1)*nstar+plt,:)),'Interpreter','none');
|
||||
end
|
||||
eval(['print -depsc2 ' M_.fname '_IRF_' deblank(tit(i,:)) int2str(fig) '.eps']);
|
||||
if ~exist('OCTAVE_VERSION')
|
||||
eval(['print -dpdf ' M_.fname '_IRF_' deblank(tit(i,:)) int2str(fig)]);
|
||||
saveas(hh,[M_.fname '_IRF_' deblank(tit(i,:)) int2str(fig) '.fig']);
|
||||
end
|
||||
if TeX
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
for j = 1:nstar
|
||||
fprintf(fidTeX,['\\psfrag{%s}[1][][0.5][0]{$%s$}\n'],deblank(mylist((fig-1)*nstar+j,:)),deblank(mylistTeX((fig-1)*nstar+j,:)));
|
||||
end
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_IRF_%s%s}\n',M_.fname,deblank(tit(i,:)),int2str(fig));
|
||||
if options_.relative_irf
|
||||
fprintf(fidTeX,['\\caption{Relative impulse response' ...
|
||||
' functions (orthogonalized shock to $%s$).}'],deblank(titTeX(i,:)));
|
||||
else
|
||||
fprintf(fidTeX,['\\caption{Impulse response functions' ...
|
||||
' (orthogonalized shock to $%s$).}'],deblank(titTeX(i,:)));
|
||||
end
|
||||
fprintf(fidTeX,'\\label{Fig:BayesianIRF:%s:%s}\n',deblank(tit(i,:)),int2str(fig));
|
||||
fprintf(fidTeX,'\\end{figure}\n');
|
||||
fprintf(fidTeX,' \n');
|
||||
end
|
||||
% close(hh);
|
||||
end
|
||||
hh = figure('Name',['Orthogonalized shock to ' tit(i,:) ' figure ' int2str(nbplt) '.']);
|
||||
m = 0;
|
||||
for plt = 1:number_of_plots_to_draw-(nbplt-1)*nstar;
|
||||
m = m+1;
|
||||
subplot(lr,lc,m);
|
||||
plot(1:options_.irf,transpose(irfs((nbplt-1)*nstar+plt,:)),'-k','linewidth',1);
|
||||
hold on
|
||||
plot([1 options_.irf],[0 0],'-r','linewidth',0.5);
|
||||
hold off
|
||||
xlim([1 options_.irf]);
|
||||
title(deblank(mylist((nbplt-1)*nstar+plt,:)),'Interpreter','none');
|
||||
end
|
||||
eval(['print -depsc2 ' M_.fname '_IRF_' deblank(tit(i,:)) int2str(nbplt) '.eps']);
|
||||
if ~exist('OCTAVE_VERSION')
|
||||
eval(['print -dpdf ' M_.fname '_IRF_' deblank(tit(i,:)) int2str(nbplt)]);
|
||||
saveas(hh,[M_.fname '_IRF_' deblank(tit(i,:)) int2str(nbplt) '.fig']);
|
||||
end
|
||||
if TeX
|
||||
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
||||
for j = 1:m
|
||||
fprintf(fidTeX,['\\psfrag{%s}[1][][0.5][0]{$%s$}\n'],deblank(mylist((nbplt-1)*nstar+j,:)),deblank(mylistTeX((nbplt-1)*nstar+j,:)));
|
||||
end
|
||||
fprintf(fidTeX,'\\centering \n');
|
||||
fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_IRF_%s%s}\n',M_.fname,deblank(tit(i,:)),int2str(nbplt));
|
||||
if options_.relative_irf
|
||||
fprintf(fidTeX,['\\caption{Relative impulse response functions' ...
|
||||
' (orthogonalized shock to $%s$).}'],deblank(titTeX(i,:)));
|
||||
else
|
||||
fprintf(fidTeX,['\\caption{Impulse response functions' ...
|
||||
' (orthogonalized shock to $%s$).}'],deblank(titTeX(i,:)));
|
||||
end
|
||||
fprintf(fidTeX,'\\label{Fig:IRF:%s:%s}\n',deblank(tit(i,:)),int2str(nbplt));
|
||||
fprintf(fidTeX,'\\end{figure}\n');
|
||||
fprintf(fidTeX,' \n');
|
||||
end
|
||||
% close(hh);
|
||||
end
|
||||
end
|
||||
end
|
||||
iter_ = olditer;
|
||||
if TeX
|
||||
fprintf(fidTeX,' \n');
|
||||
fprintf(fidTeX,'%% End Of TeX file. \n');
|
||||
fclose(fidTeX);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if options_.SpectralDensity == 1
|
||||
[omega,f] = UnivariateSpectralDensity(oo_.dr,var_list);
|
||||
end
|
||||
|
||||
|
||||
options_ = options_old;
|
Binary file not shown.
|
@ -193,12 +193,12 @@ Interpreter::compute_block_time() /*throw(EvalException)*/
|
|||
mexEvalString("drawnow;");
|
||||
#endif
|
||||
y[(it_+lag)*y_size+var] = Stack.top();
|
||||
#ifdef DEBUGC
|
||||
if(var==153)
|
||||
{
|
||||
mexPrintf(" FSTP y[var=%d,time=%d,lag=%d,%d]=%f\n",var,it_,lag,(it_+lag)*y_size+var,y[(it_+lag)*y_size+var]);
|
||||
mexEvalString("drawnow;");
|
||||
}
|
||||
#ifdef DEBUGC
|
||||
mexPrintf("%f\n",y[(it_+lag)*y_size+var]);
|
||||
mexEvalString("drawnow;");
|
||||
#endif
|
||||
|
|
|
@ -601,6 +601,7 @@ void SparseMatrix::Init(int periods, int y_kmin, int y_kmax, int Size, std::map<
|
|||
mexEvalString("drawnow;");
|
||||
#endif
|
||||
tmp_b+=u[it4->second+u_count_init*t]*y[index_vara[var+Size*(y_kmin+t)]];
|
||||
//mexPrintf(" u[%d](%f)*y[%d](%f)=%f",it4->second+u_count_init*t,u[it4->second+u_count_init*t],index_vara[var+Size*(y_kmin+t)],y[index_vara[var+Size*(y_kmin+t)]],u[it4->second+u_count_init*t]*y[index_vara[var+Size*(y_kmin+t)]]);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -610,6 +611,7 @@ void SparseMatrix::Init(int periods, int y_kmin, int y_kmax, int Size, std::map<
|
|||
#endif
|
||||
b[eq]=it4->second+u_count_init*t;
|
||||
u[b[eq]]+=tmp_b;
|
||||
//mexPrintf("u[%d]=%f corr=%f\n",b[eq],u[b[eq]],tmp_b);
|
||||
#ifdef PRINT_OUT
|
||||
mexPrintf("=> b[%d]=%f\n", eq, u[b[eq]]);
|
||||
mexEvalString("drawnow;");
|
||||
|
@ -626,6 +628,7 @@ void SparseMatrix::Init(int periods, int y_kmin, int y_kmax, int Size, std::map<
|
|||
mexPrintf("end of Init\n");
|
||||
mexEvalString("drawnow;");
|
||||
#endif
|
||||
//mexEvalString("Init");
|
||||
mxFree(temp_NZE_R);
|
||||
mxFree(temp_NZE_C);
|
||||
}
|
||||
|
@ -641,7 +644,7 @@ void SparseMatrix::ShortInit(int periods, int y_kmin, int y_kmax, int Size, std:
|
|||
#ifdef PRINT_OUT
|
||||
mexPrintf("t=%d\n",t);
|
||||
#endif
|
||||
int ti_y_kmin=-min( t , y_kmin);
|
||||
int ti_y_kmin=-min( t , y_kmin);
|
||||
int ti_y_kmax= min( periods-(t+1), y_kmax);
|
||||
it4=IM.begin();
|
||||
eq=-1;
|
||||
|
@ -681,6 +684,7 @@ void SparseMatrix::ShortInit(int periods, int y_kmin, int y_kmax, int Size, std:
|
|||
#endif
|
||||
b[eq]=it4->second+u_count_init*t;
|
||||
u[b[eq]]+=tmp_b;
|
||||
//mexPrintf("u[%d]=%f\n",b[eq],u[b[eq]]);
|
||||
#ifdef PRINT_OUT
|
||||
mexPrintf("=> b[%d]=%f\n", eq, u[b[eq]]);
|
||||
#endif
|
||||
|
@ -691,6 +695,7 @@ void SparseMatrix::ShortInit(int periods, int y_kmin, int y_kmax, int Size, std:
|
|||
it4++;
|
||||
}
|
||||
}
|
||||
//mexPrintf("ShortInit\n");
|
||||
}
|
||||
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -169,7 +169,11 @@ StochSimulStatement::writeOutput(ostream &output, const string &basename) const
|
|||
{
|
||||
options_list.writeOutput(output);
|
||||
symbol_list.writeOutput("var_list_", output);
|
||||
output << "info = stoch_simul(var_list_);\n";
|
||||
output << "if(options_.model_mode)\n";
|
||||
output << " info = stoch_simul_sparse(var_list_);\n";
|
||||
output << "else\n";
|
||||
output << " info = stoch_simul(var_list_);\n";
|
||||
output << "end\n";
|
||||
}
|
||||
|
||||
ForecastStatement::ForecastStatement(const SymbolList &symbol_list_arg,
|
||||
|
|
|
@ -164,6 +164,12 @@ NumConstNode::collectEndogenous(set<pair<int, int> > &result) const
|
|||
{
|
||||
}
|
||||
|
||||
void
|
||||
NumConstNode::collectExogenous(set<pair<int, int> > &result) const
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
VariableNode::VariableNode(DataTree &datatree_arg, int symb_id_arg, SymbolType type_arg, int lag_arg) :
|
||||
ExprNode(datatree_arg),
|
||||
symb_id(symb_id_arg),
|
||||
|
@ -473,6 +479,14 @@ VariableNode::collectEndogenous(set<pair<int, int> > &result) const
|
|||
result.insert(make_pair(symb_id, lag));
|
||||
}
|
||||
|
||||
void
|
||||
VariableNode::collectExogenous(set<pair<int, int> > &result) const
|
||||
{
|
||||
if (type == eExogenous)
|
||||
result.insert(make_pair(symb_id, lag));
|
||||
}
|
||||
|
||||
|
||||
UnaryOpNode::UnaryOpNode(DataTree &datatree_arg, UnaryOpcode op_code_arg, const NodeID arg_arg) :
|
||||
ExprNode(datatree_arg),
|
||||
arg(arg_arg),
|
||||
|
@ -864,6 +878,13 @@ UnaryOpNode::collectEndogenous(set<pair<int, int> > &result) const
|
|||
arg->collectEndogenous(result);
|
||||
}
|
||||
|
||||
void
|
||||
UnaryOpNode::collectExogenous(set<pair<int, int> > &result) const
|
||||
{
|
||||
arg->collectExogenous(result);
|
||||
}
|
||||
|
||||
|
||||
BinaryOpNode::BinaryOpNode(DataTree &datatree_arg, const NodeID arg1_arg,
|
||||
BinaryOpcode op_code_arg, const NodeID arg2_arg) :
|
||||
ExprNode(datatree_arg),
|
||||
|
@ -1322,6 +1343,14 @@ BinaryOpNode::collectEndogenous(set<pair<int, int> > &result) const
|
|||
arg2->collectEndogenous(result);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BinaryOpNode::collectExogenous(set<pair<int, int> > &result) const
|
||||
{
|
||||
arg1->collectExogenous(result);
|
||||
arg2->collectExogenous(result);
|
||||
}
|
||||
|
||||
TrinaryOpNode::TrinaryOpNode(DataTree &datatree_arg, const NodeID arg1_arg,
|
||||
TrinaryOpcode op_code_arg, const NodeID arg2_arg, const NodeID arg3_arg) :
|
||||
ExprNode(datatree_arg),
|
||||
|
@ -1334,7 +1363,7 @@ TrinaryOpNode::TrinaryOpNode(DataTree &datatree_arg, const NodeID arg1_arg,
|
|||
|
||||
// Non-null derivatives are the union of those of the arguments
|
||||
// Compute set union of arg{1,2,3}->non_null_derivatives
|
||||
set<int> non_null_derivatives_tmp;
|
||||
set<int> non_null_derivatives_tmp;
|
||||
set_union(arg1->non_null_derivatives.begin(),
|
||||
arg1->non_null_derivatives.end(),
|
||||
arg2->non_null_derivatives.begin(),
|
||||
|
@ -1590,6 +1619,15 @@ TrinaryOpNode::collectEndogenous(set<pair<int, int> > &result) const
|
|||
arg3->collectEndogenous(result);
|
||||
}
|
||||
|
||||
void
|
||||
TrinaryOpNode::collectExogenous(set<pair<int, int> > &result) const
|
||||
{
|
||||
arg1->collectExogenous(result);
|
||||
arg2->collectExogenous(result);
|
||||
arg3->collectExogenous(result);
|
||||
}
|
||||
|
||||
|
||||
UnknownFunctionNode::UnknownFunctionNode(DataTree &datatree_arg,
|
||||
int symb_id_arg,
|
||||
const vector<NodeID> &arguments_arg) :
|
||||
|
@ -1650,6 +1688,15 @@ UnknownFunctionNode::collectEndogenous(set<pair<int, int> > &result) const
|
|||
(*it)->collectEndogenous(result);
|
||||
}
|
||||
|
||||
void
|
||||
UnknownFunctionNode::collectExogenous(set<pair<int, int> > &result) const
|
||||
{
|
||||
for(vector<NodeID>::const_iterator it = arguments.begin();
|
||||
it != arguments.end(); it++)
|
||||
(*it)->collectExogenous(result);
|
||||
}
|
||||
|
||||
|
||||
double
|
||||
UnknownFunctionNode::eval(const eval_context_type &eval_context) const throw (EvalException)
|
||||
{
|
||||
|
|
|
@ -69,7 +69,7 @@ ModFile::checkPass()
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (mod_file_struct.simul_present && stochastic_statement_present)
|
||||
if (mod_file_struct.simul_present && stochastic_statement_present && model_tree.mode==0)
|
||||
{
|
||||
cerr << "ERROR: A .mod file cannot contain both a simul command and one of {stoch_simul, estimation, forecast, osr, ramsey_policy}" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -169,7 +169,7 @@ ParsingDriver::add_model_variable(string *name, string *olag)
|
|||
if (type == eUnknownFunction)
|
||||
error("Symbol " + *name + " is a function name unknown to Dynare. It cannot be used inside model.");
|
||||
|
||||
if (type == eExogenous && lag != 0)
|
||||
if (type == eExogenous && lag != 0 && (model_tree->mode != eSparseDLLMode && model_tree->mode != eSparseMode))
|
||||
warning("Exogenous variable " + *name + " has lead/lag " + *olag);
|
||||
|
||||
if (type == eModelLocalVariable && lag != 0)
|
||||
|
@ -179,9 +179,13 @@ ParsingDriver::add_model_variable(string *name, string *olag)
|
|||
|
||||
NodeID id = model_tree->AddVariable(*name, lag);
|
||||
|
||||
if ((type == eEndogenous) && (model_tree->mode == eSparseDLLMode || model_tree->mode == eSparseMode))
|
||||
model_tree->block_triangular.fill_IM(model_tree->equation_number(), mod_file->symbol_table.getID(*name), lag);
|
||||
|
||||
/*if (model_tree->mode == eSparseDLLMode || model_tree->mode == eSparseMode)
|
||||
{
|
||||
if (type == eEndogenous)
|
||||
model_tree->block_triangular.fill_IM(model_tree->equation_number(), mod_file->symbol_table.getID(*name), lag);
|
||||
if (type == eExogenous)
|
||||
model_tree->block_triangular.fill_IM_X(model_tree->equation_number(), mod_file->symbol_table.getID(*name), lag);
|
||||
}*/
|
||||
delete name;
|
||||
delete olag;
|
||||
return id;
|
||||
|
@ -360,14 +364,16 @@ void
|
|||
ParsingDriver::sparse_dll()
|
||||
{
|
||||
model_tree->mode = eSparseDLLMode;
|
||||
model_tree->block_triangular.init_incidence_matrix(mod_file->symbol_table.endo_nbr);
|
||||
/*model_tree->block_triangular.init_incidence_matrix(mod_file->symbol_table.endo_nbr);
|
||||
model_tree->block_triangular.init_incidence_matrix_X(mod_file->symbol_table.exo_nbr);*/
|
||||
}
|
||||
|
||||
void
|
||||
ParsingDriver::sparse()
|
||||
{
|
||||
model_tree->mode = eSparseMode;
|
||||
model_tree->block_triangular.init_incidence_matrix(mod_file->symbol_table.endo_nbr);
|
||||
/*model_tree->block_triangular.init_incidence_matrix(mod_file->symbol_table.endo_nbr);
|
||||
model_tree->block_triangular.init_incidence_matrix_X(mod_file->symbol_table.exo_nbr);*/
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -36,41 +36,61 @@ struct List_IM
|
|||
bool* IM;
|
||||
};
|
||||
|
||||
|
||||
//! create and manage the incidence matrix
|
||||
class IncidenceMatrix //: SymbolTable
|
||||
{
|
||||
//friend class BlockTriangular;
|
||||
public:
|
||||
const SymbolTable &symbol_table;
|
||||
IncidenceMatrix(const SymbolTable &symbol_table_arg);
|
||||
List_IM* Build_IM(int lead_lag, SymbolType type);
|
||||
List_IM* Get_IM(int lead_lag, SymbolType type) const;
|
||||
bool* bGet_IM(int lead_lag, SymbolType type) const;
|
||||
void fill_IM(int equation, int variable_endo, int lead_lag, SymbolType type);
|
||||
void unfill_IM(int equation, int variable_endo, int lead_lag, SymbolType type);
|
||||
void init_incidence_matrix();
|
||||
void Free_IM() const;
|
||||
List_IM* Get_First(SymbolType type) const;
|
||||
void Print_IM(SymbolType type) const;
|
||||
void Print_SIM(bool* IM, SymbolType type) const;
|
||||
|
||||
void swap_IM_c(bool *SIM, int pos1, int pos2, int pos3, simple* Index_Var_IM, simple* Index_Equ_IM, int n) const;
|
||||
private:
|
||||
List_IM *First_IM, *Last_IM, *First_IM_X, *Last_IM_X ;
|
||||
public:
|
||||
int Model_Max_Lead, Model_Max_Lag;
|
||||
int Model_Max_Lead_Endo, Model_Max_Lag_Endo, Model_Max_Lead_Exo, Model_Max_Lag_Exo;
|
||||
};
|
||||
|
||||
|
||||
//! Matrix of doubles for representing jacobian
|
||||
typedef map<pair<int ,int >,double> jacob_map;
|
||||
|
||||
//! Create the incidence matrix, computes prologue & epilogue, normalizes the model and computes the block decomposition
|
||||
class BlockTriangular
|
||||
{
|
||||
//friend class IncidenceMatrix;
|
||||
public:
|
||||
BlockTriangular(const SymbolTable &symbol_table_arg);
|
||||
const SymbolTable &symbol_table;
|
||||
BlockTriangular(const SymbolTable &symbol_table_arg);
|
||||
//BlockTriangular(const IncidenceMatrix &incidence_matrix_arg);
|
||||
//const SymbolTable &symbol_table;
|
||||
Blocks blocks;
|
||||
Normalization normalization;
|
||||
List_IM* Build_IM(int lead_lag);
|
||||
List_IM* Get_IM(int lead_lag);
|
||||
bool* bGet_IM(int lead_lag) const;
|
||||
void fill_IM(int equation, int variable_endo, int lead_lag);
|
||||
void unfill_IM(int equation, int variable_endo, int lead_lag);
|
||||
void init_incidence_matrix(int nb_endo);
|
||||
void Print_IM(int n) const;
|
||||
void Free_IM(List_IM* First_IM) const;
|
||||
void Print_SIM(bool* IM, int n) const;
|
||||
IncidenceMatrix incidencematrix;
|
||||
void Normalize_and_BlockDecompose_Static_0_Model(const jacob_map &j_m);
|
||||
bool Normalize_and_BlockDecompose(bool* IM, Model_Block* ModelBlock, int n, int* prologue, int* epilogue, simple* Index_Var_IM, simple* Index_Equ_IM, bool Do_Normalization, bool mixing, bool* IM_0 , jacob_map j_m);
|
||||
void Prologue_Epilogue(bool* IM, int* prologue, int* epilogue, int n, simple* Index_Var_IM, simple* Index_Equ_IM, bool* IM0);
|
||||
void swap_IM_c(bool *SIM, int pos1, int pos2, int pos3, simple* Index_Var_IM, simple* Index_Equ_IM, int n);
|
||||
void Allocate_Block(int size, int *count_Equ, int *count_Block, BlockType type, Model_Block * ModelBlock);
|
||||
void Free_Block(Model_Block* ModelBlock) const;
|
||||
List_IM *First_IM ;
|
||||
List_IM *Last_IM ;
|
||||
simple *Index_Equ_IM;
|
||||
simple *Index_Var_IM;
|
||||
int prologue, epilogue;
|
||||
int Model_Max_Lead, Model_Max_Lag, periods;
|
||||
bool bt_verbose;
|
||||
int endo_nbr;
|
||||
//int endo_nbr, exo_nbr;
|
||||
Model_Block* ModelBlock;
|
||||
int periods;
|
||||
inline static std::string BlockType0(int type)
|
||||
{
|
||||
switch (type)
|
||||
|
@ -98,14 +118,14 @@ public:
|
|||
{
|
||||
case EVALUATE_FORWARD:
|
||||
case EVALUATE_FORWARD_R:
|
||||
return ("EVALUATE FORWARD ");
|
||||
return ("EVALUATE FORWARD ");
|
||||
break;
|
||||
case EVALUATE_BACKWARD:
|
||||
case EVALUATE_BACKWARD_R:
|
||||
return ("EVALUATE BACKWARD ");
|
||||
break;
|
||||
case SOLVE_FORWARD_SIMPLE:
|
||||
return ("SOLVE FORWARD SIMPLE ");
|
||||
return ("SOLVE FORWARD SIMPLE ");
|
||||
break;
|
||||
case SOLVE_BACKWARD_SIMPLE:
|
||||
return ("SOLVE BACKWARD SIMPLE ");
|
||||
|
@ -114,7 +134,7 @@ public:
|
|||
return ("SOLVE TWO BOUNDARIES SIMPLE ");
|
||||
break;
|
||||
case SOLVE_FORWARD_COMPLETE:
|
||||
return ("SOLVE FORWARD COMPLETE ");
|
||||
return ("SOLVE FORWARD COMPLETE ");
|
||||
break;
|
||||
case SOLVE_BACKWARD_COMPLETE:
|
||||
return ("SOLVE BACKWARD COMPLETE ");
|
||||
|
|
|
@ -143,6 +143,7 @@ public:
|
|||
/*! Endogenous are stored as integer pairs of the form (symb_id, lag)
|
||||
They are added to the set given in argument */
|
||||
virtual void collectEndogenous(set<pair<int, int> > &result) const = 0;
|
||||
virtual void collectExogenous(set<pair<int, int> > &result) const = 0;
|
||||
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count,
|
||||
temporary_terms_type &temporary_terms,
|
||||
map<NodeID, int> &first_occurence,
|
||||
|
@ -179,6 +180,7 @@ public:
|
|||
NumConstNode(DataTree &datatree_arg, int id_arg);
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
|
||||
virtual void collectEndogenous(set<pair<int, int> > &result) const;
|
||||
virtual void collectExogenous(set<pair<int, int> > &result) const;
|
||||
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
|
||||
};
|
||||
|
@ -198,6 +200,7 @@ public:
|
|||
VariableNode(DataTree &datatree_arg, int symb_id_arg, SymbolType type_arg, int lag_arg);
|
||||
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms = temporary_terms_type()) const;
|
||||
virtual void collectEndogenous(set<pair<int, int> > &result) const;
|
||||
virtual void collectExogenous(set<pair<int, int> > &result) const;
|
||||
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
|
||||
};
|
||||
|
@ -223,6 +226,7 @@ public:
|
|||
Model_Block *ModelBlock,
|
||||
map_idx_type &map_idx) const;
|
||||
virtual void collectEndogenous(set<pair<int, int> > &result) const;
|
||||
virtual void collectExogenous(set<pair<int, int> > &result) const;
|
||||
static double eval_opcode(UnaryOpcode op_code, double v) throw (EvalException);
|
||||
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
|
||||
|
@ -250,6 +254,7 @@ public:
|
|||
Model_Block *ModelBlock,
|
||||
map_idx_type &map_idx) const;
|
||||
virtual void collectEndogenous(set<pair<int, int> > &result) const;
|
||||
virtual void collectExogenous(set<pair<int, int> > &result) const;
|
||||
static double eval_opcode(double v1, BinaryOpcode op_code, double v2) throw (EvalException);
|
||||
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
|
||||
|
@ -282,6 +287,7 @@ public:
|
|||
Model_Block *ModelBlock,
|
||||
map_idx_type &map_idx) const;
|
||||
virtual void collectEndogenous(set<pair<int, int> > &result) const;
|
||||
virtual void collectExogenous(set<pair<int, int> > &result) const;
|
||||
static double eval_opcode(double v1, TrinaryOpcode op_code, double v2, double v3) throw (EvalException);
|
||||
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
|
||||
|
@ -307,6 +313,7 @@ public:
|
|||
Model_Block *ModelBlock,
|
||||
map_idx_type &map_idx) const;
|
||||
virtual void collectEndogenous(set<pair<int, int> > &result) const;
|
||||
virtual void collectExogenous(set<pair<int, int> > &result) const;
|
||||
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
|
||||
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
|
||||
};
|
||||
|
@ -314,21 +321,22 @@ public:
|
|||
//! For one lead/lag of one block, stores mapping of information between original model and block-decomposed model
|
||||
struct IM_compact
|
||||
{
|
||||
int size, u_init, u_finish, nb_endo;
|
||||
int *u, *us, *Var, *Equ, *Var_Index, *Equ_Index, *Var_dyn_Index;
|
||||
int size, u_init, u_finish, nb_endo, size_exo;
|
||||
int *u, *us, *Var, *Equ, *Var_Index, *Equ_Index, *Exogenous, *Exogenous_Index, *Equ_X, *Equ_X_Index;
|
||||
};
|
||||
|
||||
//! One block of the model
|
||||
struct Block
|
||||
{
|
||||
int Size, Sized;
|
||||
int Size, Sized, nb_exo, nb_exo_det;
|
||||
BlockType Type;
|
||||
BlockSimulationType Simulation_Type;
|
||||
int Max_Lead, Max_Lag, Nb_Lead_Lag_Endo;
|
||||
int Max_Lag_Endo, Max_Lead_Endo;
|
||||
int Max_Lag_Exo, Max_Lead_Exo;
|
||||
bool is_linear;
|
||||
int *Equation, *Own_Derivative;
|
||||
int *Variable, *Variable_Sorted, *dVariable;
|
||||
int *variable_dyn_index, *variable_dyn_leadlag;
|
||||
int *Variable, *Exogenous;
|
||||
temporary_terms_type *Temporary_terms;
|
||||
IM_compact *IM_lead_lag;
|
||||
int Code_Start, Code_Length;
|
||||
|
@ -339,7 +347,7 @@ struct Model_Block
|
|||
{
|
||||
int Size, Periods;
|
||||
Block* Block_List;
|
||||
int *in_Block_Equ, *in_Block_Var, *in_Equ_of_Block, *in_Var_of_Block;
|
||||
//int *in_Block_Equ, *in_Block_Var, *in_Equ_of_Block, *in_Var_of_Block;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -26,6 +26,7 @@ using namespace std;
|
|||
#include <vector>
|
||||
#include <map>
|
||||
#include <ostream>
|
||||
#include <algorithm>
|
||||
|
||||
#include "SymbolTable.hh"
|
||||
#include "NumericalConstants.hh"
|
||||
|
@ -82,12 +83,14 @@ private:
|
|||
//! Computes derivatives of ModelTree
|
||||
void derive(int order);
|
||||
//! Write derivative of an equation w.r. to a variable
|
||||
void writeDerivative(ostream &output, int eq, int symb_id, int lag, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
|
||||
void writeDerivative(ostream &output, int eq, int symb_id, int lag, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, SymbolType type) const;
|
||||
//! Write derivative code of an equation w.r. to a variable
|
||||
void compileDerivative(ofstream &code_file, int eq, int symb_id, int lag, ExprNodeOutputType output_type, map_idx_type map_idx) const;
|
||||
//! Computes temporary terms
|
||||
void computeTemporaryTerms(int order);
|
||||
void computeTemporaryTermsOrdered(int order, Model_Block *ModelBlock);
|
||||
//! Build The incidence matrix form the modeltree
|
||||
void BuildIncidenceMatrix();
|
||||
//! Writes temporary terms
|
||||
void writeTemporaryTerms(ostream &output, ExprNodeOutputType output_type) const;
|
||||
//! Writes model local variables
|
||||
|
|
|
@ -48,7 +48,7 @@ e = exp(e_a);
|
|||
y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a));
|
||||
gy_obs = dA*y/y(-1);
|
||||
gp_obs = (P/P(-1))*m(-1)/dA;
|
||||
vv = 0.2*ww+0.5*vv(-1)+1;
|
||||
vv = 0.2*ww+0.5*vv(-1)+1+c(-1)+e_a;
|
||||
ww = 0.1*vv+0.5*ww(-1)+2;
|
||||
/* A lt=
|
||||
0.5*vv-0.2*ww = 1
|
||||
|
@ -84,11 +84,11 @@ vv = 0;
|
|||
ww = 0;
|
||||
end;
|
||||
|
||||
/*shocks;
|
||||
shocks;
|
||||
var e_a; stderr 0.014;
|
||||
var e_m; stderr 0.005;
|
||||
end;
|
||||
*/
|
||||
|
||||
options_.solve_tolf=1e-10;
|
||||
options_.maxit_=100;
|
||||
steady;
|
||||
|
@ -102,6 +102,8 @@ end;
|
|||
|
||||
|
||||
simul(periods=200, method=lu);
|
||||
stoch_simul(periods=200,order=1);
|
||||
|
||||
rplot y;
|
||||
rplot k;
|
||||
rplot c;
|
||||
|
|
|
@ -89,7 +89,7 @@ end;
|
|||
options_.maxit_=20;
|
||||
model_info;
|
||||
|
||||
simul(periods=200, method=/*LU*/GMRES/*bicgstab*/);
|
||||
simul(periods=2000, method=/*LU*/GMRES/*bicgstab*/);
|
||||
rplot y;
|
||||
rplot k;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var y y_s R pie dq pie_s de A y_obs pie_obs R_obs;
|
||||
var y y_s R pie dq pie_s de A y_obs pie_obs R_obs vv ww;
|
||||
varexo e_R e_q e_ys e_pies e_A;
|
||||
|
||||
parameters psi1 psi2 psi3 rho_R tau alpha rr k rho_q rho_A rho_ys rho_pies;
|
||||
|
@ -31,9 +31,22 @@ A = rho_A*A(-1)+e_A;
|
|||
y_obs = y-y(-1)+A;
|
||||
pie_obs = 4*pie;
|
||||
R_obs = 4*R;
|
||||
vv = 0.2*ww+0.5*vv(-1)+1;
|
||||
ww = 0.1*vv+0.5*ww(-1)+2;
|
||||
/* A lt=
|
||||
0.5*vv-0.2*ww = 1
|
||||
-0.1*vv+0.5*ww = 2
|
||||
[ 0.5 -0.2][vv] [1]
|
||||
=
|
||||
[-0.1 0.5][ww] [2]
|
||||
det = 0.25-0.02 = 0.23
|
||||
[vv] [0.5 0.2] [1] [0.9] [3.91304]
|
||||
= 1/0.23* = 1/0.23* =
|
||||
[ww] [0.1 0.5] [2] [1.1] [4.7826]
|
||||
*/
|
||||
end;
|
||||
|
||||
/*shocks;
|
||||
shocks;
|
||||
var e_R = 1.25^2;
|
||||
var e_q = 2.5^2;
|
||||
var e_A = 1.89;
|
||||
|
@ -41,7 +54,7 @@ var e_ys = 1.89;
|
|||
var e_pies = 1.89;
|
||||
end;
|
||||
|
||||
varobs y_obs R_obs pie_obs dq de;
|
||||
/*varobs y_obs R_obs pie_obs dq de;
|
||||
|
||||
estimated_params;
|
||||
psi1 , gamma_pdf,1.5,0.5;
|
||||
|
@ -63,12 +76,13 @@ stderr e_ys,inv_gamma_pdf,1.2533,0.6551;
|
|||
stderr e_pies,inv_gamma_pdf,1.88,0.9827;
|
||||
end;
|
||||
|
||||
estimation(datafile=data_ca1,first_obs=8,nobs=79,mh_nblocks=10,prefilter=1,mh_jscale=0.5,mh_replic=0);
|
||||
|
||||
estimation(datafile=data_ca1,first_obs=8,nobs=79,mh_nblocks=10,prefilter=1,mh_jscale=0.5,mh_replic=0,nograph);
|
||||
*/
|
||||
|
||||
|
||||
options_.maxit_=100;
|
||||
steady;
|
||||
//model_info;
|
||||
model_info;
|
||||
check;
|
||||
|
||||
shocks;
|
||||
|
@ -77,6 +91,9 @@ periods 1;
|
|||
values 0.5;
|
||||
end;
|
||||
|
||||
//simul(periods=200,method=bicgstab);
|
||||
//rplot A;
|
||||
//rplot pie;
|
||||
simul(periods=200,method=bicgstab);
|
||||
rplot A;
|
||||
rplot pie;
|
||||
|
||||
stoch_simul(periods=200,order=1);
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ periods 1;
|
|||
values 1.002;
|
||||
end;
|
||||
|
||||
simul(periods=200, METHOD=GmRes);
|
||||
simul(periods=200, METHOD=LU);
|
||||
|
||||
rplot c;
|
||||
rplot k;
|
||||
|
|
Loading…
Reference in New Issue