Home > matlab > discretionary_policy_1.m

discretionary_policy_1

PURPOSE ^

Copyright (C) 2007-2012 Dynare Team

SYNOPSIS ^

function [dr,ys,info]=discretionary_policy_1(oo_,Instruments)

DESCRIPTION ^

 Copyright (C) 2007-2012 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/>.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [dr,ys,info]=discretionary_policy_1(oo_,Instruments)
0002 
0003 % Copyright (C) 2007-2012 Dynare Team
0004 %
0005 % This file is part of Dynare.
0006 %
0007 % Dynare is free software: you can redistribute it and/or modify
0008 % it under the terms of the GNU General Public License as published by
0009 % the Free Software Foundation, either version 3 of the License, or
0010 % (at your option) any later version.
0011 %
0012 % Dynare is distributed in the hope that it will be useful,
0013 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0014 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0015 % GNU General Public License for more details.
0016 %
0017 % You should have received a copy of the GNU General Public License
0018 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0019 
0020 global M_ options_
0021 persistent Hold
0022 
0023 options_ = set_default_option(options_,'qz_criterium',1.000001);
0024 options_ = set_default_option(options_,'solve_maxit',3000);
0025 
0026 % safeguard against issues like running ramsey policy first and then running discretion
0027 if isfield(M_,'orig_model')
0028     orig_model = M_.orig_model;
0029     M_.endo_nbr = orig_model.endo_nbr;
0030     M_.endo_names = orig_model.endo_names;
0031     M_.lead_lag_incidence = orig_model.lead_lag_incidence;
0032     M_.maximum_lead = orig_model.maximum_lead;
0033     M_.maximum_endo_lead = orig_model.maximum_endo_lead;
0034     M_.maximum_lag = orig_model.maximum_lag;
0035     M_.maximum_endo_lag = orig_model.maximum_endo_lag;
0036 else
0037     M_.orig_model = M_;
0038 end
0039 
0040 beta = get_optimal_policy_discount_factor(M_.params,M_.param_names);
0041 
0042 exo_nbr = M_.exo_nbr;
0043 if isfield(M_,'orig_model')
0044     orig_model = M_.orig_model;
0045     endo_nbr = orig_model.endo_nbr;
0046     endo_names = orig_model.endo_names;
0047     lead_lag_incidence = orig_model.lead_lag_incidence;
0048     MaxLead = orig_model.maximum_lead;
0049     MaxLag = orig_model.maximum_lag;
0050 else
0051     endo_names = M_.endo_names;
0052     endo_nbr = M_.endo_nbr;
0053     MaxLag=M_.maximum_lag;
0054     MaxLead=M_.maximum_lead;
0055     lead_lag_incidence = M_.lead_lag_incidence;
0056 end
0057 
0058 [U,Uy,W] = feval([M_.fname,'_objective_static'],zeros(endo_nbr,1),[], M_.params);
0059 if any(any(Uy~=0))
0060     error(['discretionary_policy: the objective function must have zero ' ...
0061            'first order derivatives'])
0062 end
0063 
0064 W=reshape(W,endo_nbr,endo_nbr);
0065 
0066 klen = MaxLag + MaxLead + 1;
0067 iyv=lead_lag_incidence';
0068 % Find the jacobian
0069 z = repmat(zeros(endo_nbr,1),1,klen);
0070 z = z(nonzeros(iyv)) ;
0071 it_ = MaxLag + 1 ;
0072 
0073 if exo_nbr == 0
0074     oo_.exo_steady_state = [] ;
0075 end
0076 [junk,jacobia_] = feval([M_.fname '_dynamic'],z, [oo_.exo_simul ...
0077                     oo_.exo_det_simul], M_.params, zeros(endo_nbr,1), it_);
0078 if any(junk~=0)
0079     error(['discretionary_policy: the model must be written in deviation ' ...
0080            'form and not have constant terms'])
0081 end
0082 
0083 eq_nbr= size(jacobia_,1);
0084 instr_nbr=endo_nbr-eq_nbr;
0085 
0086 instr_id=nan(instr_nbr,1);
0087 for j=1:instr_nbr
0088     vj=deblank(Instruments(j,:));
0089     vj_id=strmatch(vj,endo_names,'exact');
0090     if ~isempty(vj_id)
0091         instr_id(j)=vj_id;
0092     else
0093         error([mfilename,':: instrument ',vj,' not found'])
0094     end
0095 end
0096 
0097 Indices={'lag','0','lead'};
0098 iter=1;
0099 for j=1:numel(Indices)
0100     eval(['A',Indices{j},'=zeros(eq_nbr,endo_nbr);'])
0101     if strcmp(Indices{j},'0')||(strcmp(Indices{j},'lag') && MaxLag)||(strcmp(Indices{j},'lead') && MaxLead)
0102         [junk,row,col]=find(lead_lag_incidence(iter,:));
0103         eval(['A',Indices{j},'(:,row)=jacobia_(:,col);'])
0104         iter=iter+1;
0105     end
0106 end
0107 B=jacobia_(:,nnz(iyv)+1:end);
0108 
0109 %%% MAIN ENGINE %%%
0110 qz_criterium = options_.qz_criterium;
0111 solve_maxit = options_.solve_maxit;
0112 discretion_tol = options_.discretionary_tol;
0113 
0114 if ~isempty(Hold)
0115     [H,G,info]=discretionary_policy_engine(Alag,A0,Alead,B,W,instr_id,beta,solve_maxit,discretion_tol,qz_criterium,Hold);
0116 else
0117     [H,G,info]=discretionary_policy_engine(Alag,A0,Alead,B,W,instr_id,beta,solve_maxit,discretion_tol,qz_criterium);
0118 end
0119 
0120 if info
0121     dr=[];
0122     return
0123 else
0124     Hold=H;
0125     % Hold=[]; use this line if persistent command is not used.
0126 end
0127 % update the following elements
0128 
0129 LLI=lead_lag_incidence;
0130 LLI(MaxLag,:)=any(H);
0131 
0132 LLI=LLI';
0133 tmp=find(LLI);
0134 LLI(tmp)=1:numel(tmp);
0135 
0136 M_.lead_lag_incidence = LLI';
0137 
0138 % set the state
0139 dr=oo_.dr;
0140 dr.ys =zeros(endo_nbr,1);
0141 dr=set_state_space(dr,M_);
0142 order_var=dr.order_var;
0143 
0144 T=H(order_var,order_var);
0145 dr.ghu=G(order_var,:);
0146 Selection=any(T);
0147 dr.ghx=T(:,Selection);
0148 
0149 ys=NondistortionarySteadyState(M_);
0150 dr.ys=ys; % <--- dr.ys =zeros(NewEndo_nbr,1);
0151 
0152 function ys=NondistortionarySteadyState(M_)
0153 if exist([M_.fname,'_steadystate.m'],'file')
0154     eval(['ys=',M_.fname,'_steadystate.m;'])
0155 else
0156     ys=zeros(M_.endo_nbr,1);
0157 end

Generated on Mon 21-May-2012 02:42:43 by m2html © 2005