This is a collection of codes that solve a number of heterogeneous agent models in continuous time using finite difference methods

1. Huggett Model (from Achdou et al., 2017): Explanation of Algorithm

HJB equation, explicit method (Section 1.1): HJB_stateconstraint_explicit.m

HJB equation, implicit method (Section 1.2): HJB_stateconstraint_implicit.m

KFE Equation (Section 2, using matrix from HJB implicit method): huggett_partialeq.m

Plotting the asset supply function (Section 3.1): huggett_asset_supply.m

Finding the equilibrium interest rate (Section 3.2): huggett_equilibrium_iterate.m

Transition Dynamics (Section 4): all of (a)-(c) need inputs huggett_initial.m and huggett_terminal.m
(a) simple updating rule: huggett_transition.m
(b) Newton method: huggett_newton.m, huggett_subroutine.m

HJB equation with diffusion, implicit method (section 5.1): HJB_diffusion_implicit.m

KFE Equation (Section 5.2, using HJB matrix): huggett_diffusion_partialeq.m

Credit Crunch (courtesy of Gustavo Mellior): Explanation of Algorithm, huggett_transition_cc.m, huggett_initial_cc.m, huggett_terminal_cc.m, gifmaker.m

Consumption-Saving Problem with Endogenous Labor Supply: Explanation of Algorithm, HJB_labor_supply.m, lab_solve.m

2. Aiyagari Model (from Achdou et al., 2017): Explanation of Algorithm

Stationary Equilibrium with Poisson Process: aiyagari_poisson_steadystate.m

Steady State Asset Supply Function with Poisson Process: aiyagari_poisson_asset_supply.m

Python version (Jupyter notebook): aiyagari_continuous_time.ipynb, should be compared with QuantEcon's discrete-time version of the Aiyagari model

"MIT Shock" with Poisson Income Process: aiyagari_poisson_MITshock.m

Stationary Eq. with Diffusion (Section 6.1, courtesy of Galo Nuno): aiyagari_diffusion_equilibrium.m
C++ version of code: aiyagari_diffusion_equilibrium.cpp (instructions for Mac users, makefile)

Transition Dynamics with Diffusion (Section 6.2): aiyagari_diffusion_transition.m
Julia code for MIT Shock with Diffusion (courtesy of Matthieu Gomez): aiyagari_diffusion_MITshock.jl

Make movie of evolution of wealth distribution (Section 6.4): make_movie.m

Aiyagari Model with Fat-tailed Wealth Distribution (Section 8): fat_tail_partialeq.m, uses non-uniform grid as explained in Section 7.

3. Lifecycle Model: Description of Model and Algorithm

Partial Equilibrium: lifecycle.m

4. Investment under Uncertainty by Heterogeneous Firms: Description of Model and Algorithm

Partial Equilibrium: firm.m

5. Model with Two Assets and Kinked Adjustment Costs: Description of Model and Algorithm

Partial Equilibrium: two_asset_kinked.m
Subroutines: two_asset_kinked_cost.m, two_asset_kinked_FOC.m

6. Handling Non-Convexities I: Neoclassical Growth Model with Convex-Concave Production Function (Skiba, 1978). Description of Model and Algorithm

Finding the "Skiba point": HJB_NGM_skiba.m

7. Handling Non-Convexities II: Entrepreneurship and Financial Frictions. Description of Model and Algorithm

Stationary Equilibrium: entrepreneurs.m

MIT Shock: entrepreneurs_MIT_shock.m

8. Handling Non-Convexities III: Indivisible Housing and Mortgages. Description of Model: see Section 4.3 of Achdou et al. (2017)

Partial Equilibrium: housing.m

9. Stopping Time Problem I: Exercising an Option: Description of Model and Algorithm

Solve as Linear Complementarity Problem (LCP): option_simple_LCP.m plus LCP.m (LCP solver)

10. Stopping Time Problem II: Firm Entry and Exit (Hopenhayn, 1992): Description of Model and Algorithm

Solve as Linear Complementarity Problem (LCP): hopenhayn.m plus LCP.m (LCP solver)

11. Stopping Time Problem III: An Indivisible Durable: Description of Model and Algorithm

Solve as Linear Complementarity Problem (LCP): car.m plus LCP.m (LCP solver)

12. Stopping Time Problem IV: Liquid and Illiquid Assets and Fixed Adjustment Costs: Description of Model and Algorithm

Solve as Linear Complementarity Problem (LCP): liquid_illiquid_LCP.m plus LCP.m (LCP solver) and lininterp1.m (interpolation routine)

13. Stopping Time Problem V: Consumption and Saving with Default (courtesy of Gustavo Mellior and Katsuyuki Shibayama): Description of Model and Algorithm

Solve as LCP: default.m plus LCP.m (LCP solver) and cTsolver.m (subroutine)

14. Consumption, Saving and Wealth Distribution with Hansen-Sargent Robustness Concerns (with Edouard Djeutem): Description of Model and Algorithm

Code: robust.m

15. Labor-Market Matching with Precautionary Savings (courtesy of Bence Bardoczy): Description of Model and Algorithm

Codes: kms.zip

16. Additional Codes: Explanation of Algorithm

No uncertainty, explicit method (Section 1.1): HJB_simple.m, HJB_no_uncertainty_explicit.m

No uncertainty, implicit method (Section 1.2): HJB_no_uncertainty_implicit.m

Neoclassical Growth Model, explicit method (Section 2.1): HJB_NGM.m

Neoclassical Growth Model, implicit method (Section 2.2): HJB_NGM_implicit.m

RBC Model with diffusion for TFP, implicit method: HJB_diffusion_implicit_RBC.m

17. Matthieu Gomez's GitHub Repository with great Julia codes, including the Bansal-Yaron (2004) Long-Run Risk Model

18. Perturbation methods for heterogeneous agent models with aggregate shocks: Paper, Codes, Example 1: using the toolbox to solve Krusell-Smith model, Example 2: using the toolbox to solve a one-asset HANK model

19. Codes for Nuno and Moll (2017), "Social Optima in Economies with Heterogeneous Agents"

SOHA_codes.zip

Old codes for Huggett Model without using Matlab's sparse matrix routines (slower):
HJB_stateconstraint_implicit_old.m
huggett_partialeq_old.m
huggett_asset_supply_old.m
huggett_equilibrium_iterate_old.m
HJB_diffusion_implicit_old.m
huggett_diffusion_partialeq_old.m
aiyagari_diffusion_equilibrium_old.m