def jpy_3m_example(): calendar = objects.get('JAPAN') start = ql.Date(15, 3, 2020) maturity = ql.Date(15, 6, 2020) fixedSchedule = ql.MakeSchedule(start, maturity, ql.Period('3M'), calendar=calendar) floatSchedule = ql.MakeSchedule(start, maturity, ql.Period('3M'), calendar=calendar) jpy_3m_crv = curves.get('JPY.3M') jpy_3m_yts = ql.YieldTermStructureHandle(jpy_3m_crv) jpy_libor_3m = objects.get('JPY.3M').clone(jpy_3m_yts) jpy_yts = ql.YieldTermStructureHandle(curves.get('JPY.OIS')) engine = ql.DiscountingSwapEngine(jpy_yts) swap = ql.VanillaSwap(ql.VanillaSwap.Receiver, 1e9, fixedSchedule, -0.15 / 100, ql.Actual365Fixed(), floatSchedule, jpy_libor_3m, 0, ql.Actual360()) swap.setPricingEngine(engine) print(f"Swap NPV : {swap.NPV():,.2f}") print(f"Swap Rate : {swap.fairRate() * 100:,.6f}")
def __init__(self, swapType, notional, start, maturity, index1, index2, spread, discount): self.swapType = swapType self.notional = notional self.start = start self.maturity = maturity self.yts1 = ql.YieldTermStructureHandle(curves.get(index1)) self.index1 = objects.get(index1).clone(self.yts1) self.yts2 = ql.YieldTermStructureHandle(curves.get(index2)) self.index2 = objects.get(index2).clone(self.yts2) self.spread = spread / 100 / 100 self.discount_yts = ql.YieldTermStructureHandle(curves.get(discount)) self.engine = ql.DiscountingSwapEngine(self.discount_yts) self.swap = self.makeInstrument( swapType, notional, start, maturity, self.index1, self.index2, spread) self.swap.setPricingEngine(self.engine)
def __init__(self, index1, index2, discount, spread, notional, start, maturity): self.swapType = ql.VanillaSwap.Payer self.notional = notional self.start = ql.Date(start, '%d-%m-%Y') self.maturity = ql.Date(maturity, '%d-%m-%Y') self.yts1 = ql.YieldTermStructureHandle(curves.get(index1)) self.index1 = objects.get(index1).clone(self.yts1) self.yts2 = ql.YieldTermStructureHandle(curves.get(index2)) self.index2 = objects.get(index2).clone(self.yts2) self.spread = spread / 100 / 100 self.discount_yts = ql.YieldTermStructureHandle(curves.get(discount)) self.engine = ql.DiscountingSwapEngine(self.discount_yts) self.swap = self.makeInstrument(notional, self.start, self.maturity, self.index1, self.index2, self.spread) self.swap.setPricingEngine(self.engine)
notional = 10e6 start = ql.Date(18, 9, 2019) maturity = ql.Date(18, 9, 2024) basis = BasisSwap(swapType, notional, start, maturity, 'USD.3M', 'USD.1M', 0.00275, 'USD.OIS') indexes = ['USD.3M', 'USD.OIS', 'USD.1M'] for key in indexes: filename = key.replace('.', '') + '.csv' fixings = pd.read_csv(f'fixings/{filename}', header=None).dropna() fixings.columns = ['date', 'value'] fixingDates = [ql.Date(dt, '%Y-%m-%d') for dt in fixings.date] fixingValues = [float(value) / 100 for value in fixings.value] floatingIndex = objects.get(key) for day, fixing in zip(fixingDates, fixingValues): if day < ql.Settings.instance().evaluationDate: floatingIndex.addFixing(day, fixing) print(f"Swap Fair Spread: \t{basis.basisSpread():,.3%}") print(f"Swap BR01: \t\t{basis.BR01():,.2f}") print(f"Swap NPV: \t\t{basis.NPV():,.2f}") swapType = ql.VanillaSwap.Payer notional = 10e6 start = ql.Date(10, 1, 2019) maturity = ql.Date(10, 1, 2023) basis = BasisSwap(swapType, notional, start, maturity, 'USD.3M', 'USD.OIS',