使用Quantlib,通过YTM计算债券净值

债券标的为170005,我的python代码如下:

 1 import QuantLib as ql
 2 
 3 faceAmount = 100.0
 4 redemption = 100.0
 5 issueDate = ql.Date(20, 2, 2017)
 6 maturity = ql.Date(20, 2, 2047)
 7 couponRate = 0.0377
 8 coupons = [couponRate]
 9 ytm = 0.04245
10 calendar = ql.China(ql.China.IB)
11 frequency = ql.Semiannual
12 compounce = ql.Compounded
13 dayCounter = ql.ActualActual(ql.ActualActual.ISMA)
14 
15 accuracy=1.0e-8
16 maxNum = 500
17 today = calendar.adjust(ql.Date(14, 9, 2018))
18 ql.Settings.evaluationDate = today
19 settlementDays = 0
20 settlementDate = calendar.advance(
21         today,
22         ql.Period(settlementDays, ql.Days))
23 
24 discountingTermStructure = ql.RelinkableYieldTermStructureHandle()
25 flatTermStructure = ql.FlatForward(settlementDate,
26                                    ytm,
27                                    dayCounter,
28                                    compounce,
29                                    frequency)
30 
31 discountingTermStructure.linkTo(flatTermStructure)
32 bondEngin = ql.DiscountingBondEngine(discountingTermStructure)
33 
34 schedule = ql.Schedule(issueDate,
35                           maturity,
36                           ql.Period(frequency),
37                           ql.China(ql.China.IB),
38                           ql.Following,
39                           ql.Following,
40                           ql.DateGeneration.Backward,
41                           False)
42 fixedRateBond = ql.FixedRateBond(settlementDays,
43                        faceAmount,
44                        schedule,
45                        coupons,
46                        dayCounter,
47                        ql.Following,
48                        redemption,
49                        issueDate)
50 fixedRateBond.setPricingEngine(bondEngin)
51 
52 print(fixedRateBond.cleanPrice())
53 print(fixedRateBond.cleanPrice(0.04245,dayCounter,compounce,frequency,ql.Date(14,9,2018)))
54 print(fixedRateBond.dirtyPrice(0.04245,dayCounter,compounce,frequency))
55 print(fixedRateBond.bondYield(95,dayCounter,compounce,frequency,ql.Date(14,9,2018),accuracy,maxNum))
56 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的区别是啥?

转载于:https://www.cnblogs.com/howieRookie/p/9642750.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值