Skip to content

Commit a2e6522

Browse files
committed
Revert "Update sources from lecture-python-advanced (ce9441dad2ec187b4c93cfca6225aa68818dd033) using sphinx-tomyst + adjustment"
This reverts commit 5f277a1.
1 parent 5f277a1 commit a2e6522

File tree

1 file changed

+59
-48
lines changed

1 file changed

+59
-48
lines changed

lectures/opt_tax_recur.md

Lines changed: 59 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ In addition to what's in Anaconda, this lecture will need the following librarie
3131
tags: [hide-output]
3232
---
3333
!pip install --upgrade quantecon
34-
!pip install interpolation
3534
```
3635

3736
## Overview
@@ -71,12 +70,6 @@ Let's start with some standard imports:
7170
import numpy as np
7271
import matplotlib.pyplot as plt
7372
%matplotlib inline
74-
from scipy.optimize import root
75-
from quantecon import MarkovChain
76-
from quantecon.optimize.nelder_mead import nelder_mead
77-
from interpolation import interp
78-
from numba import njit, prange, float64
79-
from numba.experimental import jitclass
8073
```
8174

8275
## A Competitive Equilibrium with Distorting Taxes
@@ -724,7 +717,7 @@ $$
724717

725718
### Sequence Implementation
726719

727-
The above steps are implemented in a class called SequentialLS
720+
The above steps are implemented in a class called SequentialAllocation
728721

729722
```{code-cell} python3
730723
:load: _static/lecture_specific/opt_tax_recur/sequential_allocation.py
@@ -739,7 +732,7 @@ appears to be a purely “forward-looking” variable.
739732

740733
But $x_t(s^t)$ is a natural candidate for a state variable in
741734
a recursive formulation of the Ramsey problem, one that records history-dependence and so is
742-
`backward-looking`.
735+
``backward-looking''.
743736

744737
### Intertemporal Delegation
745738

@@ -1026,7 +1019,7 @@ through them, the value of initial government debt $b_0$.
10261019

10271020
### Recursive Implementation
10281021

1029-
The above steps are implemented in a class called `RecursiveLS`.
1022+
The above steps are implemented in a class called `RecursiveAllocation`.
10301023

10311024
```{code-cell} python3
10321025
:load: _static/lecture_specific/opt_tax_recur/recursive_allocation.py
@@ -1094,31 +1087,39 @@ We can now plot the Ramsey tax under both realizations of time $t = 3$ governme
10941087
* red when $g_3 = .2$
10951088

10961089
```{code-cell} python3
1097-
π = np.array([[0, 1, 0, 0, 0, 0],
1098-
[0, 0, 1, 0, 0, 0],
1099-
[0, 0, 0, 0.5, 0.5, 0],
1100-
[0, 0, 0, 0, 0, 1],
1101-
[0, 0, 0, 0, 0, 1],
1102-
[0, 0, 0, 0, 0, 1]])
1103-
1104-
g = np.array([0.1, 0.1, 0.1, 0.2, 0.1, 0.1])
1105-
crra_pref = CRRAutility()
1090+
time_π = np.array([[0, 1, 0, 0, 0, 0],
1091+
[0, 0, 1, 0, 0, 0],
1092+
[0, 0, 0, 0.5, 0.5, 0],
1093+
[0, 0, 0, 0, 0, 1],
1094+
[0, 0, 0, 0, 0, 1],
1095+
[0, 0, 0, 0, 0, 1]])
1096+
1097+
time_G = np.array([0.1, 0.1, 0.1, 0.2, 0.1, 0.1])
1098+
# Θ can in principle be random
1099+
time_Θ = np.ones(6)
1100+
time_example = CRRAutility(π=time_π, G=time_G, Θ=time_Θ)
11061101
11071102
# Solve sequential problem
1108-
seq = SequentialLS(crra_pref, π=π, g=g)
1103+
time_allocation = SequentialAllocation(time_example)
11091104
sHist_h = np.array([0, 1, 2, 3, 5, 5, 5])
11101105
sHist_l = np.array([0, 1, 2, 4, 5, 5, 5])
1111-
sim_seq_h = seq.simulate(1, 0, 7, sHist_h)
1112-
sim_seq_l = seq.simulate(1, 0, 7, sHist_l)
1106+
sim_seq_h = time_allocation.simulate(1, 0, 7, sHist_h)
1107+
sim_seq_l = time_allocation.simulate(1, 0, 7, sHist_l)
1108+
1109+
# Government spending paths
1110+
sim_seq_l[4] = time_example.G[sHist_l]
1111+
sim_seq_h[4] = time_example.G[sHist_h]
11131112
1114-
fig, axes = plt.subplots(3, 2, figsize=(14, 10))
1113+
# Output paths
1114+
sim_seq_l[5] = time_example.Θ[sHist_l] * sim_seq_l[1]
1115+
sim_seq_h[5] = time_example.Θ[sHist_h] * sim_seq_h[1]
1116+
1117+
fig, axes = plt.subplots(3, 2, figsize=(12, 8))
11151118
titles = ['Consumption', 'Labor Supply', 'Government Debt',
11161119
'Tax Rate', 'Government Spending', 'Output']
11171120
11181121
for ax, title, sim_l, sim_h in zip(axes.flatten(),
1119-
titles,
1120-
sim_seq_l[:6],
1121-
sim_seq_h[:6]):
1122+
titles, sim_seq_l, sim_seq_h):
11221123
ax.set(title=title)
11231124
ax.plot(sim_l, '-ok', sim_h, '-or', alpha=0.7)
11241125
ax.grid()
@@ -1226,16 +1227,18 @@ $t=0$ and time $t\geq1$ as functions of the initial government debt
12261227
above)
12271228

12281229
```{code-cell} python3
1229-
tax_seq = SequentialLS(CRRAutility(), g=np.array([0.15]), π=np.ones((1, 1)))
1230+
tax_sequence = SequentialAllocation(CRRAutility(G=0.15,
1231+
π=np.ones((1, 1)),
1232+
Θ=np.ones(1)))
12301233
12311234
n = 100
12321235
tax_policy = np.empty((n, 2))
12331236
interest_rate = np.empty((n, 2))
12341237
gov_debt = np.linspace(-1.5, 1, n)
12351238
12361239
for i in range(n):
1237-
tax_policy[i] = tax_seq.simulate(gov_debt[i], 0, 2)[3]
1238-
interest_rate[i] = tax_seq.simulate(gov_debt[i], 0, 3)[-1]
1240+
tax_policy[i] = tax_sequence.simulate(gov_debt[i], 0, 2)[3]
1241+
interest_rate[i] = tax_sequence.simulate(gov_debt[i], 0, 3)[-1]
12391242
12401243
fig, axes = plt.subplots(2, 1, figsize=(10,8), sharex=True)
12411244
titles = ['Tax Rate', 'Gross Interest Rate']
@@ -1295,16 +1298,18 @@ Ramsey planner and what a new Ramsey planner would choose for its
12951298
time $t=0$ tax rate
12961299

12971300
```{code-cell} python3
1298-
tax_seq = SequentialLS(CRRAutility(), g=np.array([0.15]), π=np.ones((1, 1)))
1301+
tax_sequence = SequentialAllocation(CRRAutility(G=0.15,
1302+
π=np.ones((1, 1)),
1303+
Θ=np.ones(1)))
12991304
13001305
n = 100
13011306
tax_policy = np.empty((n, 2))
13021307
τ_reset = np.empty((n, 2))
13031308
gov_debt = np.linspace(-1.5, 1, n)
13041309
13051310
for i in range(n):
1306-
tax_policy[i] = tax_seq.simulate(gov_debt[i], 0, 2)[3]
1307-
τ_reset[i] = tax_seq.simulate(gov_debt[i], 0, 1)[3]
1311+
tax_policy[i] = tax_sequence.simulate(gov_debt[i], 0, 2)[3]
1312+
τ_reset[i] = tax_sequence.simulate(gov_debt[i], 0, 1)[3]
13081313
13091314
fig, ax = plt.subplots(figsize=(10, 6))
13101315
ax.plot(gov_debt, tax_policy[:, 1], gov_debt, τ_reset, lw=2)
@@ -1363,32 +1368,38 @@ The figure below plots a sample path of the Ramsey tax rate
13631368
```{code-cell} python3
13641369
log_example = LogUtility()
13651370
# Solve sequential problem
1366-
seq_log = SequentialLS(log_example)
1371+
seq_log = SequentialAllocation(log_example)
13671372
13681373
# Initialize grid for value function iteration and solve
1369-
x_grid = np.linspace(-3., 3., 200)
1370-
1374+
μ_grid = np.linspace(-0.6, 0.0, 200)
13711375
# Solve recursive problem
1372-
rec_log = RecursiveLS(log_example, x_grid)
1376+
bel_log = RecursiveAllocation(log_example, μ_grid)
13731377
1374-
T_length = 20
1375-
sHist = np.array([0, 0, 0, 0, 0,
1376-
0, 0, 0, 1, 1,
1377-
0, 0, 0, 1, 1,
1378-
1, 1, 1, 1, 0])
1378+
T = 20
1379+
sHist = np.array([0, 0, 0, 0, 0, 0, 0,
1380+
0, 1, 1, 0, 0, 0, 1,
1381+
1, 1, 1, 1, 1, 0])
13791382
13801383
# Simulate
1381-
sim_seq = seq_log.simulate(0.5, 0, T_length, sHist)
1382-
sim_rec = rec_log.simulate(0.5, 0, T_length, sHist)
1384+
sim_seq = seq_log.simulate(0.5, 0, T, sHist)
1385+
sim_bel = bel_log.simulate(0.5, 0, T, sHist)
13831386
1384-
fig, axes = plt.subplots(3, 2, figsize=(14, 10))
1387+
# Government spending paths
1388+
sim_seq[4] = log_example.G[sHist]
1389+
sim_bel[4] = log_example.G[sHist]
1390+
1391+
# Output paths
1392+
sim_seq[5] = log_example.Θ[sHist] * sim_seq[1]
1393+
sim_bel[5] = log_example.Θ[sHist] * sim_bel[1]
1394+
1395+
fig, axes = plt.subplots(3, 2, figsize=(10, 6))
13851396
titles = ['Consumption', 'Labor Supply', 'Government Debt',
13861397
'Tax Rate', 'Government Spending', 'Output']
13871398
1388-
for ax, title, sim_s, sim_b in zip(axes.flatten(), titles, sim_seq[:6], sim_rec[:6]):
1389-
ax.plot(sim_s, '-ob', sim_b, '-xk', alpha=0.7)
1390-
ax.set(title=title)
1391-
ax.grid()
1399+
for ax, title, sim_s, sim_b in zip(axes.flatten(), titles, sim_seq, sim_bel):
1400+
ax.plot(sim_s, '-ob', sim_b, '-xk', alpha=0.7)
1401+
ax.set(title=title)
1402+
ax.grid()
13921403
13931404
axes.flatten()[0].legend(('Sequential', 'Recursive'))
13941405
fig.tight_layout()

0 commit comments

Comments
 (0)