-
Notifications
You must be signed in to change notification settings - Fork 6
/
Life_cycle_2_periods_portfolio.m
60 lines (45 loc) · 1.6 KB
/
Life_cycle_2_periods_portfolio.m
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
% Two-period life-cycle porfolio model
% Written by Michael Hatcher ([email protected]) in 2017.
clc; clear;
% Parameter values
beta = 0.96; r = 0.05; Y1 = 1; p = 0.99;
eps1 = 0.0107; eps2 = -0.7;
Nguess = 2000;
Nguess2 = 2000;
for i=1:Nguess
for j=1:Nguess2
Sguess(i) = 0.5*(i-1)/Nguess;
Bguess(j) = 0.5*(j-1)/Nguess2;
S = Sguess(i);
B = Bguess(j);
C1 = Y1 - S - B;
C2_1 = (1+r)*B + (1+r+eps1)*S ;
C2_2 = (1+r)*B + (1+r+eps2)*S;
U(i,j) = log(C1) + beta*( p*log(C2_1) + (1-p)*log(C2_2) );
end
end
%Find maximum of utility w.r.t. S guesses
MN = max(U'); %row vector containing max for each column (note: transposed)
[MN1, Index_S] = max(MN);
Index_S
%Find maximum of utility w.r.t. B guesses
MN3 = max(U); %row vector containing max for each column (note: not transposed)
[MN4, Index_B] = max(MN3);
Index_B
disp('Optimal holding of shares is')
Sguess(Index_S)
disp('Optimal holding of bonds is')
Bguess(Index_B)
Bstar = Bguess(Index_B);
Sstar = Sguess(Index_S);
C1star = Y1 - Sstar - Bstar;
C2_1star = (1+r)*Bstar + (1+r+eps1)*Sstar;
C2_2star = (1+r)*Bstar + (1+r+eps2)*Sstar;
%Check that FOCs hold
Resid = abs( 1/C1star - beta*(1+r)*(p/C2_1star + (1-p)/C2_2star) )
Resid2 = abs( 1/C1star - beta*( p*(1+r+eps1)/C2_1star + (1-p)*(1+r+eps2)/C2_2star ) )
%Plot results
T = 40; %Window around optimum (see below)
surf( Sguess(Index_S-T:Index_S+T), Bguess(Index_B-T:Index_B+T),...
U(Index_S-T:Index_S+T, Index_B-T:Index_B+T) )
xlabel('S'), ylabel('B'), zlabel('Expected Utility, U')