GitHub

@@ -388,8 +388,8 @@ Here's the Coleman-Reffett operator using JAX:

388388389389

```{code-cell} ipython3

390390

def K(

391-

a_in: jnp.array, # a_in[i, z] is an asset grid

392391

c_in: jnp.array, # c_in[i, z] = consumption at a_in[i, z]

392+

a_in: jnp.array, # a_in[i, z] is an asset grid

393393

ifp: IFP

394394

):

395395

"""

@@ -430,7 +430,7 @@ def K(

430430

c_out = c_out.at[0, :].set(0)

431431

a_out = a_out.at[0, :].set(0)

432432433-

return a_out, c_out

433+

return c_out, a_out

434434

```

435435436436

The next function solves for an approximation of the optimal consumption policy

@@ -487,15 +487,15 @@ a_init = σ_init.copy()

487487

Let's generate an approximation solution with JAX:

488488489489

```{code-cell} ipython3

490-

a_star, σ_star = solve_model(ifp, a_init, σ_init)

490+

σ_star, a_star = solve_model(ifp, σ_init, a_init)

491491

```

492492493493

Let's try it again with a timer.

494494495495

```{code-cell} python3

496496

with qe.Timer(precision=8):

497-

a_star, σ_star = solve_model(ifp, a_init, σ_init)

498-

a_star.block_until_ready()

497+

σ_star, a_star = solve_model(ifp, σ_init, a_init)

498+

σ_star.block_until_ready()

499499

```

500500501501

## Simulation

@@ -642,7 +642,7 @@ s_grid = ifp.s_grid

642642

n_z = len(ifp.P)

643643

a_init = s_grid[:, None] * jnp.ones(n_z)

644644

c_init = a_init

645-

a_vec, c_vec = solve_model(ifp, a_init, c_init)

645+

c_vec, a_vec = solve_model(ifp, c_init, a_init)

646646

assets = compute_asset_stationary(c_vec, a_vec, ifp, num_households=200_000)

647647648648

# Compute Gini coefficient for the plot

@@ -734,8 +734,8 @@ for a_r in a_r_vals:

734734

n_z_temp = len(ifp_temp.P)

735735

a_init_temp = s_grid_temp[:, None] * jnp.ones(n_z_temp)

736736

c_init_temp = a_init_temp

737-

a_vec_temp, c_vec_temp = solve_model(

738-

ifp_temp, a_init_temp, c_init_temp

737+

c_vec_temp, a_vec_temp = solve_model(

738+

ifp_temp, c_init_temp, a_init_temp

739739

)

740740741741

# Simulate households

@@ -811,8 +811,8 @@ for a_y in a_y_vals:

811811

n_z_temp = len(ifp_temp.P)

812812

a_init_temp = s_grid_temp[:, None] * jnp.ones(n_z_temp)

813813

c_init_temp = a_init_temp

814-

a_vec_temp, c_vec_temp = solve_model(

815-

ifp_temp, a_init_temp, c_init_temp

814+

c_vec_temp, a_vec_temp = solve_model(

815+

ifp_temp, c_init_temp, a_init_temp

816816

)

817817818818

# Simulate households

Read the original on github.com ↗