REPRO-Bench / 105 /replication_package /examples /rbc /prepare_model_auxiliary_functions.m
raw
history blame
3.31 kB
%----------------------------------------------
% RBC model with auxiliary functions
%----------------------------------------------
clear,clc
%-----------------------------------------
% Define symbolic variables and parameters
%-----------------------------------------
syms k kp c cp z zp epsp real
syms BETA GAMMA ALPHA RHO DELTA SIGMA real
%-------------------------------
% Define the auxiliary functions
%-------------------------------
% Logs of consumption and capital.
syms logc logcp logk logkp real
logc_=log(c);
logcp_=log(cp);
logk_=log(k);
logkp_=log(kp);
% Log and level of future mpk.
syms mpkp logmpkp real
logmpkp_=log(ALPHA)+zp+(ALPHA-1)*logkp;
mpkp_=exp(logmpkp);
% Log and level of stochastic discount factor.
syms mp logmp real
logmp_=log(BETA)+GAMMA*(logc-logcp);
mp_=exp(logmp);
% Log and level of output.
syms logoutput output real
logoutput_=z+ALPHA*logk;
output_=exp(logoutput);
%-----------------------------
% Function f (Euler condition)
%-----------------------------
f_fun=mp*(mpkp+1-DELTA)-1;
%-------------------------------------------------------
% Function Phi (law of motion of capital and technology)
%-------------------------------------------------------
Phi_fun=[output+(1-DELTA)*k-c;
RHO*z+SIGMA*epsp];
%--------------------------
% Vector of state variables
%--------------------------
x=[k,z]; % current period
xp=[kp,zp]; % future period
%----------------------------
% Vector of control variables
%----------------------------
y=[c]; % current period
yp=[cp]; % future period
%-----------------
% Vector of shocks
%-----------------
shocks=[epsp];
%---------------------
% Vector of parameters
%---------------------
symparams=[BETA,GAMMA,ALPHA,RHO,DELTA,SIGMA];
%-----------------------------------------------------------
% Vectors of auxiliary functions and corresponding variables
%-----------------------------------------------------------
% you can do it manually:
% auxfuns=[logc_;logcp_;logk_;logkp_;logmp_;logmpkp_;logoutput_;mp_;mpkp_;output_];
% auxvars=[logc;logcp;logk;logkp;logmp;logmpkp;logoutput;mp;mpkp;output];
% or automatically by the following code (the names of the
% auxiliary functions must be the same as the auxiliary variables with an
% underscore suffix):
allvars=who;
auxfuns=[];
auxvars=[];
for i=1:length(allvars)
if strcmp(allvars{i}(end),'_')
eval(['tempfun=' allvars{i} ';'])
eval(['tempvar=' allvars{i}(1:end-1) ';'])
auxfuns=[auxfuns(:);tempfun(:)];
auxvars=[auxvars(:);tempvar(:)];
end
end
% Note that f is a function of the model variables and the auxiliary
% variables. To get f as a function of the model variables only, use the
% function subsf:
f_noaux = subsf( f_fun,auxvars,auxfuns );
% Compare f with f_noaux
f_fun,f_noaux
% Display the auxiliary equations:
[auxvars,auxfuns]
%--------------------
% Approximation order
%--------------------
order=4; % fourth order is the maximum possible
%----------------
% Call prepare_tp
%----------------
model=prepare_tp(f_fun,Phi_fun,yp,y,xp,x,shocks,symparams,order,auxfuns,auxvars);
%-----------
% Save model
%-----------
save('model') % you will need this later