|
|
function err_mom = objective(x)
|
|
|
|
|
|
set(groot, 'DefaultAxesLineWidth', 1.5);
|
|
|
set(groot, 'DefaultLineLineWidth', 4);
|
|
|
set(groot, 'DefaultAxesTickLabelInterpreter','latex');
|
|
|
set(groot, 'DefaultLegendInterpreter','latex');
|
|
|
set(groot, 'DefaultAxesFontSize',22);
|
|
|
|
|
|
intmeth = 'linear';
|
|
|
printr = 0;
|
|
|
|
|
|
optset('bisect', 'tol', 1e-32);
|
|
|
|
|
|
|
|
|
|
|
|
p.beta = x(1);
|
|
|
p.alpha = x(2);
|
|
|
p.R = x(3);
|
|
|
p.phi = x(4);
|
|
|
p.F0m = x(5);
|
|
|
p.B = x(6);
|
|
|
p.r1 = x(7);
|
|
|
p.r2 = x(8);
|
|
|
p.rh = (1 + x(9))^(1/4) - 1;
|
|
|
p.rr = x(10);
|
|
|
p.hr = x(11);
|
|
|
|
|
|
|
|
|
|
|
|
p.nu = 3;
|
|
|
|
|
|
p.pidelta = [0.975; 0.025];
|
|
|
p.delta = [0; 0.0625];
|
|
|
|
|
|
p.rl = (1 - 0.028)^(1/4) - 1;
|
|
|
|
|
|
p.T = 61*4;
|
|
|
p.D = 30*4;
|
|
|
|
|
|
p.sigma = 2;
|
|
|
p.gamma = 1;
|
|
|
|
|
|
p.rm = (1 + 0.025)^(1/4) - 1;
|
|
|
|
|
|
p.Fs = 0.06;
|
|
|
p.F1m = 0.005;
|
|
|
|
|
|
p.wbar = 1;
|
|
|
|
|
|
p.thetam = 0.85;
|
|
|
p.thetay = 0.214;
|
|
|
|
|
|
rhoz = 0.9908;
|
|
|
sz = 0.0761;
|
|
|
se = (1 - 0.55)^(1/2)*0.4869;
|
|
|
|
|
|
time = (1 : 1 : p.T)';
|
|
|
p.lambdat = exp(0.07982636 - 0.02322307 * (time/4 + 25) + 0.00105409 * (time/4 + 25).^2 - 0.00001028 * (time/4 + 25).^3);
|
|
|
|
|
|
p.thetay = p.thetay*(1 - 0.3126./(1 + exp(18.629 - 0.3049*(time/4 + 25))));
|
|
|
|
|
|
p.mbar = p.rm/(1 - (1 + p.rm)^(-p.D)); % minimum payment required per 1 of initial debt
|
|
|
|
|
|
|
|
|
% Quality of Approximation
|
|
|
|
|
|
p.na = 75; % number of nodes for liquid assets
|
|
|
p.nat = 75; % number of nodes for atilde = (1 + rl)*a - delta*h
|
|
|
p.nl = 75; % number of nodes for liquidity
|
|
|
p.no = 11; % number of nodes for omega (fraction of loan outstanding)
|
|
|
p.nt = 5; % number of possible initial LTV
|
|
|
p.nh = 7; % number of nodes for housing
|
|
|
p.nz = 9; % points for exogenous income z
|
|
|
p.ne = 3;
|
|
|
|
|
|
|
|
|
% Discretize Income Process
|
|
|
|
|
|
[zgrid, Fzz] = rouwenhorst(rhoz, sz, p.nz);
|
|
|
zgrid = exp(zgrid');
|
|
|
p.zgrid = zgrid;
|
|
|
|
|
|
[Fz, d] = eigs(Fzz', 1, 'largestabs');
|
|
|
Fz = Fz/sum(Fz);
|
|
|
Fz = full(Fz); % ergodic distribution of z
|
|
|
|
|
|
[egrid, we] = qnwnorm(p.ne, 0, se^2);
|
|
|
egrid = exp(egrid);
|
|
|
p.egrid = egrid;
|
|
|
|
|
|
|
|
|
% Discretize other state variables
|
|
|
|
|
|
amin = -0.4;
|
|
|
amax = 100;
|
|
|
p.agrid = amin + (amax - amin)*nodeunif(p.na, 0, 1).^2;
|
|
|
|
|
|
omin = 0;
|
|
|
omax = 1;
|
|
|
p.ogrid = omin + (omax - omin)*nodeunif(p.no, 0, 1);
|
|
|
|
|
|
tmin = 0.25;
|
|
|
tmax = p.thetam; % allow to cover fixed cost
|
|
|
p.tgrid = tmin + (tmax - tmin)*nodeunif(p.nt, 0, 1);
|
|
|
|
|
|
hmin = 5; % minimum house size
|
|
|
hmax = 40; % maximum house size
|
|
|
p.hgrid = hmin + (hmax - hmin)*nodeunif(p.nh, 0, 1).^1.5;
|
|
|
|
|
|
ymin = min(p.lambdat)*zgrid(1)*egrid(1);
|
|
|
ymax = max(p.lambdat)*zgrid(end)*egrid(end);
|
|
|
|
|
|
lmin = -1; % keep it reasonably negative so they know that's a bad state to find yourself in
|
|
|
lmax = 125;
|
|
|
p.lgrid = lmin + (lmax - lmin)*nodeunif(p.nl, 0, 1).^1.5;
|
|
|
|
|
|
atmin = -p.delta(2)*hmax + (1 + p.rl)*amin;
|
|
|
atmax = (1 + p.rh)*amax;
|
|
|
p.atgrid = atmin + (atmax - atmin)*nodeunif(p.nat, 0, 1).^1.5;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
svbarh = gridmake(p.agrid, p.ogrid, p.tgrid, p.hgrid, p.zgrid);
|
|
|
svbarr = gridmake(p.agrid, p.zgrid);
|
|
|
|
|
|
svh = gridmake(p.atgrid, p.ogrid, p.tgrid, p.hgrid, p.zgrid, p.egrid);
|
|
|
svr = gridmake(p.atgrid, p.zgrid, p.egrid);
|
|
|
|
|
|
swh = gridmake(p.lgrid, p.ogrid, p.tgrid, p.hgrid, p.zgrid);
|
|
|
swr = gridmake(p.lgrid, p.zgrid);
|
|
|
|
|
|
svht = gridmake(p.agrid, p.ogrid, p.tgrid, p.hgrid, p.zgrid, p.egrid);
|
|
|
svrt = gridmake(p.agrid, p.zgrid, p.egrid);
|
|
|
|
|
|
ind2h = kron((1:1:p.no*p.nt*p.nh*p.nz)', ones(p.nl, 1)); % index of all other state-variables to speed up evaluations (Bangladesh)
|
|
|
ind2r = kron((1:1: p.nz)', ones(p.nl, 1));
|
|
|
|
|
|
ind3h = kron((1:1:p.no*p.nt*p.nh*p.nz*p.ne)', ones(p.na, 1)); % index of all other state-variables to speed up evaluations (Bangladesh)
|
|
|
ind3r = kron((1:1: p.nz*p.ne)', ones(p.na, 1));
|
|
|
|
|
|
|
|
|
vbarh = zeros(p.na*p.no*p.nt*p.nh*p.nz, p.T + 1);
|
|
|
vbarr = zeros(p.na*p.nz, p.T + 1);
|
|
|
|
|
|
vh = zeros(p.nat*p.no*p.nt*p.nh*p.nz*p.ne, p.T);
|
|
|
vr = zeros(p.nat*p.nz*p.ne, p.T);
|
|
|
|
|
|
wh = zeros(p.nl*p.no*p.nt*p.nh*p.nz, p.T);
|
|
|
wr = zeros(p.nl*p.nz, p.T);
|
|
|
|
|
|
ch = zeros(p.nl*p.no*p.nt*p.nh*p.nz, p.T);
|
|
|
cr = zeros(p.nl*p.nz, p.T);
|
|
|
|
|
|
cmaxh = bisect('savings', 1e-13, 1e5, p.lgrid, p, 'h', amin);
|
|
|
cmaxr = bisect('savings', 1e-13, 1e5, p.lgrid, p, 'r', amin);
|
|
|
|
|
|
cminh = bisect('savings', 1e-13, 1e5, p.lgrid, p, 'h', amax);
|
|
|
cminr = bisect('savings', 1e-13, 1e5, p.lgrid, p, 'r', amax);
|
|
|
|
|
|
cmaxh = repmat(cmaxh, p.no*p.nt*p.nh*p.nz, 1);
|
|
|
cmaxr = repmat(cmaxr, p.nz, 1);
|
|
|
|
|
|
cminh = repmat(cminh, p.no*p.nt*p.nh*p.nz, 1);
|
|
|
cminr = repmat(cminr, p.nz, 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rlh = 1./(1 + exp(-p.r1*(svbarh(:,1) - p.r2)))*(p.rh - p.rl) + p.rl;
|
|
|
rlr = 1./(1 + exp(-p.r1*(svbarr(:,1) - p.r2)))*(p.rh - p.rl) + p.rl;
|
|
|
|
|
|
vbarh(:, p.T + 1) = p.pidelta(1)*p.B*(p.wbar + (1 + rlh).*svbarh(:,1) + (1 - p.Fs - svbarh(:,2).*svbarh(:,3)*(1 + p.rm) - p.delta(1)).*svbarh(:,4)).^(1 - p.sigma)/(1 - p.sigma) + ...
|
|
|
p.pidelta(2)*p.B*(p.wbar + (1 + rlh).*svbarh(:,1) + (1 - p.Fs - svbarh(:,2).*svbarh(:,3)*(1 + p.rm) - p.delta(2)).*svbarh(:,4)).^(1 - p.sigma)/(1 - p.sigma);
|
|
|
|
|
|
vbarr(:, p.T + 1) = p.B*(p.wbar + (1 + rlr).*svbarr(:,1)).^(1 - p.sigma)/(1 - p.sigma);
|
|
|
|
|
|
|
|
|
for t = p.T : -1 : 1
|
|
|
|
|
|
EVh = griddedInterpolant({p.agrid, (1: 1:p.no*p.nt*p.nh*p.nz)'}, reshape(vbarh(:, t + 1), p.na, p.no*p.nt*p.nh*p.nz), intmeth, 'linear');
|
|
|
EVr = griddedInterpolant({p.agrid, (1: 1: p.nz)'}, reshape(vbarr(:, t + 1), p.na, p.nz), intmeth, 'linear');
|
|
|
|
|
|
|
|
|
|
|
|
ch(:, t) = solve_golden('wfunc', cminh, cmaxh, swh, ind2h, EVh, p, 'h');
|
|
|
cr(:, t) = solve_golden('wfunc', cminr, cmaxr, swr, ind2r, EVr, p, 'r');
|
|
|
|
|
|
wh(:, t) = wfunc(ch(:, t), swh, ind2h, EVh, p, 'h');
|
|
|
wr(:, t) = wfunc(cr(:, t), swr, ind2r, EVr, p, 'r');
|
|
|
|
|
|
Whinterp = griddedInterpolant({p.lgrid, (1: 1: p.no*p.nt*p.nh*p.nz)'}, reshape(wh(:, t), p.nl, p.no*p.nt*p.nh*p.nz), intmeth, 'linear');
|
|
|
Wrinterp = griddedInterpolant({p.lgrid, (1: 1: p.nz)'}, reshape(wr(:, t), p.nl, p.nz), intmeth, 'linear');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
At = svr(:,1);
|
|
|
Y = p.lambdat(t)*svr(:,2).*svr(:,3);
|
|
|
znow = repmat(kron((1: 1 : p.nz)', ones(p.nat, 1)), p.ne, 1); % index of z in (a, z, e) space for renters
|
|
|
|
|
|
[~, ~, ~, ~, vr(:,t)] = solveh(svr, Whinterp, Wrinterp, p, p.thetay(t), 'r', At, Y, znow);
|
|
|
|
|
|
% Solve discrete choice problem of housing
|
|
|
|
|
|
At = svh(:,1);
|
|
|
Y = p.lambdat(t)*svh(:,5).*svh(:,6);
|
|
|
|
|
|
znow = repmat(kron((1: 1 : p.nz)', ones(p.nat*p.no*p.nt*p.nh, 1)), p.ne, 1);
|
|
|
hnow = repmat(kron((1: 1 : p.nh)', ones(p.nat*p.no*p.nt, 1)), p.nz*p.ne, 1); % index of h in (a, omega, theta, h, z, e) space for owners
|
|
|
tnow = repmat(kron((1: 1 : p.nt)', ones(p.nat*p.no, 1)), p.nh*p.nz*p.ne, 1);
|
|
|
|
|
|
|
|
|
[~, ~, ~, ~, vh(:,t)] = solveh(svh, Whinterp, Wrinterp, p, p.thetay(t), 'h', At, Y, znow, hnow, tnow);
|
|
|
|
|
|
|
|
|
|
|
|
Vhinterp = griddedInterpolant({p.atgrid, (1: 1:p.no*p.nt*p.nh*p.nz*p.ne)'}, reshape(vh(:, t), p.nat, p.no*p.nt*p.nh*p.nz*p.ne), intmeth, 'linear');
|
|
|
Vrinterp = griddedInterpolant({p.atgrid, (1: 1: p.nz*p.ne)'}, reshape(vr(:, t), p.nat, p.nz*p.ne), intmeth, 'linear');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vhtemp = p.pidelta(1)*Vhinterp((1 + interest(svht(:,1), p)).*svht(:,1) - p.delta(1)*svht(:, 4), ind3h) + p.pidelta(2)*Vhinterp((1 + interest(svht(:,1), p)).*svht(:,1) - p.delta(2)*svht(:, 4), ind3h);
|
|
|
|
|
|
vrtemp = Vrinterp((1 + interest(svrt(:,1), p)).*svrt(:,1), ind3r);
|
|
|
|
|
|
|
|
|
for i = 1 : p.ne
|
|
|
|
|
|
vbarh(:,t) = vbarh(:,t) + we(i)*kronm({p.na*p.no*p.nt*p.nh, Fzz}, vhtemp((i - 1)*p.na*p.no*p.nt*p.nh*p.nz + 1 : i*p.na*p.no*p.nt*p.nh*p.nz));
|
|
|
vbarr(:,t) = vbarr(:,t) + we(i)*kronm({p.na, Fzz}, vrtemp((i - 1)*p.na*p.nz + 1 : i*p.na*p.nz));
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
simulate
|
|
|
|