Skip to content

Conversation

@jstac
Copy link
Contributor

@jstac jstac commented Nov 16, 2025

This PR addresses issue #707 by extending the basic McCall model to include continuous wage distributions and volatility analysis.

Changes

1. New "Continuous Offer Distribution" Section

  • Moved continuous wage distribution content from exercises into main text
  • Implemented lognormal wage distribution with Monte Carlo integration
  • Added contour plots showing how reservation wage varies with unemployment compensation (c) and discount factor (β)
  • Uses JAX for efficient computation with JIT compilation

2. New "Volatility" Section

  • Demonstrates that reservation wage increases with volatility
  • Uses mean-preserving spread with lognormal distribution
  • Shows mathematical relationship: μ = ln(m) - σ²/2 to maintain constant mean
  • Includes visualization of how reservation wage varies with volatility parameter σ

Key insight: Workers prefer more volatile wage distributions because they can accept high offers while rejecting low ones, leading to higher reservation wages.

3. Updated Exercise mm_ex1

  • Changed solution from discrete to continuous distribution
  • Now uses compute_stopping_time_continuous() with lognormal wages
  • Removed old Numba and discrete JAX solutions for clarity

4. Removed Exercise mm_ex2

  • Content now covered in the main "Continuous Offer Distribution" section
  • Avoids duplication

Testing

  • Converted to Python using jupytext --to py
  • All cells execute successfully
  • Computations are fast (~2-3 seconds total with JAX)

Closes #707

…707)

This commit addresses issue #707 by extending the basic McCall model:

- Add "Continuous Offer Distribution" section
  - Move continuous wage distribution from exercises to main content
  - Implement lognormal wage distribution with Monte Carlo integration
  - Show how reservation wage varies with c and β using contour plots

- Add "Volatility" section
  - Demonstrate that reservation wage increases with volatility
  - Use mean-preserving spread with lognormal distribution
  - Illustrate how workers prefer more volatile distributions

- Update exercise mm_ex1 solution
  - Change from discrete to continuous distribution
  - Use JAX implementation with continuous wage draws

- Remove exercise mm_ex2 (now covered in main text)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@jstac
Copy link
Contributor Author

jstac commented Nov 16, 2025

Implementation Notes

Continuous Distribution Implementation

The continuous wage offer distribution uses:

  • Lognormal wages: w(s) = exp(μ + σs) where s ~ N(0,1)
  • Monte Carlo integration: Averages over 1000 wage draws to evaluate integrals
  • JAX JIT compilation: Significant speedup for iterative computations

Volatility Analysis

The mean-preserving spread is achieved by adjusting μ when varying σ:

  • For lognormal distribution, mean = exp(μ + σ²/2)
  • To maintain constant mean m: μ = ln(m) - σ²/2
  • Results show reservation wage increasing from ~18 to ~21 as σ goes from 0.1 to 1.0

Code Quality

  • All code follows existing style conventions in the lecture
  • Uses JAX's functional programming paradigm with jax.lax.while_loop
  • Vectorized computations with jax.vmap for efficiency
  • Clear documentation in docstrings and comments

Testing

Tested via jupytext --to py mccall_model.md and execution:

  • ✅ All cells execute without errors
  • ✅ Contour plots generate correctly
  • ✅ Volatility visualization shows expected increasing trend
  • ✅ Exercise solution runs successfully with 100,000 Monte Carlo replications

The file is ready for review and merge.

@github-actions
Copy link

📖 Netlify Preview Ready!

Preview URL: https://pr-709--sunny-cactus-210e3e.netlify.app (2ea4ce0)

📚 Changed Lecture Pages: mccall_fitted_vfi, mccall_model

- Add new section showing expected lifetime value increases with volatility
- Implement parallel JAX code for simulating job search with optimal policy
- Use jax.vmap to vectorize 10,000 simulation replications
- Compute reservation wage and lifetime value across volatility levels
- Plot demonstrates option value of search under uncertainty
- Fix LaTeX escape sequence warnings in xlabel (use raw strings)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@jstac
Copy link
Contributor Author

jstac commented Nov 16, 2025

Added new section "Lifetime Value and Volatility" that demonstrates how expected lifetime value increases with volatility under the optimal policy.

Implementation

The section includes:

  • Parallel JAX simulation code using jax.vmap to run 10,000 replications efficiently
  • simulate_lifetime_value(): JIT-compiled function that simulates job search with jax.lax.while_loop
  • compute_mean_lifetime_value(): Vectorized computation across all simulation replications
  • Plot showing expected lifetime value increasing with σ

Key Results

For each volatility level:

  1. Computes the optimal reservation wage
  2. Simulates workers following the optimal policy (accept if wage ≥ reservation wage)
  3. Calculates expected discounted lifetime income over 10,000 replications
  4. Demonstrates that higher volatility → higher lifetime value (option value of search)

The code runs without warnings and complements the existing volatility section that shows reservation wages increase with σ.

🤖 Generated with Claude Code

- Replace while_loop with fixed-period simulation (100 periods)
- Draw all wage offers upfront using vectorized operations
- Use cumsum to track employment status from first acceptance
- Simpler logic that's easier to parallelize (same path length)
- Cleaner code without nested loop functions
- Update description to reflect simplified approach

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@github-actions
Copy link

📖 Netlify Preview Ready!

Preview URL: https://pr-709--sunny-cactus-210e3e.netlify.app (905151e)

📚 Changed Lecture Pages: mccall_fitted_vfi, mccall_model

@jstac
Copy link
Contributor Author

jstac commented Nov 16, 2025

Simplified the lifetime value simulation for better parallelization:

Changes

Replaced the while_loop based simulation with a fixed 100-period approach:

Before: Used jax.lax.while_loop to search until acceptance, then computed analytical present value
After: Draw all 100 wage offers upfront and process vectorially

Key Improvements

  1. Cleaner logic: No nested loop functions, just straightforward array operations
  2. Better parallelization: All simulation paths have the same length
  3. Simpler code:
    • jnp.cumsum(accept) > 0 tracks when employment starts
    • jnp.argmax(accept) finds first accepted wage
    • Vectorized computation of earnings and discounted sum

Code Structure

# Draw 100 wage offers upfront
wage_offers = jnp.exp(μ + σ * s_vals)

# Track employment from first acceptance onward
employed = jnp.cumsum(wage_offers >= w_bar) > 0

# Compute earnings and discounted sum
earnings = jnp.where(employed, accepted_wage, c)
lifetime_value = jnp.sum(discount_factors * earnings)

This approach is cleaner and more efficient for parallel JAX execution, while 100 periods provides sufficient accuracy given β=0.99.

🤖 Generated with Claude Code

@github-actions
Copy link

📖 Netlify Preview Ready!

Preview URL: https://pr-709--sunny-cactus-210e3e.netlify.app (326b343)

📚 Changed Lecture Pages: mccall_fitted_vfi, mccall_model

@github-actions
Copy link

📖 Netlify Preview Ready!

Preview URL: https://pr-709--sunny-cactus-210e3e.netlify.app (e609076)

📚 Changed Lecture Pages: mccall_fitted_vfi, mccall_model

@jstac jstac merged commit b37d0ca into main Nov 16, 2025
1 check failed
@jstac jstac deleted the issue-707-mccall-volatility branch November 16, 2025 08:46
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.

Extension to basic mccall model -- response to volatility

2 participants