1
$\begingroup$

I'm new to QuantLib and I'm confused about ZeroCurve in YieldTermStructureHandle

The start date is Oct 20, 2001. Assuming the evaluation date is May 8, 2017, and I can obtain the ytm, which is 4.3291. I think I can construct a flat yield curve and discount the cash flow. However, it says negative time (-0.452055) given.

from QuantLib import *
todaysDate = Date(8, 5, 2017)
Settings.instance().evaluationDate = todaysDate


spotDates = [Date(20, 4, 2017)+Period(i*6, Months) for i in range(1, 10)]
spotRates = [4.3291/100]*len(spotDates)

dayCount = ActualActual()
calendar = China()
interpolation = Linear()
compounding = Compounded
compoundingFrequency = 2

spotCurve = ZeroCurve(spotDates, spotRates, dayCount, calendar, interpolation, compounding, compoundingFrequency)
spotCurveHandle = YieldTermStructureHandle(spotCurve)

issueDate = Date(20, 10, 2001)
maturityDate = Date(20, 10, 2021)
tenor = Period(2)

bussinessConvention = Following
dateGeneration = DateGeneration.Backward
monthEnd = False

schedule = Schedule(issueDate, maturityDate, tenor, calendar, bussinessConvention, bussinessConvention, dateGeneration, monthEnd)


couponRate = 4.2/100
coupons = [couponRate]

settlementDays = 
faceValue = 100
fixedRateBond = FixedRateBond(settlementDays, faceValue, schedule, coupons, dayCount)

bondEngine = DiscountingBondEngine(spotCurveHandle)
fixedRateBond.setPricingEngine(bondEngine)

fixedRateBond.NPV()
$\endgroup$
1
$\begingroup$

The first point in your rate curve needs to be the evaluation date, start with i = 0 and your evaluation date

spotDates = [Date(8, 5, 2017)+Period(i*6, Months) for i in range(0, 10)]

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.