File size: 2,019 Bytes
2a8276b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
A     = [Asave,   zeros(2*N, T)];           % Liquid Assets 
Th    = [Thsave,  zeros(2*N, T)];           % initial mortgage size

C     = [Csave,   zeros(2*N, T)];           % consumption
L     = [Lsave,   zeros(2*N, T)];           % liquidity after making housing choice
R     = [Rsave,   zeros(2*N, T)];           % refinance choice
X     = [Xsave,   zeros(2*N, T)];           % amount extracted
Age   = [Agesave, zeros(2*N, T)];           % age of loan


% First simulate history of shocks to income


Y     = randn(N, T)*se; 
Y     = [Ysave, exp([Y; -Y])]; 

S     = ones(2*N, size(Asave, 2) + T);  % interest state


for t = size(Asave, 2) : size(Asave, 2) + T - 1

unif         = rand(2*N, 1); 
    
state        = [(1 + p.rl)*A(:,t) + Y(:,t), Th(:,t), S(:,t)];    

[~, pall, ~, Lall, thetall] = solveh_new(state, Winterp, p);

R(:,t)       = unif <= pall(:,1); 

L(:,t)       = Lall(:,1).*R(:,t) + Lall(:,2).*(1 - R(:,t));        % when many options: generate a single unif and ask which interval belongs to

Th(:, t+1)   = thetall(:,1).*R(:,t) + thetall(:,2).*(1 - R(:,t)); 

cmax         = bisect('savings', 1e-13, 1e5, L(:,t), p, amin);     % c that implies a' = amin
cmin         = bisect('savings', 1e-13, 1e5, L(:,t), p, amax);     % c that implies a' = amax

C(:,t)          = max(min(Cinterp_new(L(:,t), Th(:,t+1), S(:,t+1)), cmax), cmin); 

[~, A(:, t+1)]  = savings(C(:,t), L(:,t), p);
    
Age(:, t+1)     = (Age(:,t) + 1).*(1 - R(:,t)) + R(:,t); 

X(:,t)       = (Th(:,t+1) - Th(:,t))./Th(:,t).*R(:,t); 

S(:,t + 1)   = S(:,t).*(1 - R(:,t)) + p.nr*R(:,t); 

end

 

 
figure(4)

id = 1; 

subplot(1, 3, 1), plot(mean(C)'); 
title('Consumption', 'Interpreter','Latex');
set(gca, 'ygrid', 'on')
set(h,'Interpreter','latex'); 


subplot(1, 3, 2), plot(mean(R)'); 
title('Fraction Refinance', 'Interpreter','Latex');
set(gca, 'ygrid', 'on')
set(h,'Interpreter','latex'); 


subplot(1, 3, 3), plot(mean(Th)'); 
title('LTV', 'Interpreter','Latex');
set(gca, 'ygrid', 'on')
set(h,'Interpreter','latex');