Пример #1
0
def test_FinOISDepositsFRAsSwaps():

    valuationDate = FinDate(2019, 9, 18)

    dccType = FinDayCountTypes.THIRTY_E_360_ISDA
    depos = []

    spotDays = 0
    settleDt = valuationDate.addWeekDays(spotDays)

    depoDCCType = FinDayCountTypes.ACT_360
    notional = 100.0
    calendarType = FinCalendarTypes.TARGET
    depos = []

    # 1 month
    depositRate = 0.04
    maturityDate = settleDt.addMonths(1)
    depo = FinIborDeposit(settleDt, maturityDate, depositRate, depoDCCType,
                          notional, calendarType)
    depos.append(depo)

    fras = []
    # 1 x 4 FRA
    fraRate = 0.04
    frasettleDt = settleDt.addMonths(9)
    fraMaturityDate = settleDt.addMonths(13)
    fra = FinIborFRA(frasettleDt, fraMaturityDate, fraRate, dccType)
    fras.append(fra)

    # 4 x 7 FRA
    fraRate = 0.03
    frasettleDt = settleDt.addMonths(13)
    fraMaturityDate = settleDt.addMonths(17)
    fra = FinIborFRA(frasettleDt, fraMaturityDate, fraRate, dccType)
    fras.append(fra)

    # 4 x 7 FRA
    fraRate = 0.07
    frasettleDt = settleDt.addMonths(17)
    fraMaturityDate = settleDt.addMonths(21)
    fra = FinIborFRA(frasettleDt, fraMaturityDate, fraRate, dccType)
    fras.append(fra)

    swaps = []
    fixedDCCType = FinDayCountTypes.ACT_365F
    fixedFreqType = FinFrequencyTypes.SEMI_ANNUAL

    swapRate = 0.05
    #    maturityDate = settleDt.addMonths(24)
    #    swap = FinIborSwap(settleDt, maturityDate, swapRate, fixedFreqType,
    #                        fixedDCCType)
    #    swaps.append(swap)

    fixedLegType = FinfixedLegTypes.PAY
    maturityDate = settleDt.addMonths(36)
    swap = FinOIS(settleDt, maturityDate, fixedLegType, swapRate,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settleDt.addMonths(48)
    swap = FinOIS(settleDt, maturityDate, fixedLegType, swapRate,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settleDt.addMonths(60)
    swap = FinOIS(settleDt, maturityDate, fixedLegType, swapRate,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settleDt.addMonths(72)
    swap = FinOIS(settleDt, maturityDate, fixedLegType, swapRate,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settleDt.addMonths(84)
    swap = FinOIS(settleDt, maturityDate, fixedLegType, swapRate,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settleDt.addMonths(96)
    swap = FinOIS(settleDt, maturityDate, fixedLegType, swapRate,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settleDt.addMonths(108)
    swap = FinOIS(settleDt, maturityDate, fixedLegType, swapRate,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settleDt.addMonths(120)
    swap = FinOIS(settleDt, maturityDate, fixedLegType, swapRate,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settleDt.addMonths(132)
    swap = FinOIS(settleDt, maturityDate, fixedLegType, swapRate,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settleDt.addMonths(144)
    swap = FinOIS(settleDt, maturityDate, fixedLegType, swapRate,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settleDt.addMonths(180)
    swap = FinOIS(settleDt, maturityDate, fixedLegType, swapRate,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settleDt.addMonths(240)
    swap = FinOIS(settleDt, maturityDate, fixedLegType, swapRate,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settleDt.addMonths(300)
    swap = FinOIS(settleDt, maturityDate, fixedLegType, swapRate,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settleDt.addMonths(360)
    swap = FinOIS(settleDt, maturityDate, fixedLegType, swapRate,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)

    liborCurve = FinOISCurve(valuationDate, depos, fras, swaps)

    df = liborCurve.df(settleDt)

    testCases.header("SETTLEMENT DATE", "DF")
    testCases.print(str(settleDt), df)
    testCases.header("DATE", "DF")

    for deposit in depos:
        df = liborCurve.df(deposit._maturityDate)
        testCases.print(str(deposit._maturityDate), df)

    for swap in swaps:
        df = liborCurve.df(swap._maturityDate)
        testCases.print(str(swap._maturityDate), df)
Пример #2
0
def test_FinOISDepositsFuturesSwaps():

    spotDate = FinDate(6, 6, 2018)
    spotDays = 0
    settleDt = spotDate.addWeekDays(spotDays)
    depoDCCType = FinDayCountTypes.THIRTY_E_360_ISDA

    depo = FinIborDeposit(settleDt, "1D", 1.712 / 100.0, depoDCCType)
    depos = [depo]

    fras = []

    fraRate = futureToFRARate(97.6675, -0.00005)
    frasettleDt = spotDate.nextIMMDate()
    fraMaturityDate = frasettleDt.nextIMMDate()
    fra = FinIborFRA(frasettleDt, fraMaturityDate, fraRate, depoDCCType)
    fras.append(fra)

    fraRate = futureToFRARate(97.5200, -0.00060)
    frasettleDt = fraMaturityDate
    fraMaturityDate = frasettleDt.nextIMMDate()
    fra = FinIborFRA(frasettleDt, fraMaturityDate, fraRate, depoDCCType)
    fras.append(fra)

    fraRate = futureToFRARate(97.3550, -0.00146)
    frasettleDt = fraMaturityDate
    fraMaturityDate = frasettleDt.nextIMMDate()
    fra = FinIborFRA(frasettleDt, fraMaturityDate, fraRate, depoDCCType)
    fras.append(fra)

    fraRate = futureToFRARate(97.2450, -0.00263)
    frasettleDt = fraMaturityDate
    fraMaturityDate = frasettleDt.nextIMMDate()
    fra = FinIborFRA(frasettleDt, fraMaturityDate, fraRate, depoDCCType)
    fras.append(fra)

    fraRate = futureToFRARate(97.1450, -0.00411)
    frasettleDt = fraMaturityDate
    fraMaturityDate = frasettleDt.nextIMMDate()
    fra = FinIborFRA(frasettleDt, fraMaturityDate, fraRate, depoDCCType)
    fras.append(fra)

    fraRate = futureToFRARate(97.0750, -0.00589)
    frasettleDt = frasettleDt.nextIMMDate()
    fraMaturityDate = frasettleDt.nextIMMDate()
    fra = FinIborFRA(frasettleDt, fraMaturityDate, fraRate, depoDCCType)
    fras.append(fra)

    ###########################################################################

    spotDays = 2
    startDate = spotDate.addWeekDays(spotDays)

    swaps = []
    fixedLegType = FinSwapTypes.PAY
    fixedDCCType = FinDayCountTypes.THIRTY_E_360
    fixedFreqType = FinFrequencyTypes.SEMI_ANNUAL
    floatFreqType = FinFrequencyTypes.QUARTERLY
    notional = 1000000
    floatSpread = 0.0
    floatDCCType = FinDayCountTypes.ACT_360
    calendarType = FinCalendarTypes.US
    busDayAdjustRule = FinBusDayAdjustTypes.PRECEDING

    swapRate = 0.02776305
    paymentLag = 1

    swap = FinOIS(startDate, "2Y", fixedLegType, swapRate, fixedFreqType,
                  fixedDCCType, notional, paymentLag, floatSpread,
                  floatFreqType, floatDCCType, calendarType, busDayAdjustRule)

    swaps.append(swap)

    liborCurve = FinOISCurve(spotDate, depos, fras, swaps)

    times = np.linspace(0.0, 2.0, 25)
    dates = spotDate.addYears(times)
    zeroRates = liborCurve.zeroRate(dates)
    fwdRates = liborCurve.fwd(dates)

    if PLOT_GRAPHS:
        plt.figure(figsize=(8, 6))
        plt.plot(times, zeroRates * 100, label="zero rates")
        plt.plot(times, fwdRates * 100, label="fwd rates")
        plt.xlabel("Times")
        plt.ylabel("CC forward rates")
        plt.legend()

        print("==============================================================")
        for fra in fras:
            print(fra)
        print("==============================================================")

        endDate = spotDate
        df = liborCurve.df(endDate)
        print(endDate, df)

        endDate = settleDt
        df = liborCurve.df(endDate)
        print(endDate, df)

        endDate = FinDate(20, 6, 2018)
        df = liborCurve.df(endDate)
        print(endDate, df)

        for fra in fras:
            endDate = fra._maturityDate
            df = liborCurve.df(endDate)
            print(endDate, df)

        for swap in swaps:
            endDate = swap._maturityDate
            df = liborCurve.df(endDate)
            print(endDate, df)

        swap.printFixedLegPV(spotDate)
        swap.printFloatLegPV(spotDate)