File size: 2,794 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
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

close all

% Inaction Region

figure(1)

[~, pall]           = solveh_new(sv, Winterp, p);

data = [sv(1 : p.na*p.nt, 1 : 2), pall(1 : p.na*p.nt, 1)]; 
data = data(data(:,1) <= 3, :); 

n1   = numel(unique(data(:,1)));
n2   = numel(unique(data(:,2)));

surf(reshape(data(:,1), n1, n2), reshape(data(:,2), n1, n2), reshape(data(:,3), n1, n2)); colorbar 

xlabel('$w$', 'Interpreter', 'Latex');
ylabel('$\theta$', 'Interpreter', 'Latex');
title('probability refinance', 'Interpreter', 'Latex');
xlim([0, 3])


state = gridmake(nodeunif(100, wmin, 3), 0.7, 2); 

[v, pall, vall, Lall, thetaall] = solveh_new(state, Winterp, p);

call         = zeros(size(pall)); 
aprimeall    = zeros(size(pall)); 
sall         = [state(:,3), 2*ones(size(state, 1), 1)]; 

for i = 1 : 2

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

call(:,i)    = solve_golden('wfunc_new', cmin, cmax, [Lall(:,i), thetaall(:,i), sall(:,i)], EV, p);

[~, aprimeall(:,i)]  = savings(call(:,i), Lall(:,i), p);

end

figure(2)

subplot(2, 3, 1)
plot(state(:,1), pall(:,1));
set(gca, 'ygrid', 'on')
xlabel('$w$', 'Interpreter', 'Latex');
title('probability refinance', 'Interpreter', 'Latex');

subplot(2, 3, 2)
plot(state(:,1), Lall);
set(gca, 'ygrid', 'on')
xlabel('$w$', 'Interpreter', 'Latex');
title('$l$', 'Interpreter', 'Latex');
legend('refinance', 'dont refinance')

subplot(2, 3, 3)
plot(state(:,1), thetaall);
set(gca, 'ygrid', 'on')
xlabel('$w$', 'Interpreter', 'Latex');
title('$\theta^{\prime}$', 'Interpreter', 'Latex');

subplot(2, 3, 4)
plot(state(:,1), call);
set(gca, 'ygrid', 'on')
xlabel('$w$', 'Interpreter', 'Latex');
title('$c$', 'Interpreter', 'Latex');

subplot(2, 3, 5)
plot(state(:,1), aprimeall);
set(gca, 'ygrid', 'on')
xlabel('$w$', 'Interpreter', 'Latex');
title('$a^{\prime}$', 'Interpreter', 'Latex');


subplot(2, 3, 6)
plot(state(:,1), [vall, v]);
set(gca, 'ygrid', 'on')
xlabel('$w$', 'Interpreter', 'Latex');
title('values', 'Interpreter', 'Latex');
legend('refinance', 'dont refinance', 'envelope')


figure(3)

state = gridmake(nodeunif(100, lmin, 3), 0.5, 1); 

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

c     = solve_golden('wfunc_new', cmin, cmax, state, EV, p);

[~, aprime]  = savings(c, state, p);


subplot(1, 2, 1)
plot(state(:,1), c);
set(gca, 'ygrid', 'on')
xlabel('$l$', 'Interpreter', 'Latex');
title('$c$', 'Interpreter', 'Latex');

subplot(1, 2, 2)
plot(state(:,1), aprime);
set(gca, 'ygrid', 'on')
xlabel('$w$', 'Interpreter', 'Latex');
title('$a^{\prime}$', 'Interpreter', 'Latex');