OvernightIndexedSwap in Python
Posted by KK on
URL: http://quantlib.414.s1.nabble.com/OvernightIndexedSwap-in-Python-tp15920.html
Hi All
Is is possible to create an OIS object OvernightIndexedSwap in python?
Creating a curve is possible, but creating a swap and hence finding fairRate() or NPV() is eluding me at the moment.
In the code below I have used "OvernightIndexedSwap" but this is undefined in python quantlib.
Many thanks
from QuantLib import *
settlementDate = Date(18,9,2014);
maturity = Date(18,9,2016)
nominal = 1000000
fixedRate = 0.025
dayCount = Actual365Fixed()
spread = 0
discountTermStructure = RelinkableYieldTermStructureHandle()
forecastTermStructure = RelinkableYieldTermStructureHandle()
MyOisHelper = [OISRateHelper( 0, Period(6,Months),QuoteHandle(SimpleQuote(0.02)), Sonia() ),OISRateHelper( 0, Period(3,Years),QuoteHandle(SimpleQuote(0.03)), Sonia() )]
OISSwapCurve = PiecewiseFlatForward(settlementDate, MyOisHelper, dayCount)
swapEngine = DiscountingSwapEngine(discountTermStructure)
print OISSwapCurve.discount(Date(21,12,2013))
fixedSchedule = Schedule(settlementDate,maturity, Annual, UnitedKingdom(), ModifiedFollowing, ModifiedFollowing, DateGeneration.Forward, False)
ois_swap = OvernightIndexedSwap(OvernightIndexedSwap.Payer, nominal, fixedSchedule, fixedRate, dayCount, Sonia(), spread);
ois_swap.setPricingEngine(swapEngine)
swapEngine = DiscountingSwapEngine(discountTermStructure)
discountTermStructure.linkTo(OISSwapCurve)
forecastTermStructure.linkTo(OISSwapCurve)
print ois_swap.NPV();
print ois_swap.fairRate();