def test_euriborcurve(self): # 1/21/2012 is a weekend, should be adjusted to 23rd evaldate = date(2012, 1, 21) #set_eval_date(evaldate) depos = dict([(str(n) + "M", .05) for n in [1, 3, 6, 9, 12]]) swaps = dict([(str(n) + "Y", .05) for n in [2, 3, 5, 7, 10, 12, 15, 20, 30]]) futures = {} rh = curves.RateHelperCurve(EURiborCurve("6M", Annual)) rh.update(depos, futures, swaps, evaldate) print("Test EURibor") self.assertTrue(rh.referenceDate == date(2012, 1, 25)) self.assertTrue(rh.tenorquote("10Y") == .05) self.assertTrue(rh.discount(0.0) == 1.0) self.assertTrue(rh.discount(10.0) <= rh.discount(5.0)) print("Done\n\n")
def test_swapcurve(self): evaldate = date(2004, 9, 20) set_eval_date(evaldate) futures = dict( zip(("ED1", "ED2", "ED3", "ED4", "ED5", "ED6", "ED7", "ED8"), (96.2875, 96.7875, 96.9875, 96.6875, 96.4875, 96.3875, 96.2875, 96.0875))) depos = dict(zip(("1W", "1M"), (.0382, 0.0372))) swaps = dict( zip(("3y", "5y", "10Y", "15Y"), (0.0398, 0.0443, 0.05165, 0.055175))) rh = curves.RateHelperCurve(EURiborCurve("6M", Annual)) rh.update(depos, futures, swaps, evaldate) self.assertTrue(abs(rh.discount(10.) - 0.597) < 0.001)
) depotenors, depospots = ( ("1W", "1M", "3M", "6M", "9M", "1y"), (.0382, 0.0372, 0.0363, 0.0353, 0.0348, 0.0345) ) swaptenors, swapspots = ( ("2y", "3y", "5y", "10Y", "15Y"), (0.037125, 0.0398, 0.0443, 0.05165, 0.055175) ) futures = dict(zip(futtenors, futspots)) depos = dict(zip(depotenors, depospots)) swaps = dict(zip(swaptenors, swapspots)) print("one") rh = curves.RateHelperCurve(EURiborCurve("6M", pybg.enums.Frequencies.Annual)) print("two") dt = rh.update(depos, {}, swaps, evaldate) print("\nin quicktest curve: \ncrv date: %s" % dt) print("ref date: %s" % rh.referenceDate) df = rh.discount(10.0) print("\nTest curve: \ndiscount: %s" % df) #BONDS uscal = enums.Calendars.UnitedStates(enums.Calendars.GOVERNMENTBOND) print("\n\nbonding: {}".format(get_eval_date()))
'30Y': 0.02366, '3Y': 0.00568, '40Y': 0.023895, '4Y': 0.007007, '5Y': 0.008685, '6Y': 0.010549, '7Y': 0.012316, '8Y': 0.01387, '9Y': 0.015218} print("\nSetting eval date: %s" % dt0) set_eval_date(dt0) print("eval date used: {}".format(get_eval_date())) rh = curves.RateHelperCurve(USDLiborCurve("3M")) rh.update(depos, {}, swaps, get_eval_date()) govbondcurve = curves.CurveBase(pybg.enums.Calendars.UnitedStates(pybg.enums.Calendars.GOVERNMENTBOND), 1, pybg.enums.DayCounters.Actual360(), pybg.enums.Frequencies.Semiannual, pybg.enums.BusinessDayConventions.ModifiedFollowing, pybg.enums.DayCounters.ActualActual(pybg.enums.DayCounters.Bond), pybg.enums.DayCounters.ActualActual(pybg.enums.DayCounters.ISDA) ) bcrv = curves.BondCurve(govbondcurve) dated = [date(2005, 3, 15),
set_eval_date(evaldate) futtenors, futspots = (("ED1", "ED2", "ED3", "ED4", "ED5", "ED6", "ED7", "ED8"), (96.2875, 96.7875, 96.9875, 96.6875, 96.4875, 96.3875, 96.2875, 96.0875)) depotenors, depospots = (("1W", "1M", "3M", "6M", "9M", "1y"), (.0382, 0.0372, 0.0363, 0.0353, 0.0348, 0.0345)) swaptenors, swapspots = (("2y", "3y", "5y", "10Y", "15Y"), (0.037125, 0.0398, 0.0443, 0.05165, 0.055175)) futures = dict(zip(futtenors, futspots)) depos = dict(zip(depotenors, depospots)) swaps = dict(zip(swaptenors, swapspots)) rh = curves.RateHelperCurve(EURiborCurve("6M", Annual)) rh.update(depos, {}, swaps, evaldate) print("\nTest curve: \ndate: %s" % rh.referenceDate) df = rh.discount(10.0) print("\nTest curve: \ndiscount: %s" % df) swp2 = EuriborSwap("6M", rh.referenceDate, date(2009, 9, 22), .04, FixedPayer) swp2.setEngine(rh) print("\nSwap\nNPV: %s | fx: %s | fl: %s" % (swp2.NPV, swp2.fixedLegNPV, swp2.floatingLegNPV)) print("Fixed Leg")
set_eval_date(evaldate) futtenors, futspots = (("ED1", "ED2", "ED3", "ED4", "ED5", "ED6", "ED7", "ED8"), (96.2875, 96.7875, 96.9875, 96.6875, 96.4875, 96.3875, 96.2875, 96.0875)) depotenors, depospots = (("1W", "1M", "3M", "6M", "9M", "1y"), (.0382, 0.0372, 0.0363, 0.0353, 0.0348, 0.0345)) swaptenors, swapspots = (("2y", "3y", "5y", "10Y", "15Y"), (0.037125, 0.0398, 0.0443, 0.05165, 0.055175)) futures = dict(zip(futtenors, futspots)) depos = dict(zip(depotenors, depospots)) swaps = dict(zip(swaptenors, swapspots)) rh = curves.RateHelperCurve(EURiborCurve("6M", Frequencies.Annual)) rh.update(depos, {}, swaps, evaldate) df = rh.discount(10.0) print("\nTest curve: \ndate: %s" % rh.referenceDate) print("\nTest curve: \ndiscount: %s" % df) swp2 = EuriborSwap("6M", rh.referenceDate, date(2009, 9, 22), .04, FixedPayer) swp2.setEngine(rh) print("\nSwap\nNPV: %s | fx: %s | fl: %s" % (swp2.NPV, swp2.fixedLegNPV, swp2.floatingLegNPV)) print("Fixed Leg") cfNPV = 0.0