def makeSwaption(self, vol, volType=ql.ShiftedLognormal, delivery=ql.Settlement.Physical, settlementMethod=ql.Settlement.PhysicalOTC, shift=0.02, swapRebuild=True): if swapRebuild: self.makeSwap(self.optionTenor, self.swapTenor, self.fairRate) self.volHandle = ql.QuoteHandle(ql.SimpleQuote(vol)) self.payerSwaption = ql.Swaption( self.payerSwap, ql.EuropeanExercise(self.exerciseDate), delivery, settlementMethod) self.receiverSwaption = ql.Swaption( self.receiverSwap, ql.EuropeanExercise(self.exerciseDate), delivery, settlementMethod) if volType == ql.ShiftedLognormal: swaptionEngine = ql.BlackSwaptionEngine( self.discountTermStructure, ql.QuoteHandle(ql.SimpleQuote(vol)), ql.Actual365Fixed(), shift) elif volType == ql.Normal: swaptionEngine = ql.BachelierSwaptionEngine( self.discountTermStructure, ql.QuoteHandle(ql.SimpleQuote(vol)), ql.Actual365Fixed()) self.payerSwaption.setPricingEngine(swaptionEngine) self.receiverSwaption.setPricingEngine(swaptionEngine)
def __init__(self, underlyingSwap, expiryDate, normalVolatility): self.underlyingSwap = underlyingSwap self.exercise = ql.EuropeanExercise(expiryDate) self.swaption = ql.Swaption(self.underlyingSwap.swap,self.exercise,ql.Settlement.Physical) self.normalVolatility = normalVolatility volQuote = ql.SimpleQuote(normalVolatility) volHandle = ql.QuoteHandle(volQuote) initialEngine = ql.BachelierSwaptionEngine(self.underlyingSwap.discHandle,volHandle,ql.Actual365Fixed()) self.swaption.setPricingEngine(initialEngine)
def make_const_bachelier_vol_engine(discount_handle, volatility): h = ql.QuoteHandle(ql.SimpleQuote(volatility)) return ql.BachelierSwaptionEngine(discount_handle, h)