Skip to content

Commit

Permalink
further_edits
Browse files Browse the repository at this point in the history
  • Loading branch information
shlff committed Mar 4, 2024
1 parent 2fed0fb commit 8a1f149
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions lectures/arellano.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.14.5
jupytext_version: 1.15.2
kernelspec:
display_name: Python 3 (ipykernel)
language: python
Expand Down Expand Up @@ -370,9 +370,9 @@ We define a namedtuple to store parameters, grids and transition
probabilities.
```{code-cell} ipython3
Arellano = namedtuple('Arellano', ('β', 'γ', 'r', 'ρ', 'η', 'θ', \
'B_size', 'y_size', \
'P', 'B_grid', 'y_grid', 'def_y'))
Arellano_Economy = namedtuple('Arellano_Economy', ('β', 'γ', 'r', 'ρ', 'η', 'θ', \
'B_size', 'y_size', \
'P', 'B_grid', 'y_grid', 'def_y'))
```
```{code-cell} ipython3
Expand Down Expand Up @@ -400,9 +400,9 @@ def create_arellano(B_size=251, # Grid size for bonds
# Output received while in default, with same shape as y_grid
def_y = jnp.minimum(def_y_param * jnp.mean(y_grid), y_grid)
return Arellano(β=β, γ=γ, r=r, ρ=ρ, η=η, θ=θ, B_size=B_size, \
y_size=y_size, P=P, B_grid=B_grid, y_grid=y_grid, \
def_y=def_y)
return Arellano_Economy(β=β, γ=γ, r=r, ρ=ρ, η=η, θ=θ, B_size=B_size, \
y_size=y_size, P=P, B_grid=B_grid, y_grid=y_grid, \
def_y=def_y)
```
Here is the utility function.
Expand Down Expand Up @@ -462,6 +462,7 @@ def T_d(v_c, v_d, params, sizes, arrays):
β, γ, r, ρ, η, θ = params
B_size, y_size = sizes
P, B_grid, y_grid, def_y = arrays
B0_idx = jnp.searchsorted(B_grid, 1e-10) # Index at which B is near zero
current_utility = u(def_y, γ)
Expand Down Expand Up @@ -546,19 +547,19 @@ def update_values_and_prices(v_c, v_d, params, sizes, arrays):
return new_v_c, new_v_d
```
We can now write a function that will use the `Arellano` namedtuple and the
functions defined above to compute the solution to our model.
We can now write a function that will use an instance of `Arellano_Economy` and
the functions defined above to compute the solution to our model.
One of the jobs of this function is to take an instance of
`Arellano`, which is hard for the JIT compiler to handle, and strip it
`Arellano_Economy`, which is hard for the JIT compiler to handle, and strip it
down to more basic objects, which are then passed out to jitted functions.
```{code-cell} ipython3
:hide-output: false
def solve(model, tol=1e-8, max_iter=10_000):
"""
Given an instance of Arellano, this function computes the optimal
Given an instance of `Arellano_Economy`, this function computes the optimal
policy and value functions.
"""
# Unpack
Expand Down Expand Up @@ -621,14 +622,15 @@ def simulate(model, T, v_c, v_d, q, B_star, key):
"""
Simulates the Arellano 2008 model of sovereign debt
Here `model` is an instance of `Arellano` and `T` is the length of
Here `model` is an instance of `Arellano_Economy` and `T` is the length of
the simulation. Endogenous objects `v_c`, `v_d`, `q` and `B_star` are
assumed to come from a solution to `model`.
"""
# Unpack elements of the model
B_size, y_size = model.B_size, model.y_size
B_grid, y_grid, P = model.B_grid, model.y_grid, model.P
B0_idx = jnp.searchsorted(B_grid, 1e-10) # Index at which B is near zero
# Set initial conditions
Expand Down Expand Up @@ -685,17 +687,15 @@ def simulate(model, T, v_c, v_d, q, B_star, key):
Let’s start by trying to replicate the results obtained in {cite}`Are08`.
In what follows, all results are computed using Arellano’s parameter values.
The values can be seen in the `create_arellano` method shown above.
In what follows, all results are computed using parameter values of `Arellano_Economy` created by `create_arellano`.
For example, `r=0.017` matches the average quarterly rate on a 5 year US treasury over the period 1983–2001.
Details on how to compute the figures are reported as solutions to the
exercises.
The first figure shows the bond price schedule and replicates Figure 3 of
Arellano, where $ y_L $ and $ Y_H $ are particular below average and above average
{cite}`Are08`, where $ y_L $ and $ Y_H $ are particular below average and above average
values of output $ y $.
![https://python-advanced.quantecon.org/_static/lecture_specific/arellano/arellano_bond_prices.png](https://python-advanced.quantecon.org/_static/lecture_specific/arellano/arellano_bond_prices.png)
Expand Down Expand Up @@ -755,7 +755,7 @@ Periods of relative stability are followed by sharp spikes in the discount rate
To the extent that you can, replicate the figures shown above
- Use the parameter values listed as defaults in `Arellano`.
- Use the parameter values listed as defaults in `Arellano_Economy` created by `create_arellano`.
- The time series will of course vary depending on the shock draws.
```{exercise-end}
Expand All @@ -778,7 +778,7 @@ ae = create_arellano()
v_c, v_d, q, B_star = solve(ae)
```
Compute the bond price schedule as seen in figure 3 of Arellano (2008)
Compute the bond price schedule as seen in figure 3 of {cite}`Are08`
```{code-cell} ipython3
:hide-output: false
Expand All @@ -800,7 +800,7 @@ x = []
q_low = []
q_high = []
for i, B in enumerate(B_grid):
if -0.35 <= B <= 0: # To match fig 3 of Arellano
if -0.35 <= B <= 0: # To match fig 3 of Arellano (2008)
x.append(B)
q_low.append(q[i, iy_low])
q_high.append(q[i, iy_high])
Expand Down

0 comments on commit 8a1f149

Please sign in to comment.