Skip to content

Conversation

@jstac
Copy link
Contributor

@jstac jstac commented Nov 28, 2025

Summary

This PR fixes the simulation code in ifp_advanced.md to properly handle stochastic returns on assets and improves the wealth inequality analysis.

Key Changes

Simulation Fixes

  • Fixed stochastic returns: Simulation now properly implements R_t = R(Z_t, ζ_t) by drawing ζ shocks each period
  • Corrected NamedTuple unpacking: Fixed all unpacking of the IFP NamedTuple throughout simulation functions
  • Added missing shocks: simulate_household now draws both η (income) and ζ (return) shocks

Model Calibration

  • Increased grid_max: Changed from 10 to 100 for better coverage of wealth distribution tail
  • Calibrated return volatility: Set a_r=0.16 to produce realistic wealth inequality (Gini ≈ 0.787)
  • Larger simulation: Increased to 200,000 households for better tail estimates

Visualization Improvements

  • Better histogram: Changed to log y-axis (instead of log x-axis) for clearer wealth distribution visualization
  • Removed Lorenz curve: Simplified to single histogram plot
  • Added diagnostics: Shows grid coverage statistics to verify extrapolation issues resolved

Educational Content

  • New exercise: Asks students to explore how Gini coefficient varies with return volatility (a_r from 0.10 to 0.16)
  • Complete solution: Includes code and interpretation showing nonlinear relationship between volatility and inequality

Results

The corrected model produces realistic wealth inequality:

  • Gini coefficient: 0.787 (empirical US ≈ 0.8)
  • Top 1% wealth share: 73% (higher than empirical ~30%, but demonstrates capital income risk effects)
  • Grid coverage: 99.98% (excellent, only 0.02% of households beyond grid)

The exercise solution reveals a fascinating threshold effect: inequality increases gradually until a_r ≈ 0.15, then jumps dramatically.

Technical Notes

  • Fixed code cell language consistency (all ipython3) to prevent Jupyter Book build warnings
  • Maintained all function definitions and model structure
  • Results demonstrate that stochastic returns are crucial for generating realistic wealth inequality

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

- Fix simulation code to properly handle stochastic returns R_t = R(Z_t, ζ_t)
- Add ζ shock draws in simulate_household function
- Correct NamedTuple unpacking throughout simulation code
- Increase grid_max to 100 for better coverage of wealth distribution
- Calibrate return volatility (a_r=0.16) to match empirical inequality
- Increase simulation to 200,000 households for better tail estimates
- Replace Lorenz curve with histogram using log y-axis for clearer visualization
- Add exercise exploring relationship between return volatility and inequality
- Include solution showing nonlinear Gini-volatility relationship
- Fix code cell language consistency (ipython3) for Jupyter Book compatibility

Results: Gini coefficient of 0.787 (close to empirical ~0.8)

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
@jstac
Copy link
Contributor Author

jstac commented Nov 28, 2025

Testing Summary

All code has been thoroughly tested:

Model Solution

  • Converges in 123 iterations with grid_max=100 and a_r=0.16
  • Proper handling of stochastic returns confirmed through diagnostics

Grid Coverage Analysis

Grid max: 100.00
Endogenous grid max: 105.25
Simulated assets max: 458,807.50
Fraction beyond grid: 0.02%

Excellent coverage with minimal extrapolation issues.

Inequality Measures

Main simulation produces:

  • Gini: 0.7870
  • Top 1% share: 73.33%

Exercise Solution

Tested across 7 values of a_r (0.10 to 0.16), showing clear nonlinear relationship between return volatility and wealth inequality.

Build Compatibility

  • All code cells now use ipython3 consistently
  • No jupytext warnings
  • Ready for Jupyter Book build

The lecture now correctly demonstrates how stochastic returns generate realistic wealth inequality! 🎉

@github-actions
Copy link

📖 Netlify Preview Ready!

Preview URL: https://pr-748--sunny-cactus-210e3e.netlify.app (3e230d4)

📚 Changed Lecture Pages: ifp_advanced

@jstac jstac merged commit 57b1b34 into main Nov 28, 2025
1 check passed
@jstac jstac deleted the fadv branch November 28, 2025 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants