Commit 8bfb282
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>1 parent 8f0e37c commit 8bfb282
2 files changed
Lines changed: 714 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
| |||
0 commit comments