Quiero usar QuantLib Python para calcular el precio de un swap en 2 fechas de evaluación diferentes durante la vida útil del swap. Lo siguiente es lo que he intentado hasta ahora:
from QuantLib import *
# datos globales
calendar = TARGET()
todaysDate = Date(6,Noviembre,2001);
Settings.instance().evaluationDate = todaysDate
settlementDate = Date(8,Noviembre,2001);
# comillas de mercado
deposits = { (1,Semanas): 0.0382,
(1,Meses): 0.0372,
(3,Meses): 0.0363,
(6,Meses): 0.0353,
(9,Meses): 0.0348,
(1,Años): 0.0345 }
swaps = { (2,Años): 0.037125,
(3,Años): 0.0398,
(5,Años): 0.0443,
(10,Años): 0.05165,
(15,Años): 0.055175 }
# convertirlos en objetos Quote
for n,unit in deposits.keys():
deposits[(n,unit)] = SimpleQuote(deposits[(n,unit)])
for n,unit in swaps.keys():
swaps[(n,unit)] = SimpleQuote(swaps[(n,unit)])
# construir ayudantes de tasas
dayCounter = Actual360()
settlementDays = 2
depositHelpers = [ DepositRateHelper(QuoteHandle(deposits[(n,unit)]),
Period(n,unit), settlementDays,
calendar, ModifiedFollowing,
False, dayCounter)
for n, unit in [(1,Semanas),(1,Meses),(3,Meses),
(6,Meses),(9,Meses),(1,Años)] ]
settlementDays = 2
fixedLegFrequency = Anual
fixedLegTenor = Period(1,Años)
fixedLegAdjustment = Unadjusted
fixedLegDayCounter = Thirty360()
floatingLegFrequency = Semiannual
floatingLegTenor = Period(6,Meses)
floatingLegAdjustment = ModifiedFollowing
swapHelpers = [ SwapRateHelper(QuoteHandle(swaps[(n,unit)]),
Period(n,unit), calendar,
fixedLegFrequency, fixedLegAdjustment,
fixedLegDayCounter, Euribor6M())
for n, unit in swaps.keys() ]
# manijas de estructura de plazos
discountTermStructure = RelinkableYieldTermStructureHandle()
forecastTermStructure = RelinkableYieldTermStructureHandle()
# construcción de la estructura de plazos
helpers = depositHelpers + swapHelpers
depoFraSwapCurve = PiecewiseFlatForward(settlementDate, helpers, Actual360())
# swaps a ser valorados
swapEngine = DiscountingSwapEngine(discountTermStructure)
nominal = 1000000
length = 5
maturity = calendar.advance(settlementDate,length,Años)
payFixed = True
fixedLegFrequency = Anual
fixedLegAdjustment = Unadjusted
fixedLegDayCounter = Thirty360()
fixedRate = 0.04
floatingLegFrequency = Semiannual
spread = 0.0
fixingDays = 2
index = Euribor6A(forecastTermStructure)
floatingLegAdjustment = ModifiedFollowing
floatingLegDayCounter = index.dayCounter()
fixedSchedule = Schedule(settlementDate, maturity,
fixedLegTenor, calendar,
fixedLegAdjustment, fixedLegAdjustment,
DateGeneration.Forward, False)
floatingSchedule = Schedule(settlementDate, maturity,
floatingLegTenor, calendar,
floatingLegAdjustment, floatingLegAdjustment,
DateGeneration.Forward, False)
spot = VanillaSwap(VanillaSwap.Payer, nominal,
fixedSchedule, fixedRate, fixedLegDayCounter,
floatingSchedule, index, spread,
floatingLegDayCounter)
spot.setPricingEngine(swapEngine)
# precio en dos fechas de evaluación diferentes
discountTermStructure.linkTo(depoFraSwapCurve)
forecastTermStructure.linkTo(depoFraSwapCurve)
print(Settings.instance().evaluationDate)
print(spot.NPV())
print
Settings.instance().evaluationDate = Date(13,Noviembre,2001)
settlementDate = Date(15,Noviembre,2001)
depoFraSwapCurve = PiecewiseFlatForward(settlementDate, helpers, Actual360())
discountTermStructure.linkTo(depoFraSwapCurve)
forecastTermStructure.linkTo(depoFraSwapCurve)
print(Settings.instance().evaluationDate)
print(spot.NPV())
Recibo el siguiente error:
6 de Noviembre de 2001
19065.5382172
13 de Noviembre de 2001
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
in ()
145 forecastTermStructure.linkTo(depoFraSwapCurve)
146
--> 147 print(spot.NPV())
148
C:\ProgramData\Anaconda2\lib\site-packages\QuantLib\QuantLib.pyc in NPV(self)
9157
9158 def NPV(self):
-> 9159 return _QuantLib.Instrument_NPV(self)
9160
9161 def errorEstimate(self):
RuntimeError: 2nd leg: Falta la fijación Euribor6M Actual/360 para el 6 de Noviembre de 2001
¿Alguna idea de lo que debo hacer para resolver este error?