def curve_params(current_duration, yield_path):
    
    """Calculate parameters for all 10 years"""
    df_yield_params = pd.DataFrame(['NaN', 'NaN', 'NaN'], columns=['Current'])

    for i in range(1,11):
        df_yield_params[i] = np.nan

    tau=1.65

    param_list = []
    for i in range(0, 11):
        t = np.array(current_duration)
        y = np.array(yield_path.iloc[:,i])

        curve, status = betas_ns_ols(tau, t, y)
        curve = str(curve)

        B0 = float((curve.split('=')[1]).split(',')[0])
        B1 = float((curve.split('=')[2]).split(',')[0])
        B2 = float((curve.split('=')[3]).split(',')[0])
        param = [B0, B1, B2]
        df_yield_params.iloc[:,i] = param
        
    return df_yield_params
 def test_nelson_siegel_betas_recovery(self):
     '''Test recovery of betas using ordinary least squares
        (given fixed tau)
     '''
     t = np.linspace(0, 30)
     y_target = self.y(t)
     curve, lstsq_res = betas_ns_ols(self.y.tau, t, y_target)
     self.assertAlmostEqual(self.y.beta0, curve.beta0, places=12)
     self.assertAlmostEqual(self.y.beta1, curve.beta1, places=12)
     self.assertAlmostEqual(self.y.beta2, curve.beta2, places=12)
Exemple #3
0
# +
# Determine parameters for each year
df_yield_params = pd.DataFrame(['NaN', 'NaN', 'NaN'], columns=['Current'])

for i in range(1, 11):
    df_yield_params[i] = np.nan

tau = 1.65

param_list = []
for i in range(0, 11):
    t = np.array(df_interest_rates['Current_Duration'])
    y = np.array(df_yield_10yr.iloc[:, i])

    curve, status = betas_ns_ols(tau, t, y)
    curve = str(curve)

    B0 = float((curve.split('=')[1]).split(',')[0])
    B1 = float((curve.split('=')[2]).split(',')[0])
    B2 = float((curve.split('=')[3]).split(',')[0])
    param = [B0, B1, B2]
    df_yield_params.iloc[:, i] = param

# +
# US Yield Curve Over Next 10 Years
term_structure = (np.arange(0.5, 100.5, 0.5))

curve_list = []
for i in range(0, 11):
    curve_item = [