固定收益

在 QuantLib python 中使用 ytm 定價固定息票債券

  • June 1, 2018

ZeroCurve我是 QuantLib的新手,我很困惑YieldTermStructureHandle

開始日期是2001年10月20日。假設評估日期是2017年5月8日,我可以得到ytm,也就是4.3291。我想我可以建構一條平坦的收益率曲線並貼現現金流。但是,它說給出了負時間(-0.452055)。

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

您的費率曲線的第一個點必須是評估日期,從 i = 0 和您的評估日期開始

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

引用自:https://quant.stackexchange.com/questions/40067