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