Skip to content

Commit e4c60de

Browse files
authored
Merge pull request #5 from gusamarante/feature/match-original
Matching results of the original paper
2 parents caac148 + e23e089 commit e4c60de

File tree

9 files changed

+4927
-11122
lines changed

9 files changed

+4927
-11122
lines changed

example_br.ipynb

Lines changed: 37 additions & 86 deletions
Large diffs are not rendered by default.

example_us.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""
2+
This file replicates the term premium estimates from the original paper. The
3+
file `us_data.xlsx` contains data from the authors' original matlab replication
4+
files. The output of this script matches the one from the original.
5+
6+
For the updated US term premium estimates, visit the NY FED website.
7+
"""
8+
from pyacm import NominalACM
9+
import pandas as pd
10+
import matplotlib.pyplot as plt
11+
12+
13+
ylds_d = pd.read_excel("sample_data/us_data.xlsx", index_col=0, sheet_name="daily")
14+
ylds_d.index = pd.to_datetime(ylds_d.index)
15+
ylds_d = ylds_d / 100
16+
17+
ylds_m = pd.read_excel("sample_data/us_data.xlsx", index_col=0, sheet_name="monthly")
18+
ylds_m.index = pd.to_datetime(ylds_m.index)
19+
ylds_m = ylds_m.resample("M").last()
20+
ylds_m = ylds_m / 100
21+
22+
acm = NominalACM(
23+
curve=ylds_d,
24+
curve_m=ylds_m,
25+
n_factors=5,
26+
selected_maturities=[6, 12, 24, 36, 48, 60, 72, 84, 96, 108, 120],
27+
)
28+
29+
30+
# =================
31+
# ===== Chart =====
32+
# =================
33+
size = 7
34+
fig = plt.figure(figsize=(size * (16 / 7.3), size))
35+
36+
ax = plt.subplot2grid((1, 2), (0, 0))
37+
ax.plot(ylds_d[120], label="Actual Yield", lw=1)
38+
ax.plot(acm.miy[120], label="Fitted Yield", lw=1, ls='--')
39+
ax.set_title("10-Year Model Fit")
40+
ax.xaxis.grid(color="grey", linestyle="-", linewidth=0.5, alpha=0.5)
41+
ax.yaxis.grid(color="grey", linestyle="-", linewidth=0.5, alpha=0.5)
42+
ax.tick_params(rotation=90, axis="x")
43+
ax.legend(loc="upper right")
44+
45+
ax = plt.subplot2grid((1, 2), (0, 1))
46+
ax.plot(ylds_d[120], label="Yield", lw=1)
47+
ax.plot(acm.rny[120], label="Risk Neutral Yield", lw=1)
48+
ax.plot(acm.tp[120], label="Term Premium", lw=1)
49+
ax.set_title("10-Year Yield Decomposition")
50+
ax.xaxis.grid(color="grey", linestyle="-", linewidth=0.5, alpha=0.5)
51+
ax.yaxis.grid(color="grey", linestyle="-", linewidth=0.5, alpha=0.5)
52+
ax.tick_params(rotation=90, axis="x")
53+
ax.legend(loc="upper right")
54+
55+
plt.tight_layout()
56+
plt.show()

pit_estimates.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)