1+ # TODO Turn this into a jupyter notebook
2+
13from pyacm import NominalACM
24
35import matplotlib .pyplot as plt
6+ import matplotlib .dates as mdates
47import pandas as pd
58import numpy as np
69
912 "sample_data/di monthly maturities.csv" ,
1013 index_col = 0 ,
1114)
12- yield_curve = yield_curve .iloc [:, :120 ] # maturities up to 10y
15+ yield_curve = yield_curve .iloc [:, :121 ] # maturities up to 10y
1316yield_curve = yield_curve .dropna ()
1417yield_curve .index = pd .to_datetime (yield_curve .index )
18+ yield_curve = yield_curve [yield_curve .index >= "2007-03-01" ] # TODO deal with this missing data
19+
1520
21+ # Plot the Series of selcted maturities
1622yield_curve [["12m" , "24m" , "60m" , "120m" ]].plot (legend = True , title = "Yields for Selected Maturities" , grid = True )
1723plt .tight_layout ()
18- plt .show ()
24+ plt .show ()
25+
26+ # Run the model
27+ acm = NominalACM (
28+ curve = yield_curve ,
29+ n_factors = 5 ,
30+ )
31+
32+ # Excess returns of synthetic bonds
33+ acm .rx_m [["12m" , "24m" , "60m" ]].plot (legend = True , title = "Monthly excess returns of synthetic bonds" , grid = True )
34+ plt .tight_layout ()
35+ plt .show ()
36+
37+
38+ # Principal components
39+ acm .pc_factors_d .plot (legend = True , title = "Principal Components of the Curve" , grid = True )
40+ plt .tight_layout ()
41+ plt .show ()
42+
43+
44+ # Fitted VS Observed
45+ fig = plt .figure (figsize = (5 * (16 / 9 ), 5 ))
46+ ax = plt .subplot2grid ((1 , 2 ), (0 , 0 ))
47+ mat = "24m"
48+ ax .plot (acm .curve [mat ], label = 'Observed' )
49+ ax .plot (acm .miy [mat ], label = 'Fitted' )
50+ ax .set_title (f"{ mat } DI Futures" )
51+ ax .xaxis .grid (color = "grey" , linestyle = "-" , linewidth = 0.5 , alpha = 0.5 )
52+ ax .yaxis .grid (color = "grey" , linestyle = "-" , linewidth = 0.5 , alpha = 0.5 )
53+ ax .xaxis .set_major_formatter (mdates .DateFormatter ("%Y" ))
54+ ax .tick_params (rotation = 90 , axis = "x" )
55+ ax .legend (frameon = True , loc = "best" )
56+
57+ ax = plt .subplot2grid ((1 , 2 ), (0 , 1 ))
58+ mat = "60m"
59+ ax .plot (acm .curve [mat ], label = 'Observed' )
60+ ax .plot (acm .miy [mat ], label = 'Fitted' )
61+ ax .set_title (f"{ mat } DI Futures" )
62+ ax .xaxis .grid (color = "grey" , linestyle = "-" , linewidth = 0.5 , alpha = 0.5 )
63+ ax .yaxis .grid (color = "grey" , linestyle = "-" , linewidth = 0.5 , alpha = 0.5 )
64+ ax .xaxis .set_major_formatter (mdates .DateFormatter ("%Y" ))
65+ ax .tick_params (rotation = 90 , axis = "x" )
66+ ax .legend (frameon = True , loc = "best" )
67+
68+ plt .tight_layout ()
69+ plt .show ()
70+
71+
72+ # Risk Neutral vs market
73+ fig = plt .figure (figsize = (5 * (16 / 9 ), 5 ))
74+ ax = plt .subplot2grid ((1 , 2 ), (0 , 0 ))
75+ mat = "24m"
76+ ax .plot (acm .curve [mat ], label = 'Observed' )
77+ ax .plot (acm .rny [mat ], label = 'Risk-Neutral' )
78+ ax .set_title (f"{ mat } DI Futures VS Risk-Neutral" )
79+ ax .xaxis .grid (color = "grey" , linestyle = "-" , linewidth = 0.5 , alpha = 0.5 )
80+ ax .yaxis .grid (color = "grey" , linestyle = "-" , linewidth = 0.5 , alpha = 0.5 )
81+ ax .xaxis .set_major_formatter (mdates .DateFormatter ("%Y" ))
82+ ax .tick_params (rotation = 90 , axis = "x" )
83+ ax .legend (frameon = True , loc = "best" )
84+
85+ ax = plt .subplot2grid ((1 , 2 ), (0 , 1 ))
86+ mat = "60m"
87+ ax .plot (acm .curve [mat ], label = 'Observed' )
88+ ax .plot (acm .rny [mat ], label = 'Risk-Neutral' )
89+ ax .set_title (f"{ mat } DI Futures VS Risk-Neutral" )
90+ ax .xaxis .grid (color = "grey" , linestyle = "-" , linewidth = 0.5 , alpha = 0.5 )
91+ ax .yaxis .grid (color = "grey" , linestyle = "-" , linewidth = 0.5 , alpha = 0.5 )
92+ ax .xaxis .set_major_formatter (mdates .DateFormatter ("%Y" ))
93+ ax .tick_params (rotation = 90 , axis = "x" )
94+ ax .legend (frameon = True , loc = "best" )
95+
96+ plt .tight_layout ()
97+ plt .show ()
98+
99+ # Term premium
100+ fig = plt .figure (figsize = (5 * (16 / 9 ), 5 ))
101+ ax = plt .subplot2grid ((1 , 1 ), (0 , 0 ))
102+ ax .plot (acm .tp ["24m" ], label = '24m' )
103+ ax .plot (acm .tp ["60m" ], label = '60m' )
104+ ax .set_title (f"Term Premium for DI Futures" )
105+ ax .xaxis .grid (color = "grey" , linestyle = "-" , linewidth = 0.5 , alpha = 0.5 )
106+ ax .yaxis .grid (color = "grey" , linestyle = "-" , linewidth = 0.5 , alpha = 0.5 )
107+ ax .xaxis .set_major_formatter (mdates .DateFormatter ("%Y" ))
108+ ax .tick_params (rotation = 90 , axis = "x" )
109+ ax .legend (frameon = True , loc = "best" )
110+
111+ plt .tight_layout ()
112+ plt .show ()
113+
114+ # Term Premium VS Expected Returns
115+ fig = plt .figure (figsize = (5 * (16 / 9 ), 5 ))
116+ ax = plt .subplot2grid ((1 , 1 ), (0 , 0 ))
117+ ax .plot (acm .tp ["60m" ], label = 'Term Premium' )
118+ ax .plot (acm .er_hist_d ["60m" ], label = 'Expected Return' )
119+ ax .set_title (f"Term Premium VS Expected Return" )
120+ ax .xaxis .grid (color = "grey" , linestyle = "-" , linewidth = 0.5 , alpha = 0.5 )
121+ ax .yaxis .grid (color = "grey" , linestyle = "-" , linewidth = 0.5 , alpha = 0.5 )
122+ ax .xaxis .set_major_formatter (mdates .DateFormatter ("%Y" ))
123+ ax .tick_params (rotation = 90 , axis = "x" )
124+ ax .legend (frameon = True , loc = "best" )
125+
126+ plt .tight_layout ()
127+ plt .show ()
128+
129+
130+ # TODO mkt implied vs RN implied VS realized (develop)
0 commit comments