File size: 5,751 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 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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
clear;
clc;
set(groot, 'DefaultAxesLineWidth', 1.5);
set(groot, 'DefaultLineLineWidth', 4);
set(groot, 'DefaultAxesTickLabelInterpreter','latex');
set(groot, 'DefaultLegendInterpreter','latex');
set(groot, 'DefaultAxesFontSize',22);
intmeth = 'spline';
printr = 1;
optset('bisect', 'tol', 1e-32);
% Calibrated Parameters
p.beta = 0.992; % discount factor
p.F = 0.22; % fixed cost of refinancing
p.phi = 1; % productivity non-market
p.nu = 3; % 1 / volatility of extreme value shocks
% Assigned Parameters
p.rm = (1 + 0.025)^(1/4) - 1; % mortgage rate
p.rl = (1 + 0.010)^(1/4) - 1; % liquid rate
p.D = 120; % maturity of mortgages
p.sigma = 2; % CRRA
p.gamma = 1;
p.thetam = 0.85; % maximum LTV
se = (1 - 0.55)^(1/2)*0.4869; % Krueger Perri (2011) show 55% of the variance of trans compon is measurement error so subtract
p.mbar = p.rm/(1 - (1 + p.rm)^(-p.D))*p.thetam; % minimum payment required per 1 of initial debt
p.hbar = 8; % house size
% Quality of Approximation
p.na = 250; % number of nodes for liquid assets
p.nw = 250; % number of nodes for cash on hand
p.nl = 250; % number of nodes for liquidity
p.nt = 75;
p.ny = 71;
% Discretize Income Process
%[y, wy] = qnwnorm(p.ny, 0, se^2);
%y = exp(y);
[y, wy] = qnwunif(p.ny, 0, 1);
y = norminv(y, 0, 1)*se;
y = exp(y);
% Discretize other state variables
amin = 0;
amax = 50;
p.agrid = amin + (amax - amin)*nodeunif(p.na, 0, 1).^2;
wmin = min(y);
wmax = (1 + p.rl)*amax + max(y);
p.wgrid = wmin + (wmax - wmin)*nodeunif(p.nw, 0, 1).^2;
lmin = -0.5;
lmax = wmax + p.hbar;
p.lgrid = lmin + (lmax - lmin)*nodeunif(p.nl, 0, 1).^2;
p.tgrid = nodeunif(p.nt, 0, p.thetam);
% Construct grids:
sv = gridmake(p.wgrid, p.tgrid); % grid for V
sw = gridmake(p.lgrid, p.tgrid); % grid for W
svbar = gridmake(p.agrid, p.tgrid); % grid for Vbar (expected continuation value)
% Bounds on consumption mid-period
cmax = bisect('savings', 1e-13, 1e5, p.lgrid, p, amin); % c that implies a' = amin
cmin = bisect('savings', 1e-13, 1e5, p.lgrid, p, amax); % c that implies a' = amax
cmax = repmat(cmax, p.nt, 1);
cmin = repmat(cmin, p.nt, 1);
% Initial guess for value function
Vbar = zeros(p.na*p.nt, 1);
for iter = 1 : 5
Vbarold = Vbar;
EV = griddedInterpolant({p.agrid, p.tgrid}, reshape(Vbar, p.na, p.nt), intmeth, 'linear');
% solve consumption-savings choice
c = solve_golden('wfunc', cmin, cmax, sw, EV, p);
[~, aprime] = savings(c, sw, p);
W = wfunc(c, sw, EV, p);
Winterp = griddedInterpolant({p.lgrid, p.tgrid}, reshape(W, p.nl, p.nt), intmeth, 'linear');
% Solve discrete choice problem
V = solveh(sv, Winterp, p);
% Interpolate V(w, theta)
Vinterp = griddedInterpolant({p.wgrid, p.tgrid}, reshape(V, p.nw, p.nt), intmeth, 'linear');
% Compute expected value and update vbar
Vbar = zeros(p.na*p.nt, 1);
for i = 1 : p.ny
Vbar = Vbar + wy(i)*Vinterp((1 + p.rl)*svbar(:,1) + y(i), svbar(:,2));
end
fprintf('%4i %6.2e \n', [iter, norm(Vbar - Vbarold)/norm(Vbar)]);
end
% Apply Howard Improvement to Go Faster
for iter = 1 : 5000
Vbarold = Vbar;
EV = griddedInterpolant({p.agrid, p.tgrid}, reshape(Vbar, p.na, p.nt), intmeth, 'linear');
% solve consumption-savings choice
if mod(iter, 50) == 0
c = solve_golden('wfunc', cmin, cmax, sw, EV, p);
end
[~, aprime] = savings(c, sw, p);
W = wfunc(c, sw, EV, p);
Winterp = griddedInterpolant({p.lgrid, p.tgrid}, reshape(W, p.nl, p.nt), intmeth, 'linear');
% Solve discrete choice problem
V = solveh(sv, Winterp, p);
% Interpolate V(w, theta)
Vinterp = griddedInterpolant({p.wgrid, p.tgrid}, reshape(V, p.nw, p.nt), intmeth, 'linear');
% Compute expected value and update vbar
Vbar = zeros(p.na*p.nt, 1);
for i = 1 : p.ny
Vbar = Vbar + wy(i)*Vinterp((1 + p.rl)*svbar(:,1) + y(i), svbar(:,2));
end
if mod(iter, 50) == 0
fprintf('%4i %6.2e \n', [iter/50, norm(Vbar - Vbarold)/norm(Vbar)]);
if norm(Vbar - Vbarold)/norm(Vbar) < 1e-7, break, end
end
end
Cinterp = griddedInterpolant({p.lgrid, p.tgrid}, reshape(c, p.nl, p.nt), intmeth, 'linear');
plot_decisions
return
simulate
start_new
Cinterp_new = griddedInterpolant({p.lgrid, p.tgrid, p.rgrid}, reshape(c, p.nl, p.nt, p.nr), intmeth, 'linear');
simulate_new |