This repository contains Matlab implementation of EGM and DC-EGM algorithms for solving dynamic stochastic lifecycle models of consumption and savings, with additional discrete choices.
Three models are solved using these methods:
- Phelps model of consumption and savings with stochastic returns (and credit constraints) (EGM)
- Deaton model of consumption and savings with idiosyncratic wage shocks and credit constraints (EGM)
- Model of consumption, saving and retirement decisions with idiosyncratic wage shocks, credit constraints and absorbing retirement (DC-EGM)
The code also contains the polyline.m
class which presents a set of tools for working with linearly interpolated functions, including the upper envelope algorithm.
The code also contains the easy start implementation of EGM algorithm in just 13 lines of code.
- Christopher D. Carroll "[The method of endogenous gridpoints for solving dynamic stochastic optimization problems] (http://www.sciencedirect.com/science/article/pii/S0165176505003368)" (Economics Letters, 2006)
- Iskhakov, Jorgensen, Rust and Schjerning "[The Endogenous Grid Method for Discrete-Continuous Dynamic Choice Models with (or without) Taste Shocks] (http://onlinelibrary.wiley.com/doi/10.3982/QE643/full)" (Quantitative Economics, 2017)
Lecture notes from the DSE2019 lecture on DC-EGM https://github.com/dseconf/DSE2019/blob/master/11_DCEGM_Iskhakov/slides/dcegm_DSE2019.pdf
- Make sure the files are in the Matlab work directory
- Run
addpath('utils')
(this is done automatically inrun.m
script) - Run your script, or run
run.m
for examples
The minimal implementation of the EGM algorithms for the stochastic consumption-savings lifecycle model with credit constraints is
% Parameters
EXPN=10 % Number of quadrature points to calculate expectation
MMAX=10 % Maximum wealth
NM=100 % Number of grid points
TBAR=25 % Number of time periods
SIGMA=0.25 % Sigma parameter in logNormal distribution
Y=1 % Wage income
R=0.05 % Interest rate
DF=0.95 % Discount factor
% 13 lines EGM implementation
[quadp quadw]=quadpoints(EXPN,0,1); % create quadrature notes and weights
quadstnorm=norminv(quadp,0,1); % prepare quadrature points for calculation of expectations of Normal
savingsgrid=linspace(0,MMAX,NM); % post-decision grid on savings
policy{TBAR}.w=[0 MMAX]; % terminal period wealth
policy{TBAR}.c=[0 MMAX]; % terminal period optimal consumption
for it=TBAR-1:-1:1 % main backwards induction loop
w1=Y+exp(quadstnorm*SIGMA)*(1+R)*savingsgrid; % next period wealth (budget equation), matrix for all savings and all shocks
c1=interp1(policy{it+1}.w,policy{it+1}.c,w1,'linear','extrap'); %next period optimal consumption
rhs=quadw'*(1./c1); % RHS of the Euler equation (with log utility)
policy{it}.c=[0 1./(DF*(1+R)*rhs)]; % current period optimal consumption rule
policy{it}.w=[0 savingsgrid+policy{it}.c(2:end)]; % current period endogenous grid on wealth
end
% Plot the optimal policy functions
for it=TBAR:-1:1
plot(policy{it}.w,policy{it}.c)
hold all
end
set(gca,'XLim',[0 MMAX])
xlabel(gca,'Wealth')
ylabel(gca,'Optimal consumption')
title(gca,'Optimal consumption rules by age')
The solution of the problems is a set of policy function saved in policy
structure.
Retirement model: optimal consumption rules, value functions and probability to remain working (DC-EGM)
Note the kinks in the value function of the worker and discontinuities in the optimal consumption rules.
The kinks in the value function of the worker and discontinuities in the optimal consumption rules are smoothed with extreme value distributed taste shocks
Simulated wealth and consumption profiles, and the histogram of simulated retirement ages