-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathLife_cycle_2_periods.m
More file actions
47 lines (34 loc) · 1.24 KB
/
Life_cycle_2_periods.m
File metadata and controls
47 lines (34 loc) · 1.24 KB
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
% Two-period life-cycle model with income risk (saving in riskless bond only)
% Written by Michael Hatcher (m.c.hatcher@soton.ac.uk) in 2017.
clear; clc;
% Parameter values
beta = 0.96; r = 0.05; Y1 = 1; p = 0.5;
eps1 = 0.5; eps2 = 1.05;
Nguess = 8000;
Sguess = NaN(Nguess,1); U = Sguess;
S_vec = linspace(0,Y1,Nguess); %Vector of guesses for S
for i=1:Nguess
Sguess(i) = S_vec(i);
S = Sguess(i);
C1 = Y1 - S;
C2_1 = eps1 + (1+r)*S;
C2_2 = eps2 + (1+r)*S;
U(i) = log(C1) + beta*( p*log(C2_1) + (1-p)*log(C2_2) );
if ~isreal(U(i)) || C1 <= 0 || C2_1 <= 0 || C2_2 <= 0
U(i) = -realmax; %Not sensible economic solutions
end
end
%Find maximum of utility w.r.t. S guesses
[Umax, IndexU] = max(U); %IndexU is the location of the optimal value
disp('Optimal holding of shares is')
Sguess(IndexU)
Sstar = Sguess(IndexU);
C1star = Y1 - Sstar;
C2_1star = eps1 + (1+r)*Sstar;
C2_2star = eps2 + (1+r)*Sstar;
%Check that FOC holds
Resid = abs(1/C1star - beta*(1+r)*(p/C2_1star + (1-p)/C2_2star) )
%Plot results
T = 1000; %Window around optimum (see below)
plot(Sguess(IndexU-T:IndexU+T),U(IndexU-T:IndexU+T))
ylabel('Expected Utility'), xlabel('S')