Unverified Commit 8ba1a152 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Remove outdated Occbin files

parent d61df2e6
% Solve model, generate model IRFs
[zdatalinear, zdatapiecewise, zdatass, oobase_, Mbase_ ] = ...
solve_one_constraint(modnam,modnamstar,...
constraint, constraint_relax,...
shockssequence,irfshock,nperiods,maxiter);
% unpack the IRFs
for i=1:Mbase_.endo_nbr
eval([Mbase_.endo_names{i}, '_uncdifference=zdatalinear(:,i);']);
eval([Mbase_.endo_names{i}, '_difference=zdatapiecewise(:,i);']);
eval([Mbase_.endo_names{i}, '_ss=zdatass(i);']);
end
nparams = length(Mbase_.param_names);
for i = 1:nparams
eval([Mbase_.param_names{i}, '= Mbase_.params(i);']);
end
[zdatalinear, zdatapiecewise, zdatass, oobase_, Mbase_] = solve_two_constraints(...
modnam_00,modnam_10,modnam_01,modnam_11,...
constraint1, constraint2,...
constraint_relax1, constraint_relax2,...
scalefactormod,irfshock,nperiods,curb_retrench,maxiter);
for i=1:Mbase_.endo_nbr
eval([Mbase_.endo_names{i}, '_uncdifference=zdatalinear(:,i);']);
eval([Mbase_.endo_names{i}, '_difference=zdatapiecewise(:,i);']);
eval([Mbase_.endo_names{i}, '_ss=zdatass(i);']);
end
constraint1_difference = process_constraint(constraint1, '_difference', Mbase_.endo_names,0);
constraint2_difference = process_constraint(constraint2, '_difference', Mbase_.endo_names,0);
nparams = length(Mbase_.param_names);
for i = 1:nparams
eval([Mbase_.param_names{i}, '= Mbase_.params(i);']);
end
function [r,g1,g2,g3] = evaluate_model(z,x,M,ss)
ll = M.lead_lag_incidence';
y = z(find(ll(:)));
switch nargout
case 1
r = feval([M.fname '.dynamic'],y,x, ...
M.params, ss, 1);
case 2
[r,g1] = feval([M.fname '.dynamic'],y,x, ...
M.params, ss, 1);
case 3
[r,g1,g2] = feval([M.fname '.dynamic'],y,x, ...
M.params, ss, 1);
case 4
[r,g1,g2,g3] = feval([M.fname '.dynamic'],y,x, ...
M.params, ss, 1);
end
\ No newline at end of file
function [coef_y,coef_u] = get_coef(jacobian,M)
ll = M.lead_lag_incidence;
endo_nbr = M.endo_nbr;
coef_y = zeros(endo_nbr,3*endo_nbr);
coef_u = zeros(endo_nbr,M.exo_nbr);
if M.maximum_lag > 0
[~,c1,c2] = find(ll(1,:));
coef_y(:,c1) = jacobian(:,c2);
[~,c1,c2] = find(ll(2,:));
coef_y(:,c1+endo_nbr) = jacobian(:,c2);
if M.maximum_lead > 0
[~,c1,c2] = find(ll(3,:));
coef_y(:,c1+2*endo_nbr) = jacobian(:,c2);
end
else
[~,c1,c2] = find(ll(1,:));
coef_y(:,c1+endo_nbr) = jacobian(:,c2);
if M.maximum_lead > 0
[~,c1,c2] = find(ll(2,:));
coef_y(:,c1+2*endo_nbr) = jacobian(:,c2);
end
end
coef_u = jacobian(:,max(ll(end,:))+1:end);
\ No newline at end of file
function [lb,ub,eq_index] = get_complementarity_conditions(M,ramsey_policy)
% Copyright (C) 2014-2018 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/>.
ub = inf(M.endo_nbr,1);
lb = -ub;
eq_index = (1:M.endo_nbr)';
if ramsey_policy
if isfield(M,'ramsey_model_constraints')
rc = M.ramsey_model_constraints;
for i = 1:length(rc)
switch rc{i}{2}
case {'>','>='}
lb(rc{i}{1}) = eval(rc{i}{3});
case {'<','<='}
ub(rc{i}{1}) = eval(rc{i}{3});
otherwise
error('Wrong operator in get_complementarity_conditions')
end
eq_index(i) = 1;
end
end
end
etags = M.equations_tags;
for i=1:size(etags,1)
if strcmp(etags{i,2},'mcp')
str = etags{i,3};
kop = strfind(etags{i,3},'<');
if ~isempty(kop)
k = find(strcmp(strtrim(str(1:kop-1)), M.endo_names));
if isempty(k)
error(sprintf(['Complementarity condition %s: variable %s is ' ...
'not recognized',etags{i,3},b{1}]))
end
ub(k) = str2num(str(kop+1:end));
eq_index(etags{i,1}) = k;
eq_index(k) = etags{i,1};
else
kop = strfind(etags{i,3},'>');
if ~isempty(kop)
k = find(strcmp(strtrim(str(1:kop-1)), M.endo_names));
if isempty(k)
error(sprintf(['Complementarity condition %s: variable %s is ' ...
'not recognized',etags{i},b{1}]))
end
lb(k) = str2num(str(kop+1:end));
eq_index(etags{i,1}) = k;
eq_index(k) = etags{i,1};
else
error(sprintf(['Complementarity condition %s can''t be ' ...
'parsed'],etags{i,3}))
end
end
end
end
function [hm1,h,hl1,j,resid] = get_deriv(M_,ys_)
iy_ = M_.lead_lag_incidence;
it_ = 1;
x = zeros(1,M_.exo_nbr);
% For most models, there are leads, lags and current values of variables
if size(iy_,1)==3
% find non-zero columns of hm1
lag_cols = find(iy_(1,:)~=0);
% find non-zero columns of h
con_cols = find(iy_(2,:));
% find non-zero columns of hl1
lea_cols = find(iy_(3,:));
% If models either lacks leads or lags, iy_ will have two rows
% In this case, we guess that the row with more nonzeros is the row with current variables
elseif size(iy_,1)==2
% if first row has more nonzero entries than the second, assume model lacks lagged variables
if length(find(iy_(1,:)))>length(find(iy_(2,:)))
warning('Model does not have lagged endogenous variables')
con_cols = find(iy_(1,:));
lea_cols = find(iy_(2,:));
lag_cols = [];
else
warning('Model does not have expected future endogenous variables')
lag_cols = find(iy_(1,:));
con_cols = find(iy_(2,:));
lea_cols = [];
end
end
% find number of entries for y vector
ny = length(find(iy_~=0));
% build steady state y
y = ys_(lag_cols);
y = [y;ys_(con_cols)];
y = [y;ys_(lea_cols)];
if ismac
eval(['[resid,g1]=',M_.fname,'.dynamic(y,x, M_.params, ys_, it_);']);
% Older versions of DYNARE for Mac did not include ys_ in the call structure
%eval(['[resid,g1]=',M_.fname,'.dynamic(y,x, M_.params, it_);']);
else
eval(['[resid,g1]=',M_.fname,'.dynamic(y,x, M_.params, ys_, it_);']);
end
hm1=zeros(M_.endo_nbr);
h = hm1;
hl1 = hm1;
j = zeros(M_.endo_nbr,M_.exo_nbr);
% build hm1
nlag_cols = length(lag_cols);
for i=1:nlag_cols
hm1(:,lag_cols(i)) = g1(:,i);
end
% build h
ncon_cols = length(con_cols);
for i=1:ncon_cols
h(:,con_cols(i)) = g1(:,i+nlag_cols);
end
% build hl1
nlea_cols = length(lea_cols);
for i=1:nlea_cols
hl1(:,lea_cols(i)) = g1(:,i+nlag_cols+ncon_cols);
end
for i = 1:M_.exo_nbr
j(:,i) =g1(:,i+ny);
end
function [ivar,ieq,lb,ub] = get_occbin_complementarity_conditions(M,ramsey_policy)
% Copyright (C) 2015-2018 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/>.
nrow = 1;
if ramsey_policy
if isfield(M,'ramsey_model_constraints')
rc = M.ramsey_model_constraints;
for i = 1:length(rc)
switch rc{i}{2}
case {'>','>='}
ivar(nrow) = rc{i}{1};
ieq(nrow) = rc{i}{1};
lb(nrow) = eval(rc{i}{3});
case {'<','<='}
ivar(nrow) = rc{i}{1};
ieq(nrow) = rc{i}{1};
ub(nrow) = eval(rc{i}{3});
otherwise
error('Wrong operator in get_complementarity_conditions')
end
nrow = nrow + 1;
end
end
end
etags = M.equations_tags;
for i=1:size(etags,1)
if strcmp(etags{i,2},'mcp')
str = etags{i,3};
kop = strfind(etags{i,3},'<');
if ~isempty(kop)
k = find(strcmp(strtrim(str(1:kop-1)), M.endo_names));
if isempty(k)
error(sprintf(['Complementarity condition %s: variable %s is ' ...
'not recognized',etags{i,3},b{1}]))
end
ivar(nrow) = k;
ieq(nrow) = etags{i,1};
ub(nrow) = eval(str(kop+1:end));
else
kop = strfind(etags{i,3},'>');
if ~isempty(kop)
k = find(strcmp(strtrim(str(1:kop-1)), M.endo_names));
if isempty(k)
error(sprintf(['Complementarity condition %s: variable %s is ' ...
'not recognized',etags{i},b{1}]))
end
ivar(nrow) = k;
ieq(nrow) = etags{i,1};
lb(k) = eval(str(kop+1:end));
else
error(sprintf(['Complementarity condition %s can''t be ' ...
'parsed'],etags{i,3}))
end
end
nrow = nrow + 1;
end
end
function [i_base,i_alt,c_base,c_alt] = get_occbin_constraints(M,steady_state,ramsey_policy)
% Copyright (C) 2015 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/>.
nrow = 1;
if ramsey_policy
if isfield(M,'ramsey_model_constraints')
rc = M.ramsey_model_constraints;
for i = 1:length(rc)
switch rc{i}{2}
case {'>','>='}
ivar(nrow) = rc{i}{1};
ieq(nrow) = rc{i}{1};
lb(nrow) = eval(rc{i}{3});
case {'<','<='}
ivar(nrow) = rc{i}{1};
ieq(nrow) = rc{i}{1};
ub(nrow) = eval(rc{i}{3});
otherwise
error('Wrong operator in get_complementarity_conditions')
end
nrow = nrow + 1;
end
end
end
i_base = {};
i_alt = {};
etags = M.equations_tags;
m = 1;
base = true;
for i=1:size(etags,1)
[iv,boundary,operator] = parse_constraint(etags{i,3},M.endo_names,M.params,M.param_names);
if strcmp(etags{i,2},'OCCBIN')
if base
i_alt{m} = 1:M.eq_nbr;
i_alt{m}(etags{i,1}) = [];
c_base{m,1} = etags{i,1};
c_base{m,2} = iv;
c_base{m,3} = boundary - steady_state(iv);
c_base{m,4} = operator;
base = false;
else
i_base{m} = 1:M.eq_nbr;
i_base{m}(etags{i,1}) = [];
c_alt{m,1} = etags{i,1};
c_alt{m,2} = iv;
c_alt{m,3} = boundary - steady_state(iv);
c_alt{m,4} = operator;
base = true;
m = m + 1;
end
end
end
if ~base
error('OCCBIN: constraints must come by pair')
end
function [iv,boundary,operator] = parse_constraint(str,endo_names,params,param_names)
delim = {'<=','>=','<','>'};
[c,operator] = strsplit(str,delim);
operator = operator{1};
iv = strmatch(strtrim(c{1}),endo_names);
% try for a number
boundary = str2num(strtrim(c{2}));
% if not a number try for a parameter name
if isempty(boundary)
k = strmatch(strtrim(c{2}),param_names);
if isempty(k)
error(['OCCBIN: illegal constraint ' str]);
end
boundary = params(k);
end
function [p,q]=get_pq(dr_,nstatic,nfwrd)
nvars = size(dr_.ghx,1);
nshocks = size(dr_.ghu,2);
statevar_pos = (nstatic +1):(nvars-nfwrd);
p = zeros(nvars);
% interlace matrix
nnotzero = length(statevar_pos);
for i=1:nnotzero
p(:,statevar_pos(i)) = dr_.ghx(:,i);
end
% reorder p matrix according to order in lgy_
inverse_order = zeros(nvars,1);
for i=1:nvars
inverse_order(i) = find(i==dr_.order_var);
end
p_reordered = zeros(nvars);
q = zeros(nvars,nshocks);
for i=1:nvars
for j=1:nvars
p_reordered(i,j)=p(inverse_order(i),inverse_order(j));
end
q(i,:)=dr_.ghu(inverse_order(i),:);
end
p=p_reordered;
\ No newline at end of file
function r = get_residuals(ivar,lb,ub,M,oo)
ss = oo.steady_state;
for i = 1:length(ivar)
% only one is different from zero
ss(ivar(i)) = lb(i) + ub(i);
end
oo.steady_state = ss;
r = evaluate_model(M,oo);
\ No newline at end of file
function makechart(titlelist,legendlist,figlabel,ylabels,zdata1,zdata2,zdata3)
figure
titlelist = char(strrep(cellstr(titlelist),'_','.'));
ndsets=3; % default, changed below as applicable
if nargin==5
zdata2=nan*zdata1;
zdata3=nan*zdata1;
ndsets =1;
elseif nargin == 6
zdata3 =nan*zdata1;
ndsets=2;
elseif ((nargin>8) | (nargin <=4))
error ('makechart takes 5 to 6 arguments')
end
nobs = size(zdata1,1);
xvalues = (1:nobs)';
nvars = size(titlelist,1);
if nvars==1
nrows=1;
ncols = 1;
elseif nvars==2
nrows =2;
ncols = 1;
elseif (nvars == 3 | nvars ==4)
nrows = 2;
ncols =2;
elseif (nvars==5 |nvars ==6)
nrows = 3;
ncols = 2;
elseif (nvars==7 | nvars==8)
nrows = 4;
ncols = 2;
elseif (nvars==9 | nvars==10)
nrows = 5;
ncols = 2;
else
error('too many variables (makechart)')
end
for i = 1:nvars
subplot(nrows,ncols,i)
h1=plot(xvalues,zdata1(:,i),'b-','linewidth',2); hold on
h1=plot(xvalues,zdata2(:,i),'r--','linewidth',2); hold on
h2=plot(xvalues,zdata3(:,i),'b-','LineWidth',3);
[x0, x1, y10, y11] = pickaxes(xvalues,zdata1(:,i));
[x0, x1, y20, y21] = pickaxes(xvalues,zdata2(:,i));
[x0, x1, y30, y31] = pickaxes(xvalues,zdata3(:,i));
y0 = min([y10,y20,y30]);
y1 = max([y11,y21,y31]);
if y0==y1
y1=y0+1;
end
axis([x0 x1 y0 y1])
set(h1);
if i==1 && isempty(legendlist)==0
legend(legendlist)
text('String',figlabel,'Units','normalized','Position',[1.2 1.24],...
'FontSize',14,'FontWeight','bold','HorizontalAlignment','center');
end
if i==nvars | i==nvars-1
xlabel('Time');
end
% set(gca,'XTick',xtick)
% set(gca,'XTickLabel',xticklabel)
title([num2str(i),'. ',titlelist(i,:)]);
ylabel(ylabels(i,:))
end
% sets printing preferences
%printpref
function makechart9(titlelist,legendlist,figlabel,yearshock,ylabels,...
zdata1,zdata2,zdata3,zdata4,zdata5,zdata6,zdata7)
figure
titlelist = char(strrep(cellstr(titlelist),'_','.'));
ndsets=7; % default, changed below as applicable
if nargin==6
zdata2=nan*zdata1;
zdata3=nan*zdata1;
zdata4=nan*zdata1;
zdata5=nan*zdata1;
zdata6=nan*zdata1;
zdata7=nan*zdata1;
ndsets =1;
elseif nargin==7
zdata3=nan*zdata1;
zdata4=nan*zdata1;
zdata5=nan*zdata1;
zdata6=nan*zdata1;
zdata7=nan*zdata1;
ndsets =2;
elseif nargin == 8
zdata4 =nan*zdata1;
zdata5 =nan*zdata1;
zdata6=nan*zdata1;
zdata7=nan*zdata1;
ndsets=3;
elseif nargin == 9
zdata5 =nan*zdata1;
zdata6=nan*zdata1;
zdata7=nan*zdata1;
ndsets=4;
elseif nargin == 10
zdata6 =nan*zdata1;
zdata7=nan*zdata1;
ndsets=5;
elseif nargin == 11
zdata7=nan*zdata1;
ndsets=6;
elseif ((nargin>=13) | (nargin <=3))
error ('makechart takes 4 to 10 arguments')
end
nobs = size(zdata1,1);
if yearshock>-100
xvalues = yearshock+(0:nobs-1)'/4; % Matteo plot year on x axis
else
xvalues = (1:nobs)'; % Matteo plot year on x axis
end
nvars = size(titlelist,1);
if nvars==1
nrows=1;
ncols = 1;
elseif nvars==2