首页 新闻 会员 周边 捐助

关于quantlib计算债券的几个疑问

0
[待解决问题]

import QuantLib as ql

faceAmount = 100.0
redemption = 100.0
issueDate = ql.Date(20, 2, 2017)
maturity = ql.Date(20, 2, 2047)
couponRate = 0.0377
coupons = [couponRate]
ytm = 0.04245
calendar = ql.China(ql.China.IB)
frequency = ql.Semiannual
compounce = ql.Compounded
dayCounter = ql.ActualActual(ql.ActualActual.ISMA)

accuracy=1.0e-8
maxNum = 500
today = calendar.adjust(ql.Date(14, 9, 2018))
ql.Settings.evaluationDate = today
settlementDays = 0
settlementDate = calendar.advance(
today,
ql.Period(settlementDays, ql.Days))

discountingTermStructure = ql.RelinkableYieldTermStructureHandle()
flatTermStructure = ql.FlatForward(settlementDate,
ytm,
dayCounter,
compounce,
frequency)

discountingTermStructure.linkTo(flatTermStructure)
bondEngin = ql.DiscountingBondEngine(discountingTermStructure)

schedule = ql.Schedule(issueDate,
maturity,
ql.Period(frequency),
ql.China(ql.China.IB),
ql.Following,
ql.Following,
ql.DateGeneration.Backward,
False)
fixedRateBond = ql.FixedRateBond(settlementDays,
faceAmount,
schedule,
coupons,
dayCounter,
ql.Following,
redemption,
issueDate)
fixedRateBond.setPricingEngine(bondEngin)

print(fixedRateBond.cleanPrice())
print(fixedRateBond.cleanPrice(0.04245,dayCounter,compounce,frequency,ql.Date(14,9,2018)))
print(fixedRateBond.dirtyPrice(0.04245,dayCounter,compounce,frequency))
print(fixedRateBond.bondYield(95,dayCounter,compounce,frequency,ql.Date(14,9,2018),accuracy,maxNum))
print(flatTermStructure.zeroRate(ql.Date(14,9,2018),dayCounter,compounce, frequency).rate())

输出结果为: 

92.25734945596061
92.19752850225078
92.45364263268556
0.04068211793899536
0.0424500000008563

1、两种pricevalue的计算结果不一样的原因是?

2、NPV和cleanprice的区别是什么?计算结果也不相同。

HowieRookie的主页 HowieRookie | 菜鸟二级 | 园豆:202
提问于:2018-09-14 17:03
< >
分享
所有回答(1)
0

你好,我也是第一次注意到这个细节。

请查看链接:https://www.quantlib.org/reference/class_quant_lib_1_1_bond.html#a04c101af83206923fd686044725444a7

注意这一段话:the theoretical price calculated from a flat term structure might differ slightly from the price calculated from the corresponding yield by means of the other overload of this function. If the price from a constant yield is desired, it is advisable to use such other overload.

如果用到期收益率的话,建议使用另一个重载,也就是有参数的那个。

查看源代码可以看出,cleanPrice()NPV() 将计算委托给定价引擎,而 cleanPrice(...) 将计算委托给 BondFunctions::cleanPrice(...),背后是两种不同的计算体系,cleanPrice()NPV() 将计算委托给定价引擎的具体实现也有不同,这造成了三种不同的价格。计算应该以 cleanPrice(...) 的结果为准。

xuruilong100 | 园豆:202 (菜鸟二级) | 2018-09-22 10:21
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册