File size: 3,560 Bytes
ed7d493 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | %-------------------------------------------------------------------------
% The model: Safe Assets - the case of general IES (THETA not equal 1)
%
% This file defines the model (see Appendix for the full derivation).
% Bonds are perfectly safe short-term assets.
%
% Variables are denoted by small letters and
% parameters by capital letters. Future values are denoted by suffix p.
%-------------------------------------------------------------------------
clear,clc
%% Symbolic variables
syms RHO GAMMA1 GAMMA2 NU MU THETA real
syms f1 f2 f1p f2p x1 x2 x1p x2p real
syms logq logqp tilp tilpp real
syms state1 state1p state2 state2p hatyp k1 tilb1 real
syms tila1 tila2 invtila1 invtila2 invtilp rbp rep c1 c2 c1p c2p q qp real
syms invc1 invc1p invc2 invc2p invf1 invf2 r1p r2p u1p_power u2p_power u1p u2p logf1 logf1p logf2 logf2p real
syms term1p term2p invr1p invr2p real
%% Parameters
symparams = [RHO,GAMMA1,GAMMA2,NU,MU,THETA];
%% State variables
state = [state1,state2]; % current period
statep = [state1p,state2p]; % future period
%% Control variables
control = [f1,f2,x1,x2,logq,tilp]; % current period
controlp = [f1p,f2p,x1p,x2p,logqp,tilpp]; % future period
%% shocks
shocks = hatyp;
%% auxiliary variables
logc1p = log(c1p);
logc2p = log(c2p);
invf1_ = 1/f1;
invf2_ = 1/f2;
logf1p_ = log(f1p);
logf2p_ = log(f2p);
invr1p_ = 1/r1p;
invr2p_ = 1/r2p;
q_ = exp(logq);
qp_ = exp(logqp);
invtila1_ = 1/tila1;
invtila2_ = 1/tila2;
rep_ = (1 + tilpp)/tilp*hatyp; % return on equity
rbp_ = 1/q; % return on bond
%% MODEL CONDITIONS
invc1_ = 1 + 1/RHO*f1^(1 - THETA);
c1_ = 1/invc1;
invc1p_ = 1 + 1/RHO*f1p^(1 - THETA);
c1p_ = 1/invc1p;
invc2_ = 1 + 1/RHO*f2^(1-THETA);
c2_ = 1/invc2;
invc2p_ = 1 + 1/RHO*f2p^(1 - THETA);
c2p_ = 1/invc2p;
tila1_ = (1 + tilp)*state1 + state2;
tila2_ = tilp + 1 - tila1;
k1_ = x1*(1 - c1)*tila1/tilp;
eq0 = -(1 - k1) + x2*(1 - c2)*tila2/tilp;
tilb1_ = (1 - x1)*(1 - c1)*tila1;
eq1 = tilb1*invtila2 + (1 - x2)*(1 - c2);
r1p_ = x1*rep + (1 - x1)*rbp;
r2p_ = x2*rep + (1 - x2)*rbp;
term1p_ = ((invc1 - 1)*r1p*invf1)^(1 - GAMMA1)*((1 - NU*(1 - MU))*u1p^(1 - GAMMA1)...
+ NU*(1 - MU)*u2p^(1 - GAMMA1));
term2p_ = ((invc2 - 1)*r2p*invf2)^(1 - GAMMA2)*((1 - NU*MU)*u2p^(1 - GAMMA2)...
+ NU*MU*u1p^(1 - GAMMA2));
eq2 = -1 + term1p;
eq3 = -1 + term2p;
u1p_power_ = RHO/(1 + RHO)*c1p^(1 - THETA) + 1/(1 + RHO)*c1p^(1 - THETA)*f1p^(1 - THETA);
u2p_power_ = RHO/(1 + RHO)*c2p^(1 - THETA) + 1/(1 + RHO)*c2p^(1 - THETA)*f2p^(1 - THETA);
u1p_ = u1p_power^(1/(1 - THETA));
u2p_ = u2p_power^(1/(1 - THETA));
eq4 = (rep - rbp)*term1p*invr1p;
eq5 = (rep - rbp)*term2p*invr2p;
%% Function f (Ef = 0 imposes model conditions)
f_fun = [eq0;eq1;eq2;eq3;eq4;eq5];
%% law of motion of state variables
Phi_fun = [k1 - NU*(k1 - MU); % law of motion of state1p
(1 - NU)*tilb1/(hatyp*q)]; % law of motion of state2p
%% collect auxiliary variables and functions
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
%% Approximation order (<=4)
order = 4;
%% Preprocess model and save
model = prepare_tp(f_fun,Phi_fun,controlp,control,statep,state,shocks,symparams,order,auxfuns,auxvars);
save('model')
|