Skip to content

[FIX] Minor bug fixes #587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions lectures/cagan_ree.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.16.1
jupytext_version: 1.17.1
kernelspec:
display_name: Python 3 (ipykernel)
language: python
Expand Down Expand Up @@ -267,6 +267,7 @@ def solve(model, T):
A1 = np.eye(T+1, T+1) - δ * np.eye(T+1, T+1, k=1)
A2 = np.eye(T+1, T+1) - np.eye(T+1, T+1, k=-1)

# Assume γ* = 1
b1 = (1-δ) * μ_seq + np.concatenate([np.zeros(T), [δ * π_end]])
b2 = μ_seq + np.concatenate([[m0], np.zeros(T)])

Expand Down Expand Up @@ -326,7 +327,7 @@ T1 = 60
μ_star = 0
T = 80

μ_seq_1 = np.append(μ0*np.ones(T1+1), μ_star*np.ones(T-T1))
μ_seq_1 = np.append(μ0*np.ones(T1), μ_star*np.ones(T-T1+1))

cm = create_cagan_model(μ_seq=μ_seq_1)

Expand Down Expand Up @@ -493,32 +494,34 @@ cm1 = create_cagan_model(μ_seq=μ_seq_2_path1)
π_seq_2_path1, m_seq_2_path1, p_seq_2_path1 = solve(cm1, T)

# continuation path
μ_seq_2_cont = μ_star * np.ones(T-T1)
μ_seq_2_cont = μ_star * np.ones(T-T1+1)

cm2 = create_cagan_model(m0=m_seq_2_path1[T1+1],
cm2 = create_cagan_model(m0=m_seq_2_path1[T1],
μ_seq=μ_seq_2_cont)
π_seq_2_cont, m_seq_2_cont1, p_seq_2_cont1 = solve(cm2, T-1-T1)
π_seq_2_cont, m_seq_2_cont1, p_seq_2_cont1 = solve(cm2, T-T1)


# regime 1 - simply glue π_seq, μ_seq
μ_seq_2 = np.concatenate((μ_seq_2_path1[:T1+1],
μ_seq_2 = np.concatenate((μ_seq_2_path1[:T1],
μ_seq_2_cont))
π_seq_2 = np.concatenate((π_seq_2_path1[:T1+1],
π_seq_2 = np.concatenate((π_seq_2_path1[:T1],
π_seq_2_cont))
m_seq_2_regime1 = np.concatenate((m_seq_2_path1[:T1+1],
m_seq_2_regime1 = np.concatenate((m_seq_2_path1[:T1],
m_seq_2_cont1))
p_seq_2_regime1 = np.concatenate((p_seq_2_path1[:T1+1],
p_seq_2_regime1 = np.concatenate((p_seq_2_path1[:T1],
p_seq_2_cont1))

π_seq_2[T1-1] = p_seq_2_regime1[T1] - p_seq_2_regime1[T1-1]

# regime 2 - reset m_T1
m_T1 = (m_seq_2_path1[T1] + μ0) + cm2.α*(μ0 - μ_star)
m_T1 = (m_seq_2_path1[T1-1] + μ0) + cm2.α*(μ0 - μ_star)

cm3 = create_cagan_model(m0=m_T1, μ_seq=μ_seq_2_cont)
π_seq_2_cont2, m_seq_2_cont2, p_seq_2_cont2 = solve(cm3, T-1-T1)
π_seq_2_cont2, m_seq_2_cont2, p_seq_2_cont2 = solve(cm3, T-T1)

m_seq_2_regime2 = np.concatenate((m_seq_2_path1[:T1+1],
m_seq_2_regime2 = np.concatenate((m_seq_2_path1[:T1],
m_seq_2_cont2))
p_seq_2_regime2 = np.concatenate((p_seq_2_path1[:T1+1],
p_seq_2_regime2 = np.concatenate((p_seq_2_path1[:T1],
p_seq_2_cont2))
```

Expand All @@ -539,8 +542,8 @@ plot_configs = [
{'data': [(T_seq, m_seq_2_regime1, 'Smooth $m_{T_1}$'),
(T_seq, m_seq_2_regime2, 'Jumpy $m_{T_1}$')],
'ylabel': r'$m$'},
{'data': [(T_seq, p_seq_2_regime1, 'Smooth $p_{T_1}$'),
(T_seq, p_seq_2_regime2, 'Jumpy $p_{T_1}$')],
{'data': [(T_seq, p_seq_2_regime1, 'Jumpy $m_{T_1}$'),
(T_seq, p_seq_2_regime2, 'Smooth $m_{T_1}$')],
'ylabel': r'$p$'}
]

Expand Down Expand Up @@ -591,7 +594,7 @@ fig, ax = plt.subplots(5, figsize=(5, 12), dpi=200)
plot_configs = [
{'data': [(T_seq[:-1], μ_seq_2)], 'ylabel': r'$\mu$'},
{'data': [(T_seq, π_seq_2, 'Unforeseen'),
(T_seq, π_seq_1, 'Foreseen')], 'ylabel': r'$p$'},
(T_seq, π_seq_1, 'Foreseen')], 'ylabel': r'$\pi$'},
{'data': [(T_seq, m_seq_2_regime1 - p_seq_2_regime1, 'Unforeseen'),
(T_seq, m_seq_1 - p_seq_1, 'Foreseen')], 'ylabel': r'$m - p$'},
{'data': [(T_seq, m_seq_2_regime1, 'Unforeseen (Smooth $m_{T_1}$)'),
Expand Down
6 changes: 3 additions & 3 deletions lectures/cons_smooth.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.16.4
jupytext_version: 1.17.1
kernelspec:
display_name: Python 3 (ipykernel)
language: python
Expand Down Expand Up @@ -279,7 +279,7 @@ def compute_optimal(model, a0, y_seq):
b = y_seq - c_seq
b[0] = b[0] + a0

a_seq = np.linalg.inv(A) @ b
a_seq = np.linalg.inv(A) @ (R * b)
a_seq = np.concatenate([[a0], a_seq])

return c_seq, a_seq, h0
Expand Down Expand Up @@ -361,7 +361,7 @@ def plot_cs(model, # consumption-smoothing model
c_seq, a_seq, h0 = compute_optimal(model, a0, y_seq)

# Sequence length
T = cs_model.T
T = model.T

fig, axes = plt.subplots(1, 2, figsize=(12,5))

Expand Down
8 changes: 4 additions & 4 deletions lectures/tax_smooth.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.16.4
jupytext_version: 1.17.1
kernelspec:
display_name: Python 3 (ipykernel)
language: python
Expand Down Expand Up @@ -283,7 +283,7 @@ def compute_optimal(model, B0, G_seq):
A = np.diag(-R*np.ones(S), k=-1) + np.eye(S+1)
b = G_seq - T_seq
b[0] = b[0] + B0
B_seq = np.linalg.inv(A) @ b
B_seq = np.linalg.inv(A) @ (R * b)
B_seq = np.concatenate([[B0], B_seq])

return T_seq, B_seq, h0
Expand Down Expand Up @@ -368,7 +368,7 @@ def plot_ts(model, # tax-smoothing model
T_seq, B_seq, h0 = compute_optimal(model, B0, G_seq)

# Sequence length
S = tax_model.S
S = model.S

fig, axes = plt.subplots(1, 2, figsize=(12,5))

Expand Down Expand Up @@ -656,4 +656,4 @@ plt.plot(ξ1_arr, cost_grad)
plt.ylabel('derivative of cost')
plt.xlabel(r'$\phi$')
plt.show()
```
```
Loading