Hi,
I need to estimate the value of a portfolio of existing swaps in future dates. For example the value in 1 YR, 2YR, .....20YR time. At this moment I don't care about the implied curve for 1YR, 2YR, etc... I am happy to use existing curve and just change the evaluation date.
I though that If I setup the current portfolio of Swaps I would only need to change Settings::instance().evaluationDate() and get the new PV for each swap. But I findout that I still get the PV of cash flows that have already matured. (¿?).
I paste an example in Python (just a prove of concept) that setups a vanilla swap and gets NPV at inception and move 1YR and 2YR the evaluation date. It creates and excel file with the NPV and cashflows for both legs for each valuation date. (attached the excel file).
Thanks in advance for your helps and sorry if they are quite basic questions.
Lluís.
***************************************************
The initial valuation date is 13 - October - 2010
I've previously created a deposwapcurve with depoSwapCurve = PiecewiseLogLinearDiscount( ValueDate, helpers, ActualActual())
# swaps to be priced
swapEngine = DiscountingSwapEngine(discountTermStructure)
nominal = 10000000
length = 10
maturity = calendar.advance(ValueDate,length,Years)
payFixed = True
fixedLegFrequency = Annual
fixedLegTenor = Period(1,Years)
fixedLegAdjustment = ModifiedFollowing
fixedLegDayCounter = Actual365Fixed()
fixedRate = 0.05
floatingLegFrequency = Semiannual
floatingLegTenor = Period(6,Months)
spread = 0.0
fixingDays = 2
index = Euribor6M(forecastTermStructure)
index.addFixing(Date(11,October,2010),0.01204)
floatingLegAdjustment = ModifiedFollowing
floatingLegDayCounter = index.dayCounter()
fixedSchedule = Schedule(ValueDate, maturity,
fixedLegTenor, calendar,
fixedLegAdjustment, fixedLegAdjustment,
DateGeneration.Forward, False)
floatingSchedule = Schedule(ValueDate, maturity,
floatingLegTenor, calendar,
floatingLegAdjustment, floatingLegAdjustment,
DateGeneration.Forward, False)
spot = VanillaSwap(VanillaSwap.Payer, nominal,
fixedSchedule, fixedRate, fixedLegDayCounter,
floatingSchedule, index, spread,
floatingLegDayCounter)
spot.setPricingEngine(swapEngine)
# price on the bootstrapped curves
(......)
def report(swap, name):
print format % (name, formatPrice(swap.NPV(),2),formatPrice(swap.fixedLegNPV(),2),
formatPrice(swap.floatingLegNPV(),2),formatRate(swap.fairSpread(),4),
formatRate(swap.fairRate(),4))
discountTermStructure.linkTo(depoSwapCurve)
forecastTermStructure.linkTo(depoSwapCurve)
report(spot,'depo-fut-swap')
w = xlwt.Workbook()
ws = w.add_sheet('CashFlows0')
styleNum = xlwt.easyxf(num_format_str='#,##0.00')
styleDate = xlwt.easyxf(num_format_str='DD/MM/YYYY')
styleHeader = xlwt.easyxf('font: bold on; align: wrap on, vert centre, horiz center')
NewDate = date(Settings.instance().evaluationDate.year(),Settings.instance().evaluationDate.month(),Settings.instance().evaluationDate.dayOfMonth())
ws.write(0 , 0, 'Date',styleHeader)
ws.write(0 , 1, 'Amount',styleHeader)
ws.write(0 , 2, 'DF',styleHeader)
ws.write(0 , 3, 'PV',styleHeader)
ws.write(0, 4, NewDate,styleDate)
ws.write(0 , 5, 'Date',styleHeader)
ws.write(0 , 6, 'Amount',styleHeader)
ws.write(0 , 7, 'DF',styleHeader)
ws.write(0 , 8, 'PV',styleHeader)
fixedleg = spot.fixedLeg()
floatingleg = spot.floatingLeg()
for i in range(len(fixedleg)):
ws.write(i+1,0, date(fixedleg[i].date().year(),fixedleg[i].date().month(),fixedleg[i].date().dayOfMonth()),styleDate)
ws.write(i+1,1,fixedleg[i].amount(),styleNum)
ws.write(i+1,2,depoSwapCurve.discount(fixedleg[i].date()),styleNum)
ws.write(i+1,3,Formula("B" + str(i+2) + "*C" + str(i+2)),styleNum)
for i in range(len(floatingleg)):
ws.write(i+1,5,date(floatingleg[i].date().year(),floatingleg[i].date().month(),floatingleg[i].date().dayOfMonth()),styleDate)
ws.write(i+1,6,floatingleg[i].amount(),styleNum)
ws.write(i+1,7,depoSwapCurve.discount(floatingleg[i].date()),styleNum)
ws.write(i+1,8,Formula("G" + str(i+2) + "*H" + str(i+2)),styleNum)
ws.write(1, 4, spot.NPV(),styleNum)
# move forward 1 year
Settings.instance().evaluationDate = calendar.advance(ValueDate,1,Years)
(....)
discountTermStructure.linkTo(depoSwapCurve)
forecastTermStructure.linkTo(depoSwapCurve)
report(spot,'depo-swap')
NewDate = date(Settings.instance().evaluationDate.year(),Settings.instance().evaluationDate.month(),Settings.instance().evaluationDate.dayOfMonth())
ws = w.add_sheet('CashFlows1')
ws.write(0 , 0, 'Date',styleHeader)
ws.write(0 , 1, 'Amount',styleHeader)
ws.write(0 , 2, 'DF',styleHeader)
ws.write(0 , 3, 'PV',styleHeader)
ws.write(0,4, NewDate,styleDate)
ws.write(0 , 5, 'Date',styleHeader)
ws.write(0 , 6, 'Amount',styleHeader)
ws.write(0 , 7, 'DF',styleHeader)
ws.write(0 , 8, 'PV',styleHeader)
fixedleg = spot.fixedLeg()
floatingleg = spot.floatingLeg()
for i in range(len(fixedleg)):
ws.write(i+1,0, date(fixedleg[i].date().year(),fixedleg[i].date().month(),fixedleg[i].date().dayOfMonth()),styleDate)
ws.write(i+1,1,fixedleg[i].amount(),styleNum)
ws.write(i+1,2,depoSwapCurve.discount(fixedleg[i].date()),styleNum)
ws.write(i+1,3,Formula("B" + str(i+2) + "*C" + str(i+2)),styleNum)
for i in range(len(floatingleg)):
ws.write(i+1,5,date(floatingleg[i].date().year(),floatingleg[i].date().month(),floatingleg[i].date().dayOfMonth()),styleDate)
ws.write(i+1,6,floatingleg[i].amount(),styleNum)
ws.write(i+1,7,depoSwapCurve.discount(floatingleg[i].date()),styleNum)
ws.write(i+1,8,Formula("G" + str(i+2) + "*H" + str(i+2)),styleNum)
ws.write(1, 4, spot.NPV(),styleNum)
# move 2 year the time
Settings.instance().evaluationDate = calendar.advance(Settings.instance().evaluationDate,1,Years)
(...)
discountTermStructure.linkTo(depoSwapCurve)
forecastTermStructure.linkTo(depoSwapCurve)
report(spot,'depo-swap')
NewDate = date(Settings.instance().evaluationDate.year(),Settings.instance().evaluationDate.month(),Settings.instance().evaluationDate.dayOfMonth())
ws = w.add_sheet('CashFlows2')
ws.write(0 , 0, 'Date',styleHeader)
ws.write(0 , 1, 'Amount',styleHeader)
ws.write(0 , 2, 'DF',styleHeader)
ws.write(0 , 3, 'PV',styleHeader)
ws.write(0,4, NewDate,styleDate)
ws.write(0 , 5, 'Date',styleHeader)
ws.write(0 , 6, 'Amount',styleHeader)
ws.write(0 , 7, 'DF',styleHeader)
ws.write(0 , 8, 'PV',styleHeader)
fixedleg = spot.fixedLeg()
floatingleg = spot.floatingLeg()
for i in range(len(fixedleg)):
ws.write(i+1,0, date(fixedleg[i].date().year(),fixedleg[i].date().month(),fixedleg[i].date().dayOfMonth()),styleDate)
ws.write(i+1,1,fixedleg[i].amount(),styleNum)
ws.write(i+1,2,depoSwapCurve.discount(fixedleg[i].date()),styleNum)
ws.write(i+1,3,Formula("B" + str(i+2) + "*C" + str(i+2)),styleNum)
for i in range(len(floatingleg)):
ws.write(i+1,5,date(floatingleg[i].date().year(),floatingleg[i].date().month(),floatingleg[i].date().dayOfMonth()),styleDate)
ws.write(i+1,6,floatingleg[i].amount(),styleNum)
ws.write(i+1,7,depoSwapCurve.discount(floatingleg[i].date()),styleNum)
ws.write(i+1,8,Formula("G" + str(i+2) + "*H" + str(i+2)),styleNum)
ws.write(1, 4, spot.NPV(),styleNum)
w.save(Foutput)
*************************************************
| Free forum by Nabble | Edit this page |