Skip to content

Commit a9a81f5

Browse files
authored
Merge pull request #111 from QuantEcon/fix-arellano2
FIX: arellano is missing {code-cell} wrappers
2 parents 7719183 + e265123 commit a9a81f5

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

lectures/arellano.md

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
---
2-
jupyter:
3-
jupytext:
4-
text_representation:
5-
extension: .md
6-
format_name: markdown
7-
format_version: '1.3'
8-
jupytext_version: 1.13.7
9-
kernelspec:
10-
display_name: Python 3
11-
language: python
12-
name: python3
2+
jupytext:
3+
text_representation:
4+
extension: .md
5+
format_name: myst
6+
kernelspec:
7+
display_name: Python 3
8+
language: python
9+
name: python3
1310
---
1411

1512
(arellano)=
@@ -29,7 +26,7 @@ jupyter:
2926

3027
In addition to what's in Anaconda, this lecture will need the following libraries:
3128

32-
```python
29+
```{code-cell} python
3330
:tags: ["hide-output"]
3431
!pip install --upgrade quantecon
3532
```
@@ -77,7 +74,7 @@ Such dynamics are consistent with experiences of many countries.
7774

7875
Let's start with some imports:
7976

80-
```python
77+
```{code-cell} python
8178
import matplotlib.pyplot as plt
8279
import numpy as np
8380
import quantecon as qe
@@ -349,7 +346,7 @@ As we have in other places, we accelerate our code using Numba.
349346
We define a class that will store parameters, grids and transition
350347
probabilities.
351348

352-
```python
349+
```{code-cell} python
353350
class Arellano_Economy:
354351
" Stores data and creates primitives for the Arellano economy. "
355352
@@ -399,7 +396,7 @@ Jitted functions prefer simple arguments, since type inference is easier.
399396
Here is the utility function.
400397

401398

402-
```python
399+
```{code-cell} python
403400
@njit
404401
def u(c, γ):
405402
return c**(1-γ)/(1-γ)
@@ -408,7 +405,7 @@ def u(c, γ):
408405
Here is a function to compute the bond price at each state, given $v_c$ and
409406
$v_d$.
410407

411-
```python
408+
```{code-cell} python
412409
@njit
413410
def compute_q(v_c, v_d, q, params, arrays):
414411
"""
@@ -431,7 +428,7 @@ def compute_q(v_c, v_d, q, params, arrays):
431428

432429
Next we introduce Bellman operators that updated $v_d$ and $v_c$.
433430

434-
```python
431+
```{code-cell} python
435432
@njit
436433
def T_d(y_idx, v_c, v_d, params, arrays):
437434
"""
@@ -478,7 +475,7 @@ def T_c(B_idx, y_idx, v_c, v_d, q, params, arrays):
478475

479476
Here is a fast function that calls these operators in the right sequence.
480477

481-
```python
478+
```{code-cell} python
482479
@njit(parallel=True)
483480
def update_values_and_prices(v_c, v_d, # Current guess of value functions
484481
B_star, q, # Arrays to be written to
@@ -518,7 +515,7 @@ In fact, one of the jobs of this function is to take an instance of
518515
`Arellano_Economy`, which is hard for the JIT compiler to handle, and strip it
519516
down to more basic objects, which are then passed out to jitted functions.
520517

521-
```python
518+
```{code-cell} python
522519
def solve(model, tol=1e-8, max_iter=10_000):
523520
"""
524521
Given an instance of Arellano_Economy, this function computes the optimal
@@ -558,7 +555,7 @@ def solve(model, tol=1e-8, max_iter=10_000):
558555
Finally, we write a function that will allow us to simulate the economy once
559556
we have the policy functions
560557

561-
```python
558+
```{code-cell} python
562559
def simulate(model, T, v_c, v_d, q, B_star, y_idx=None, B_idx=None):
563560
"""
564561
Simulates the Arellano 2008 model of sovereign debt
@@ -703,17 +700,17 @@ To the extent that you can, replicate the figures shown above
703700

704701
Compute the value function, policy and equilibrium prices
705702

706-
```python
703+
```{code-cell} python
707704
ae = Arellano_Economy()
708705
```
709706

710-
```python
707+
```{code-cell} python
711708
v_c, v_d, q, B_star = solve(ae)
712709
```
713710

714711
Compute the bond price schedule as seen in figure 3 of Arellano (2008)
715712

716-
```python
713+
```{code-cell} python
717714
# Unpack some useful names
718715
B_grid, y_grid, P = ae.B_grid, ae.y_grid, ae.P
719716
B_grid_size, y_grid_size = len(B_grid), len(y_grid)
@@ -744,7 +741,7 @@ plt.show()
744741

745742
Draw a plot of the value functions
746743

747-
```python
744+
```{code-cell} python
748745
v = np.maximum(v_c, np.reshape(v_d, (1, y_grid_size)))
749746
750747
fig, ax = plt.subplots(figsize=(10, 6.5))
@@ -759,7 +756,7 @@ plt.show()
759756

760757
Draw a heat map for default probability
761758

762-
```python
759+
```{code-cell} python
763760
xx, yy = B_grid, y_grid
764761
zz = np.empty_like(v_c)
765762
@@ -780,7 +777,7 @@ plt.show()
780777

781778
Plot a time series of major variables simulated from the model
782779

783-
```python
780+
```{code-cell} python
784781
T = 250
785782
np.random.seed(42)
786783
y_sim, y_a_sim, B_sim, q_sim, d_sim = simulate(ae, T, v_c, v_d, q, B_star)

0 commit comments

Comments
 (0)