使用Python在quantlib中定价浮动债券

10

我试图使用Quantlib(v1.2)的SWIG包在Python中定价一个非常基本的浮动利率债券。我修改了文档中提供的示例。

我的债券到期日为4年。利率设定为10%,债券的价差为0。我的问题是,如果我按10%的利率贴现,为什么债券的现值不是100?我得到的价值是99.54。

谢谢!

from QuantLib import *

frequency_enum, settle_date = 4, Date(5, 1, 2010)
maturity_date = Date(5, 1, 2014)
face_amount = 100.0
settlement_days = 0
fixing_days = 0

calendar = NullCalendar()
settle_date = calendar.adjust(settle_date)
todays_date = calendar.advance(settle_date, -fixing_days, Days)
Settings.instance().evaluationDate = todays_date

rate = 10.0 / 100.0

flat_forward = FlatForward(settle_date,
                           rate,
                           Thirty360(),
                           Compounded,
                           frequency_enum)

discounting_term_structure = RelinkableYieldTermStructureHandle(flat_forward)
index_term_structure = RelinkableYieldTermStructureHandle(flat_forward)

index = USDLibor(Period(3, Months), index_term_structure)

schedule = Schedule(settle_date,
                    maturity_date, Period(frequency_enum),
                    NullCalendar(),
                    Unadjusted, Unadjusted,
                    DateGeneration.Forward, False)

floating_bond = FloatingRateBond(settlement_days,
                                 face_amount,
                                 schedule,
                                 index,
                                 Thirty360(),
                                 Unadjusted,
                                 fixing_days,
                                 [],   # Gearings
                                 [0],  # Spreads
                                 [],      # Caps
                                 [],      # Floors
                                 False,    # Fixing in arrears
                                 face_amount,
                                 settle_date)

bond_engine = DiscountingBondEngine(discounting_term_structure)
floating_bond.setPricingEngine(bond_engine)

# coupon pricers
pricer = BlackIborCouponPricer()

volatility = 0.0
vol = ConstantOptionletVolatility(settlement_days,
                                  calendar,
                                  Unadjusted,
                                  volatility,
                                  Thirty360())

pricer.setCapletVolatility(OptionletVolatilityStructureHandle(vol))
setCouponPricer(floating_bond.cashflows(), pricer)

print floating_bond.NPV(), floating_bond.cleanPrice(), floating_bond.dirtyPrice()
1个回答

7

优惠券利率是使用USDLibor日记数(即实际/360)固定的,这与您提供的支付日记数(30/360)不匹配。您可以通过检查优惠券来查看:

cfs = floating_bond.cashflows()
coupons = [ as_coupon(c) for c in cfs[:-1] ] # the last one is the redemption
print [ (c.rate(), c.accrualPeriod()) for c in coupons ]

这将为所有的票息赋值 T = 0.25,但利率低于10%。

为了得到您想要的价格,您需要匹配利率和应计周期。一种方法是将 Actual360() 作为债券日记数传递,这会在我的机器上给出100.002的价格(我还没有深入调查,但差异可能是由于 LIBOR 定价的结束日期是使用美元日历确定的,可能无法完全匹配票息结束日期造成的)。另一种方法是创建具有内部 30/360 日记数的自定义 LIBOR 指数;我自己还没有尝试过,但您可以通过创建适当的 IborIndex 类实例来实现它。


4
非常感谢。我创建了一个自定义指数并得到了一个精确的100.0的结果!自定义指数是:index = IborIndex('USD Libor', Period(3, Months), settlement_days, USDCurrency(), NullCalendar(), Unadjusted, False, Thirty360(), index_term_structure) - ducky

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接