4

Python で動作する公式の C++ cpibond の例を取得しようとしています。元の例はこちら: https://github.com/lballabio/quantlib/blob/master/QuantLib/test-suite/inflationcpibond.cppで、scala の場合はこちら: https://github.com/lballabio/quantlib/blob/マスター/QuantLib-SWIG/Scala/examples/CPIBond.scala

試行したことを実行すると、次のエラーが発生します。

RuntimeError: 1 回目の反復: 1 回目の有効な金融商品で失敗、満期は 2010 年 9 月 1 日、基準日は 2009 年 9 月 1 日: 2 回目: 2009 年 9 月 1 日の UK RPI 修正がありません

これが私の試みです:

import QuantLib as ql
calendar = ql.UnitedKingdom()
dayCounter = ql.ActualActual();
convention = ql.ModifiedFollowing

today = ql.Date(20, 11, 2009)
evaluationDate = calendar.adjust(today)
ql.Settings.instance().setEvaluationDate(evaluationDate)        
yTS = ql.YieldTermStructureHandle(ql.FlatForward(evaluationDate, 0.05, dayCounter))

from_date = ql.Date(20, ql.July, 2007);
to_date   = ql.Date(20, ql.November, 2009);
tenor = ql.Period(1, ql.Months)
rpiSchedule = ql.Schedule(from_date, to_date, tenor, calendar, 
                               convention, convention,
                               ql.DateGeneration.Backward, False)
cpiTS = ql.RelinkableZeroInflationTermStructureHandle()
inflationIndex = ql.UKRPI(False, cpiTS)
fixData = [206.1, 207.3, 208.0, 208.9, 209.7, 210.9,
                    209.8, 211.4, 212.1, 214.0, 215.1, 216.8,
                    216.5, 217.2, 218.4, 217.7, 216,
                    212.9, 210.1, 211.4, 211.3, 211.5,
                    212.8, 213.4, 213.4, 213.4, 214.4,213.4, 214.4]
dte_fixings=[dtes for dtes in rpiSchedule]
print len(dte_fixings)
print len(fixData)
#must be the same length
inflationIndex.addFixings(dte_fixings, fixData) 
observationLag = ql.Period(2, ql.Months)
zciisData =[( ql.Date(25, ql.November, 2010), 3.0495 ),
              ( ql.Date(25, ql.November, 2011), 2.93 ),
              ( ql.Date(26, ql.November, 2012), 2.9795 ),
              ( ql.Date(25, ql.November, 2013), 3.029 ),
              ( ql.Date(25, ql.November, 2014), 3.1425 ),
              ( ql.Date(25, ql.November, 2015), 3.211 ),
              ( ql.Date(25, ql.November, 2016), 3.2675 ),
              ( ql.Date(25, ql.November, 2017), 3.3625 ),
              ( ql.Date(25, ql.November, 2018), 3.405 ),
              ( ql.Date(25, ql.November, 2019), 3.48 ),
              ( ql.Date(25, ql.November, 2021), 3.576 ),
              ( ql.Date(25, ql.November, 2024), 3.649 ),
              ( ql.Date(26, ql.November, 2029), 3.751 ),
              ( ql.Date(27, ql.November, 2034), 3.77225),
              ( ql.Date(25, ql.November, 2039), 3.77 ),
              ( ql.Date(25, ql.November, 2049), 3.734 ),
              ( ql.Date(25, ql.November, 2059), 3.714 )]

lRates=[rtes/100.0 for rtes in zip(*zciisData)[1]]
baseZeroRate = lRates[0]

zeroSwapHelpers = [ql.ZeroCouponInflationSwapHelper(a[1]/100,observationLag,
    a[0], calendar, convention, dayCounter, inflationIndex) for a in zciisData]


cpiTS.linkTo(ql.PiecewiseZeroInflation(          
  evaluationDate, calendar, dayCounter, observationLag, 
  inflationIndex.frequency(), inflationIndex.interpolated(), 
  baseZeroRate,
  yTS, zeroSwapHelpers, 1.0e-12, ql.Linear()))


notional = 1000000


fixedRates = [0.1]    

fixedDayCounter = ql.Actual365Fixed()
fixedPaymentConvention = ql.ModifiedFollowing
fixedPaymentCalendar = ql.UnitedKingdom()
contractObservationLag = ql.Period(3, ql.Months)
observationInterpolation = ql.CPI.Flat
settlementDays = 3
growthOnly = True

baseCPI = 206.1
startDate = ql.Date(2, 10, 2007)
endDate = ql.Date(2, 10, 2052)

fixedSchedule = ql.Schedule(startDate, endDate, 
                  ql.Period(6, ql.Months), fixedPaymentCalendar,
                  ql.Unadjusted,
                  ql.Unadjusted,
                  ql.DateGeneration.Backward, False)

bond = ql.CPIBond(settlementDays, notional, growthOnly,
                       baseCPI, contractObservationLag,
                       inflationIndex, observationInterpolation,
                       fixedSchedule, fixedRates, fixedDayCounter, 
                       fixedPaymentConvention)

bondEngine=ql.DiscountingBondEngine(yTS)
bond.setPricingEngine(bondEngine)
print bond.NPV() 
print bond.cleanPrice()

私の問題のほとんどは、オブジェクトがどのように組み合わされるかを把握するのが難しいと感じていることです.

4

1 に答える 1