%% set inputs for solution below
%  The program produces responses to the shocks selected below under
%  irfshock. Paths for all the endogenous variables in the model selected
%  are produced. VariableName_difference holds the piece-wise linear solution for
%  VariableName.  VariableName_uncdifference holds the linear solution for
%  VariableName.


clear
close all


global M_ oo_

modnam = 'NIBNIL';
modnamstar = 'NIBNIL_ZLB';


constraint = 'irate <(1-Rss)';
constraint_relax ='iratenot >(1-Rss)';

% Pick innovation for IRFs
irfshock =char('epssigma');      % label for innovation for IRFs

shockssequence = [1; zeros(30,1)];  
nperiods = 30;



% Solve model, generate model IRFs
[zdatalinear zdatapiecewise zdatass oobase_ Mbase_  ] = ...
  solve_one_constraint(modnam,modnamstar,...
  constraint, constraint_relax,...
  shockssequence,irfshock,nperiods);


% unpack the IRFs                          
for i=1:M_.endo_nbr
  eval([deblank(M_.endo_names(i,:)),'_l=zdatalinear(:,i);']);
  eval([deblank(M_.endo_names(i,:)),'_p=zdatapiecewise(:,i);']);
  eval([deblank(M_.endo_names(i,:)),'_ss=zdatass(i);']);
end

% define inputs for plotting
titlelist = char('prod (GDP)','prodfor (Foreign GDP)','irate (Interest rate)','bgdp (Private debt)');
percent = 'Percent';
level = 'Level';
ylabels = char(percent,percent,percent,percent,level);
figtitle = '';
legendlist = cellstr(char('Piecewise Linear','Linear'));
line1=100*[prod_p,prodfor_p,irate_p,bgdp_p];
line2=100*[prod_l,prodfor_l,irate_l,bgdp_l];

% create plots
makechart(titlelist,legendlist,figtitle,ylabels,line1,line2)

