固定收益

在 Quantlib Python 中為固定利率債券定價

  • May 17, 2020

我正在嘗試使用以下程式碼為固定利率債券實施定價模型。

import QuantLib as ql
import pandas as pd

todaysDate = ql.Date(31, 8, 2017)
ql.Settings.instance().evaluationDate = todaysDate

spotDates = [ql.Date(1,9,2017), ql.Date(5,9,2017), ql.Date(7,9,2017), ql.Date(14,9,2017),   ql.Date(21,9,2017), ql.Date(2,10,2017), ql.Date(31,10,2017), ql.Date(30,11,2017), ql.Date(2,1,2018), ql.Date(31,1,2018), ql.Date(28,2,2018), ql.Date(3,4,2018), ql.Date(30,4,2018)]
spotRates = [0.066682, 0.067199, 0.067502, 0.068526, 0.069462, 0.070742, 0.072984, 0.073566, 0.073174, 0.072844, 0.072610, 0.072467, 0.072366]

dayCount = ql.Actual365Fixed()
calendar = ql.SouthAfrica()
interpolation = ql.Linear()
compounding = ql.Compounded
compoundingFrequency = ql.Semiannual

spotCurve = ql.ZeroCurve(spotDates, spotRates, dayCount, calendar, 
interpolation, compounding, compoundingFrequency)
spotCurveHandle = ql.YieldTermStructureHandle(spotCurve)

issueDate = ql.Date(20, 4, 2009)
maturityDate = ql.Date(20, 4, 2018)
tenor = ql.Period(ql.Semiannual)
calendar = ql.SouthAfrica()
bussinessConvention = ql.Following
dateGeneration = ql.DateGeneration.Backward
monthEnd = False

schedule = ql.Schedule (issueDate, maturityDate, tenor, calendar, bussinessConvention, bussinessConvention, dateGeneration, monthEnd)

dayCount = ql.Actual365Fixed()
couponRate = 0.0925
coupons = [couponRate]

settlementDays = 3
faceValue = 100
fixedRateBond = ql.FixedRateBond(settlementDays, faceValue, schedule, coupons, dayCount)

bondEngine = ql.DiscountingBondEngine(spotCurveHandle)
fixedRateBond.setPricingEngine(bondEngine)

fixedRateBond.NPV()
print(fixedRateBond.NPV())
print(fixedRateBond.dirtyPrice())
print(fixedRateBond.cleanPrice())
print(fixedRateBond.accruedAmount())
print(fixedRateBond.dayCounter())
print(fixedRateBond.settlementDate())

for c in fixedRateBond.cashflows():
   print('%20s %12f' % (c.date(), c.amount()))

我的現金流量表看起來有點奇怪,我的預期值為 4.625。

October 20th, 2009     4.637671
April 20th, 2010       4.612329
October 20th, 2010     4.637671
April 20th, 2011       4.612329
October 20th, 2011     4.637671
April 20th, 2012       4.637671
October 22nd, 2012     4.688356
April 22nd, 2013       4.612329
October 21st, 2013     4.612329
April 22nd, 2014       4.637671
October 20th, 2014     4.586986
April 20th, 2015       4.612329
October 20th, 2015     4.637671
April 20th, 2016       4.637671
October 20th, 2016     4.637671
April 20th, 2017       4.612329
October 20th, 2017     4.637671
April 20th, 2018       4.612329
April 20th, 2018     100.000000

產生的模型值為:

104.60163528858176
104.6774279539175
101.18016767994489
3.497260273972613
Actual/365 (Fixed) day counter
September 5th, 2017

我獲得的應計利息價值與我們內部系統提供的價值一致,但價格有點偏。淨價預期為 100.81517,臟價預期為 104.31243

嘗試:

dayCount = ql.ActualActual(ql.ActualActual.ISMA,schedule)

您的債券每年支付固定的 9.25%,每年兩次。對於大多數固定息票債券,息票不是“按天計算的”——它應該是準確的年度息票/頻率 = 4.625%(很少有例外,比如墨西哥的 mbonos)。如果您需要計算在優惠券期間的中間應計,例如獲取骯髒的價格,則使用 daycount。對於大多數固定息票貸款、lpns、IR 掉期的固定息票腿等,市場慣例是按天計算息票,這就是您的程式碼所做的。

僅專注於預測預期現金流量,我認為將 daycount 約定更改為 Actual / Actual 不會有幫助。這將導致周期分數為 182/365 或 183/365 或(閏年)/366,而您想要的正好是 1/2,而與各個月份的假期和天數無關。它還會在優惠券期間產生不同的應計,並且您對現在的應計感到滿意。

我認為(尚未嘗試)從 QL 獲得所需現金流的一種方法可能是更改您從

businessConvention = ql.Following

到 businessConvention = ql.Unadjusted

但是,您確實希望應用於現金流的貼現因子在工作日(針對周末和節假日進行調整)。

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