QuantEcon ยท GitHub

Commit 8bfb282

jstacclaude

and

authored

Add new lecture: Aiyagari model with Endogenous Grid Method (#676)

* Add new lecture: Aiyagari model with Endogenous Grid Method This PR adds a new lecture aiyagari_egm.md that combines the Aiyagari model with the Endogenous Grid Method (EGM). Key Features: - Combines concepts from egm_policy_iter.md and aiyagari.md - Uses EGM to solve the household problem (avoiding costly root-finding) - Uses simulation to compute aggregate capital (instead of analytical stationary distribution) - EGM operator for the Aiyagari model - Corrected implementation, converges in ~90 iterations - Simulation-based aggregation - Simulates 10,000+ households via Monte Carlo - Equilibrium computation - Uses bisection to find equilibrium capital stock (K* โ‰ˆ 8) - Wealth distribution analysis - Histograms, Lorenz curves, and Gini coefficient - Educational content - Comparison with standard approach and four exercises ๐Ÿค– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * misc * Rewrite aiyagari_egm as a single fully-JAX implementation Reworks the lecture so the EGM operator, the household solver and the cross-section simulation are all JIT-compiled and vectorized in JAX, matching the conventions in os_egm_jax. - Remove the broken @jax.jit `K_egm` (data-dependent Python branch) and the unusable jitted `simulate_households` (per-household Python loops); keep a single vectorized `K_egm` and one `simulate_cross_section`. - Solver now uses `jax.lax.while_loop`; simulation uses `jax.lax.fori_loop` with vmap-ed interpolation and inverse-CDF Markov transitions. - Drop the unused numba import; use deterministic PRNG keys so bisection sees a deterministic excess-demand function. - Use qe.lorenz_curve / qe.gini_coefficient instead of hand-rolled np.trapz. Runs end-to-end: K* = 8.15, r* = 0.031, Gini = 0.36, Euler residual 8e-07. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>

2 files changed

Lines changed: 714 additions & 0 deletions

File tree

  • lectures

Lines changed: 1 addition & 0 deletions

Original file line numberDiff line numberDiff line change

@@ -129,6 +129,7 @@ parts:

129129

- file: markov_perf

130130

- file: uncertainty_traps

131131

- file: aiyagari

132+

- file: aiyagari_egm

132133

- file: ak2

133134

- file: ak_aiyagari

134135

- file: two_computation

Read the original on github.com โ†—