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()