@@ -72,6 +72,44 @@ def __init__(self, curve, n_factors=5):
7272 self .er_loadings , self .er_hist_m , self .er_hist_d = self ._expected_return ()
7373 self .z_lambda , self .z_beta = self ._inference ()
7474
75+ def fwd_curve (self , date = None ):
76+ """
77+ Compute the forward curves for a given date.
78+
79+ Parameters
80+ ----------
81+ date : date-like
82+ date in any format that can be interpreted by pandas.to_datetime()
83+ """
84+
85+ if date is None :
86+ date = self .curve .index [- 1 ]
87+
88+ date = pd .to_datetime (date )
89+ fwd_mkt = self ._compute_fwd_curve (self .curve .loc [date ])
90+ fwd_miy = self ._compute_fwd_curve (self .miy .loc [date ])
91+ fwd_rny = self ._compute_fwd_curve (self .rny .loc [date ])
92+ df = pd .concat (
93+ [
94+ fwd_mkt .rename ("Observed" ),
95+ fwd_miy .rename ("Model Implied" ),
96+ fwd_rny .rename ("Risk-Neutral" ),
97+ ],
98+ axis = 1 ,
99+ )
100+ return df
101+
102+
103+ @staticmethod
104+ def _compute_fwd_curve (curve ):
105+ aux_curve = curve .reset_index (drop = True )
106+ aux_curve .index = aux_curve .index + 1
107+ factor = (1 + aux_curve ) ** (aux_curve .index / 12 )
108+ fwd_factor = factor / factor .shift (1 ).fillna (1 )
109+ fwds = (fwd_factor ** 12 ) - 1
110+ fwds = pd .Series (fwds .values , index = curve .index )
111+ return fwds
112+
75113 def _get_excess_returns (self ):
76114 ttm = np .arange (1 , self .n + 1 ) / 12
77115 log_prices = - self .curve_monthly * ttm
0 commit comments