Ejemplo n.º 1
0
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}")
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    def __init__(self, config, notional, start, maturity, fixedRate, spread,
                 *rest):
        self.config = swap_configs[config]

        self.notional = notional
        self.start = ql.Date(start, '%d-%m-%Y')
        self.maturity = ql.Date(maturity, '%d-%m-%Y')
        self.fixedRate = fixedRate / 100
        self.spread = spread / 100
        self.fixedFreq = ql.Period(self.config.get('fixedFreq'))
        self.fixedDayCount = self.config.get('fixedDayCount')
        self.calendar = self.config.get('calendar')

        self.fixedSchedule = ql.MakeSchedule(self.start,
                                             self.maturity,
                                             self.fixedFreq,
                                             calendar=self.calendar,
                                             rule=ql.DateGeneration.Backward)

        self.floatIndex = self.config.get('floatIndex')
        self.forwardCurve = curves.get(config)
        self.forwardCurve_yts = ql.RelinkableYieldTermStructureHandle()
        self.forwardCurve_yts.linkTo(self.forwardCurve)

        self.floatIndex = self.floatIndex.clone(self.forwardCurve_yts)

        self.floatSchedule = ql.MakeSchedule(self.start,
                                             self.maturity,
                                             self.floatIndex.tenor(),
                                             calendar=self.calendar,
                                             rule=ql.DateGeneration.Backward)

        self.swap = ql.VanillaSwap(ql.VanillaSwap.Payer, self.notional,
                                   self.fixedSchedule, self.fixedRate,
                                   self.fixedDayCount, self.floatSchedule,
                                   self.floatIndex, self.spread,
                                   self.floatIndex.dayCounter())
        self.discountCurve = curves.get(self.config.get('discountCurve'))

        self.discountCurve_yts = ql.RelinkableYieldTermStructureHandle()
        self.discountCurve_yts.linkTo(self.discountCurve)

        engine = ql.DiscountingSwapEngine(self.discountCurve_yts)
        self.swap.setPricingEngine(engine)