""" Unittests for the CDS related classes. """ from quantlib.settings import Settings from quantlib.quotes import SimpleQuote from quantlib.termstructures.yields.api import FlatForward from quantlib.termstructures.credit.api import SpreadCdsHelper, UpfrontCdsHelper, PiecewiseDefaultCurve from quantlib.time.api import (UnitedStates, Date, Actual365Fixed, Following, Quarterly, TwentiethIMM, March, Period) from yieldcurve import YC import pdb def create_helper(): calendar = UnitedStates() todays_date = Date(31, March, 2014) Settings.instance().evaluation_date = todays_date recovery_rate = 0.4 upfronts = [0.01, 0.02, 0.04, 0.06] tenors = [Period(str(i) +"Yr") for i in [2, 3, 5, 7]] tenors = Period("2Yr") ts_curve = YC() helpers = UpfrontCdsHelper(0.05, 0.05, tenors, 0, calendar, Quarterly, Following, TwentiethIMM, Actual365Fixed(), recovery_rate, ts_curve) pdb.set_trace() #trait = ['HazardRate', 'DefaultDensity', 'SurvivalProbability']: #interpolator = ['Linear', 'LogLinear', 'BackwardFlat']: curve = PiecewiseDefaultCurve('HazardRate','BackwardFlat', reference_date=todays_date, helpers=[helpers], daycounter=Actual365Fixed()) print(curve.survival_probability(Date(10, 3, 2015))) return curve if __name__=="__main__": curve = create_helper() prob = curve.survival_probability(Date(10, 3, 2017)) pdb.set_trace()