Missing Parameter in Schedule? Inconsistent 2nd reset compared to IborLeg

classic Classic list List threaded Threaded
1 message Options
KK
Reply | Threaded
Open this post in threaded view
|

Missing Parameter in Schedule? Inconsistent 2nd reset compared to IborLeg

KK
The code below, compares floating rate cashflows for a simple GBP swap curve based on deposit rates.
The second cashflow, GBP 18080.1163951 can be calculated by hand by bootstrapping the 6mth and 12mth rate, and this result matches the reset implied by the IborLeg calculation.
Date
07-Jan-13
08-Jul-13 0.0353
07-Jan-14 0.036
Implied Fwd Rate = 0.036061434
Cash flow = 1,000,000 * 0.036061434 * 183/365
Cashflow = 18080.11622

However the 2nd reset implied by Schedule appears to be slightly different at GBP 18077.4356294.

Is there a parameter missing when setting up Schedule?

from QuantLib import *
from datetime import date
def makeQLdatePydate(s_date):
    return date(s_date.year(),s_date.month(),s_date.dayOfMonth())

calendar = UnitedKingdom()
todaysDate = Date(7,January,2013);
Settings.instance().evaluationDate = todaysDate
settlementDate = Date(7,January,2013);

# market quotes
deposits = { (3,Months): 0.0363,
             (6,Months): 0.0353,
             (12,Months): 0.036,
             (18,Months): 0.036 }




for n,unit in deposits.keys():
    deposits[(n,unit)] = SimpleQuote(deposits[(n,unit)])


dayCounter = Actual365Fixed()
settlementDays = 0
depositHelpers = [ DepositRateHelper(QuoteHandle(deposits[(n,unit)]),
                                     Period(n,unit), settlementDays,
                                     calendar, ModifiedFollowing,
                                     False, dayCounter)
                   for n, unit in  deposits.keys()  ]




floatingLegFrequency = Semiannual
floatingLegTenor = Period(6,Months)
floatingLegAdjustment = ModifiedFollowing




discountTermStructure = RelinkableYieldTermStructureHandle()
forecastTermStructure = RelinkableYieldTermStructureHandle()


helpers = depositHelpers

depoSwapCurve = PiecewiseFlatForward(settlementDate, helpers,Actual365Fixed())


swapEngine = DiscountingSwapEngine(discountTermStructure)

discountTermStructure.linkTo(depoSwapCurve)
forecastTermStructure.linkTo(depoSwapCurve)



nominal=1000000
length = 1
maturity = calendar.advance(settlementDate,length,Years)

#
index = GBPLibor(floatingLegTenor,forecastTermStructure)

floatingLegDayCounter = index.dayCounter()


floatingSchedule = Schedule(settlementDate, maturity,
                            floatingLegTenor, calendar,
                            floatingLegAdjustment, floatingLegAdjustment,
                            DateGeneration.Forward, False)


nominals =[nominal for x in floatingSchedule]
 
   

floatingrates = IborLeg(nominals[:-1],floatingSchedule,index,dayCounter)


print "Reset for calculating second cashflow"
print index.fixing(floatingSchedule[1])
print "Start date for calculating second cashflow"
print floatingSchedule[1]
print "End date for calculating second cashflow"
print floatingSchedule[2]
print "Days/365"
print float((makeQLdatePydate(floatingSchedule[2])-makeQLdatePydate(floatingSchedule[1])).days)
print "Second Cashflow from floatingSchedule = nominal * rate * Days/365"
print nominal*index.fixing(floatingSchedule[1])* float((makeQLdatePydate(floatingSchedule[2])-makeQLdatePydate(floatingSchedule[1])).days)/365.0

print "Second cashflow from IborLeg and from simple bootstrapping"
print floatingrates[1].date(),floatingrates[1].amount()