from pybg import get_eval_date, set_eval_date import pybg.ql as ql from datetime import date import pybg fn = pybg.__file__ print("File: %s " % fn) evaldate = date(2004, 9, 20) set_eval_date(evaldate) print("date: {}".format(get_eval_date())) 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))
daycounter=dc30360 ) cb.oasEngine(rh, 0., .2017, True) prc_cb = cb.oasValue(0.0, .2017) print("Call bond value: {0:.3f}".format(prc_cb)) prc = cb.toPrice() yld = cb.toYield(prc) print("Call bond value: {0:.3f}, {1:.3%}".format(prc, yld)) print("\n\nreset date and try after-tax") set_eval_date(20130130) print("date: {}\ncusip: 64966FMG6".format(get_eval_date())) nyc = C.CallBond(.05, date(2016, 9, 1), date(2015, 9, 1), 100., date(2015,9,1), date(2005,9,22), .04, calendar=uscal, daycounter=dc30360 ) atyPx = nyc.atyToPrice(.07, capgains=.238, ordinc=.434) print("7% aty to price (bbg=90.561): {}".format(atyPx))
'25Y': 0.023115, '2Y': 0.005003, '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)
calendar=uscal, daycounter=dc30360) cb.oasEngine(rh, 0., .2017, True) prc_cb = cb.oasValue(0.0, .2017) print("Call bond value: {0:.3f}".format(prc_cb)) prc = cb.toPrice() yld = cb.toYield(prc) print("Call bond value: {0:.3f}, {1:.3%}".format(prc, yld)) print("\n\nreset date and try after-tax") set_eval_date(20130130) print("date: {}\ncusip: 64966FMG6".format(get_eval_date())) nyc = C.CallBond(.05, date(2016, 9, 1), date(2015, 9, 1), 100., date(2015, 9, 1), date(2005, 9, 22), .04, calendar=uscal, daycounter=dc30360) atyPx = nyc.atyToPrice(.07, capgains=.238, ordinc=.434) print("7% aty to price (bbg=90.561): {}".format(atyPx))