def test_yield(self): rates_data = [('Libor1M',.01), ('Libor3M', .015), ('Libor6M', .017), ('Swap1Y', .02), ('Swap2Y', .03), ('Swap3Y', .04), ('Swap5Y', .05), ('Swap7Y', .06), ('Swap10Y', .07), ('Swap20Y', .08)] settlement_date = pydate_to_qldate('01-Dec-2013') rate_helpers = [] for label, rate in rates_data: h = make_rate_helper(label, rate, settlement_date) rate_helpers.append(h) ts_day_counter = ActualActual(ISDA) tolerance = 1.0e-15 ts = PiecewiseYieldCurve[BootstrapTrait.Discount, LogLinear].from_reference_date( settlement_date, rate_helpers, ts_day_counter, accuracy=tolerance ) zc = zero_rate(ts, (200, 300), settlement_date) # not a real test - just verify execution self.assertAlmostEqual(zc[1][0], 0.0189, 2)
def test_yield(self): rates_data = [ ("Libor1M", 0.01), ("Libor3M", 0.015), ("Libor6M", 0.017), ("Swap1Y", 0.02), ("Swap2Y", 0.03), ("Swap3Y", 0.04), ("Swap5Y", 0.05), ("Swap7Y", 0.06), ("Swap10Y", 0.07), ("Swap20Y", 0.08), ] settlement_date = pydate_to_qldate("01-Dec-2013") rate_helpers = [] for label, rate in rates_data: h = make_rate_helper(label, rate, settlement_date) rate_helpers.append(h) ts_day_counter = ActualActual(ISDA) tolerance = 1.0e-15 ts = term_structure_factory("discount", "loglinear", settlement_date, rate_helpers, ts_day_counter, tolerance) zc = zero_rate(ts, (200, 300), settlement_date) # not a real test - just verify execution self.assertAlmostEqual(zc[1][0], 0.0189, 2)
def test_yield(self): rates_data = [('Libor1M',SimpleQuote(.01)), ('Libor3M', SimpleQuote(.015)), ('Libor6M', SimpleQuote(.017)), ('Swap1Y', SimpleQuote(.02)), ('Swap2Y', SimpleQuote(.03)), ('Swap3Y', SimpleQuote(.04)), ('Swap5Y', SimpleQuote(.05)), ('Swap7Y', SimpleQuote(.06)), ('Swap10Y', SimpleQuote(.07)), ('Swap20Y', SimpleQuote(.08))] settlement_date = pydate_to_qldate('01-Dec-2013') rate_helpers = [] for label, rate in rates_data: h = make_rate_helper(label, rate, settlement_date) rate_helpers.append(h) ts_day_counter = ActualActual(ISDA) tolerance = 1.0e-15 ts = PiecewiseYieldCurve( 'discount', 'loglinear', settlement_date, rate_helpers, ts_day_counter, tolerance ) zc = zero_rate(ts, (200, 300), settlement_date) # not a real test - just verify execution self.assertAlmostEqual(zc[1][0], 0.0189, 2)
def test_yield(self): rates_data = [('Libor1M',.01), ('Libor3M', .015), ('Libor6M', .017), ('Swap1Y', .02), ('Swap2Y', .03), ('Swap3Y', .04), ('Swap5Y', .05), ('Swap7Y', .06), ('Swap10Y', .07), ('Swap20Y', .08)] settlement_date = pydate_to_qldate('01-Dec-2013') rate_helpers = [] for label, rate in rates_data: h = make_rate_helper(label, rate, settlement_date) rate_helpers.append(h) ts_day_counter = ActualActual(ISDA) tolerance = 1.0e-15 ts = PiecewiseYieldCurve.from_reference_date( BootstrapTrait.Discount, Interpolator.LogLinear, settlement_date, rate_helpers, ts_day_counter, tolerance ) zc = zero_rate(ts, (200, 300), settlement_date) # not a real test - just verify execution self.assertAlmostEqual(zc[1][0], 0.0189, 2)
days = [ 10, 30, 90, 182, 365, 365 * 2, 365 * 3, 365 * 5, 365 * 10, 365 * 15 ] # maturity in columns, observation days in rows zc_rate = np.empty((len(dtI), len(days)), dtype='float64') dt_maturity = np.empty_like(zc_rate, dtype='object') # one observation date at a time, construct a term structure from # deposit and swap rates, then compute zero-coupon rates at # selected maturities for i, obs_date in enumerate(dtI): print(obs_date) rates = df_libor.xs(obs_date) / 100.0 ts = make_term_structure(rates, obs_date) (dt_maturity[i, ], zc_rate[i, ]) = zero_rate(ts, days, obs_date) # PCA on rate change zc_pca = ml.PCA(np.diff(zc_rate, axis=0)) fig = plt.figure() fig.set_size_inches(10, 6) ax = fig.add_subplot(121) dtMin = dt_maturity[0, 0] dtMax = dt_maturity[-1, -1] ax.set_xlim(dtMin, dtMax) ax.set_ylim(0.0, 0.1) # plot a few curves
dtI = dtObs[range(0, len(dtObs) - 1, 60)] days = [10, 30, 90, 182, 365, 365 * 2, 365 * 3, 365 * 5, 365 * 10, 365 * 15] # maturity in columns, observation days in rows zc_rate = np.empty((len(dtI), len(days)), dtype='float64') dt_maturity = np.empty_like(zc_rate, dtype='object') # one observation date at a time, construct a term structure from # deposit and swap rates, then compute zero-coupon rates at # selected maturities for i, obs_date in enumerate(dtI): print(obs_date) rates = df_libor.xs(obs_date) / 100 ts = make_term_structure(rates, obs_date) (dt_maturity[i, ], zc_rate[i, ]) = zero_rate(ts, days, obs_date) # PCA on rate change zc_pca = ml.PCA(np.diff(zc_rate, axis=0)) fig = plt.figure() fig.set_size_inches(10, 6) ax = fig.add_subplot(121) dtMin = dt_maturity[0, 0] dtMax = dt_maturity[-1, -1] ax.set_xlim(dtMin, dtMax) ax.set_ylim(0.0, 0.1) # plot a few curves