Esempio n. 1
0
def test_FinIborFRAsOnly():

    # TO DO FIX THIS
    valuation_date = Date(23, 2, 2018)

    spotDays = 0
    settlement_date = valuation_date.addWeekDays(spotDays)

    depoDCCType = DayCountTypes.ACT_360
    notional = 100.0

    payFixed = True

    calendar_type = CalendarTypes.TARGET
    fras = []

    # 1 x 4 FRA
    fraRate = 0.04
    fraSettlementDate = settlement_date.addMonths(1)
    fraMaturityDate = settlement_date.addMonths(4)
    fra = FinIborFRA(fraSettlementDate, fraMaturityDate, fraRate,
                      depoDCCType, notional, payFixed, calendar_type)
    fras.append(fra)

    # 4 x 7 FRA
    fraRate = 0.08
    fraSettlementDate = settlement_date.addMonths(4)
    fraMaturityDate = settlement_date.addMonths(7)
    fra = FinIborFRA(fraSettlementDate, fraMaturityDate, fraRate,
                      depoDCCType, notional, payFixed, calendar_type)
    fras.append(fra)

    depos = []
    swaps = []

    libor_curve = FinIborSingleCurveOLD(valuation_date,
                                       depos,
                                       fras,
                                       swaps)

    testCases.header("DATE", "MATDATE", "VALUE")

    """ Check calibration """
    for fra in fras:
        v = fra.value(settlement_date, libor_curve)
        testCases.print("FRA:", fra._maturity_date, v)
Esempio n. 2
0
def test_FinOISFRAsOnly():

    # TO DO FIX THIS
    valuationDate = FinDate(23, 2, 2018)

    spotDays = 0
    settleDt = valuationDate.addWeekDays(spotDays)

    depoDCCType = FinDayCountTypes.ACT_360
    notional = 100.0

    payFixed = True

    calendarType = FinCalendarTypes.TARGET
    fras = []

    # 1 x 4 FRA
    fraRate = 0.04
    frasettleDt = settleDt.addMonths(1)
    fraMaturityDate = settleDt.addMonths(4)
    fra = FinIborFRA(frasettleDt, fraMaturityDate, fraRate,
                      depoDCCType, notional, payFixed, calendarType)
    fras.append(fra)

    # 4 x 7 FRA
    fraRate = 0.08
    frasettleDt = settleDt.addMonths(4)
    fraMaturityDate = settleDt.addMonths(7)
    fra = FinIborFRA(frasettleDt, fraMaturityDate, fraRate,
                      depoDCCType, notional, payFixed, calendarType)
    fras.append(fra)

    swaps = []

    liborCurve = FinOISCurve(settleDt,
                               fras,
                               swaps)

    testCases.header("DATE", "MATDATE", "VALUE")

    ''' Check calibration '''
    for fra in fras:
        v = fra.value(settleDt, liborCurve)
        testCases.print("FRA:", fra._maturityDate, v)
Esempio n. 3
0
def test_FinOISDepositsFRAsSwaps():

    valuation_date = Date(18, 9, 2019)

    dccType = DayCountTypes.THIRTY_E_360_ISDA
    depos = []

    spotDays = 0
    settleDt = valuation_date.addWeekDays(spotDays)

    depoDCCType = DayCountTypes.ACT_360
    notional = 100.0
    calendar_type = CalendarTypes.TARGET
    depos = []

    # 1 month
    deposit_rate = 0.04
    maturity_date = settleDt.addMonths(1)
    depo = FinIborDeposit(settleDt, maturity_date, deposit_rate,
                          depoDCCType, notional, calendar_type)
    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 = DayCountTypes.ACT_365F
    fixedFreqType = FrequencyTypes.SEMI_ANNUAL

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

    fixed_legType = Finfixed_legTypes.PAY
    maturity_date = settleDt.addMonths(36)
    swap = FinOIS(settleDt, maturity_date, fixed_legType, swap_rate,
                        fixedFreqType,
                        fixedDCCType)
    swaps.append(swap)

    maturity_date = settleDt.addMonths(48)
    swap = FinOIS(settleDt, maturity_date, fixed_legType, swap_rate,
                        fixedFreqType,
                        fixedDCCType)
    swaps.append(swap)

    maturity_date = settleDt.addMonths(60)
    swap = FinOIS(settleDt, maturity_date, fixed_legType, swap_rate,
                        fixedFreqType,
                        fixedDCCType)
    swaps.append(swap)

    maturity_date = settleDt.addMonths(72)
    swap = FinOIS(settleDt, maturity_date, fixed_legType, swap_rate,
                        fixedFreqType,
                        fixedDCCType)
    swaps.append(swap)

    maturity_date = settleDt.addMonths(84)
    swap = FinOIS(settleDt, maturity_date, fixed_legType, swap_rate,
                        fixedFreqType,
                        fixedDCCType)
    swaps.append(swap)

    maturity_date = settleDt.addMonths(96)
    swap = FinOIS(settleDt, maturity_date, fixed_legType, swap_rate,
                        fixedFreqType,
                        fixedDCCType)
    swaps.append(swap)

    maturity_date = settleDt.addMonths(108)
    swap = FinOIS(settleDt, maturity_date, fixed_legType, swap_rate,
                        fixedFreqType,
                        fixedDCCType)
    swaps.append(swap)

    maturity_date = settleDt.addMonths(120)
    swap = FinOIS(settleDt, maturity_date, fixed_legType, swap_rate,
                        fixedFreqType,
                        fixedDCCType)
    swaps.append(swap)

    maturity_date = settleDt.addMonths(132)
    swap = FinOIS(settleDt, maturity_date, fixed_legType, swap_rate,
                        fixedFreqType,
                        fixedDCCType)
    swaps.append(swap)

    maturity_date = settleDt.addMonths(144)
    swap = FinOIS(settleDt, maturity_date, fixed_legType, swap_rate,
                        fixedFreqType,
                        fixedDCCType)
    swaps.append(swap)

    maturity_date = settleDt.addMonths(180)
    swap = FinOIS(settleDt, maturity_date, fixed_legType, swap_rate,
                        fixedFreqType,
                        fixedDCCType)
    swaps.append(swap)

    maturity_date = settleDt.addMonths(240)
    swap = FinOIS(settleDt, maturity_date, fixed_legType, swap_rate,
                        fixedFreqType,
                        fixedDCCType)
    swaps.append(swap)

    maturity_date = settleDt.addMonths(300)
    swap = FinOIS(settleDt, maturity_date, fixed_legType, swap_rate,
                        fixedFreqType,
                        fixedDCCType)
    swaps.append(swap)

    maturity_date = settleDt.addMonths(360)
    swap = FinOIS(settleDt, maturity_date, fixed_legType, swap_rate,
                        fixedFreqType,
                        fixedDCCType)
    swaps.append(swap)

    libor_curve = OISCurve(valuation_date,
                           depos,
                           fras,
                           swaps)

    df = libor_curve.df(settleDt)

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

    for deposit in depos:
        df = libor_curve.df(deposit._maturity_date)
        testCases.print(str(deposit._maturity_date), df)

    for swap in swaps:
        df = libor_curve.df(swap._maturity_date)
        testCases.print(str(swap._maturity_date), df)
Esempio n. 4
0
def test_FinOISDepositsFuturesSwaps():

    
    spotDate = Date(6, 6, 2018)
    spotDays = 0
    settleDt = spotDate.addWeekDays(spotDays)
    depoDCCType = DayCountTypes.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
    start_date = spotDate.addWeekDays(spotDays)

    swaps = []
    fixed_legType = FinSwapTypes.PAY
    fixedDCCType = DayCountTypes.THIRTY_E_360
    fixedFreqType = FrequencyTypes.SEMI_ANNUAL
    floatFreqType = FrequencyTypes.QUARTERLY
    notional = 1000000
    floatSpread = 0.0
    floatDCCType = DayCountTypes.ACT_360
    calendar_type = CalendarTypes.US
    busDayAdjustRule = BusDayAdjustTypes.PRECEDING

    swap_rate = 0.02776305
    payment_lag = 1

    swap = FinOIS(start_date, "2Y", fixed_legType,
                  swap_rate, fixedFreqType, fixedDCCType, notional,
                  payment_lag, floatSpread, floatFreqType, floatDCCType,
                  calendar_type, busDayAdjustRule)

    swaps.append(swap)

    libor_curve = OISCurve(spotDate, depos, fras, swaps)

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

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

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

        end_date = spotDate
        df = libor_curve.df(end_date)
        print(end_date, df)

        end_date = settleDt
        df = libor_curve.df(end_date)
        print(end_date, df)

        end_date = Date(20, 6, 2018)
        df = libor_curve.df(end_date)
        print(end_date, df)

        for fra in fras:
            end_date = fra._maturity_date
            df = libor_curve.df(end_date)
            print(end_date, df)

        for swap in swaps:
            end_date = swap._maturity_date
            df = libor_curve.df(end_date)
            print(end_date, df)

        swap.printFixedLegPV(spotDate)
        swap.printFloatLegPV(spotDate)
def test_FinIborDepositsFuturesSwaps():

    spotDate = FinDate(6, 6, 2018)
    spotDays = 0
    settlementDate = spotDate.addWeekDays(spotDays)
    depoDCCType = FinDayCountTypes.ACT_360
    depos = []
    depositRate = 0.0231381
    depo = FinIborDeposit(settlementDate, "3M", depositRate, depoDCCType)
    depos.append(depo)

    depositRate = 0.027
    depo = FinIborDeposit(settlementDate, "3M", depositRate, depoDCCType)
    depos.append(depo)

    depos = []
    depo = FinIborDeposit(settlementDate, "1M", 0.0230, depoDCCType)
    depos.append(depo)
    depo = FinIborDeposit(settlementDate, "2M", 0.0235, depoDCCType)
    depos.append(depo)
    depo = FinIborDeposit(settlementDate, "3M", 0.0240, depoDCCType)
    depos.append(depo)

    fras = []

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

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

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

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

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

    fraRate = futureToFRARate(97.0750, -0.00589)
    fraSettlementDate = fraSettlementDate.nextIMMDate()
    fraMaturityDate = fraSettlementDate.nextIMMDate()
    fra = FinIborFRA(fraSettlementDate, 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
    principal = 0.0
    floatSpread = 0.0
    floatDCCType = FinDayCountTypes.ACT_360
    calendarType = FinCalendarTypes.US
    busDayAdjustRule = FinBusDayAdjustTypes.PRECEDING

    swapRate = 0.02776305

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

    swaps.append(swap)

    liborCurve = FinIborSingleCurveOLD(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 = settlementDate
        df = liborCurve.df(endDate)
        print(endDate, df)

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

        for depo in depos:
            endDate = depo._maturityDate
            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)
def test_FinIborDepositsFRAsSwaps():

    valuationDate = FinDate(18, 9, 2019)

    dccType = FinDayCountTypes.THIRTY_E_360_ISDA
    depos = []

    spotDays = 0
    settlementDate = valuationDate.addWeekDays(spotDays)

    depositRate = 0.050
    maturityDate = settlementDate.addMonths(1)
    depo = FinIborDeposit(settlementDate, maturityDate, depositRate, dccType)
    depos.append(depo)

    maturityDate = settlementDate.addMonths(2)
    depo = FinIborDeposit(settlementDate, maturityDate, depositRate, dccType)
    depos.append(depo)

    maturityDate = settlementDate.addMonths(3)
    depo = FinIborDeposit(settlementDate, maturityDate, depositRate, dccType)
    depos.append(depo)

    maturityDate = settlementDate.addMonths(6)
    depo = FinIborDeposit(settlementDate, maturityDate, depositRate, dccType)
    depos.append(depo)

    maturityDate = settlementDate.addMonths(9)
    depo = FinIborDeposit(settlementDate, maturityDate, depositRate, dccType)
    depos.append(depo)

    maturityDate = settlementDate.addMonths(12)
    depo = FinIborDeposit(settlementDate, maturityDate, depositRate, dccType)
    depos.append(depo)

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

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

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

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

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

    fixedLegType = FinSwapTypes.PAY
    maturityDate = settlementDate.addMonths(36)
    swap = FinIborSwapOLD(settlementDate, maturityDate, fixedLegType, swapRate,
                          fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settlementDate.addMonths(48)
    swap = FinIborSwapOLD(settlementDate, maturityDate, fixedLegType, swapRate,
                          fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settlementDate.addMonths(60)
    swap = FinIborSwapOLD(settlementDate, maturityDate, fixedLegType, swapRate,
                          fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settlementDate.addMonths(72)
    swap = FinIborSwapOLD(settlementDate, maturityDate, fixedLegType, swapRate,
                          fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settlementDate.addMonths(84)
    swap = FinIborSwapOLD(settlementDate, maturityDate, fixedLegType, swapRate,
                          fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settlementDate.addMonths(96)
    swap = FinIborSwapOLD(settlementDate, maturityDate, fixedLegType, swapRate,
                          fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settlementDate.addMonths(108)
    swap = FinIborSwapOLD(settlementDate, maturityDate, fixedLegType, swapRate,
                          fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settlementDate.addMonths(120)
    swap = FinIborSwapOLD(settlementDate, maturityDate, fixedLegType, swapRate,
                          fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settlementDate.addMonths(132)
    swap = FinIborSwapOLD(settlementDate, maturityDate, fixedLegType, swapRate,
                          fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settlementDate.addMonths(144)
    swap = FinIborSwapOLD(settlementDate, maturityDate, fixedLegType, swapRate,
                          fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settlementDate.addMonths(180)
    swap = FinIborSwapOLD(settlementDate, maturityDate, fixedLegType, swapRate,
                          fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settlementDate.addMonths(240)
    swap = FinIborSwapOLD(settlementDate, maturityDate, fixedLegType, swapRate,
                          fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settlementDate.addMonths(300)
    swap = FinIborSwapOLD(settlementDate, maturityDate, fixedLegType, swapRate,
                          fixedFreqType, fixedDCCType)
    swaps.append(swap)

    maturityDate = settlementDate.addMonths(360)
    swap = FinIborSwapOLD(settlementDate, maturityDate, fixedLegType, swapRate,
                          fixedFreqType, fixedDCCType)
    swaps.append(swap)

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

    df = liborCurve.df(settlementDate)

    testCases.header("SETTLEMENT DATE", "DF")
    testCases.print(str(settlementDate), 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)
Esempio n. 7
0
def buildIborSingleCurve(valuationDate):

    settlementDate = valuationDate.addDays(2)
    dcType = FinDayCountTypes.ACT_360

    depos = []
    fras = []
    swaps = []

    maturityDate = settlementDate.addMonths(1)
    depo1 = FinIborDeposit(valuationDate, maturityDate, -0.00251, dcType)
    depos.append(depo1)

    # Series of 1M futures
    startDate = settlementDate.nextIMMDate()
    endDate = startDate.addMonths(1)
    fra = FinIborFRA(startDate, endDate, -0.0023, dcType)
    fras.append(fra)

    startDate = startDate.addMonths(1)
    endDate = startDate.addMonths(1)
    fra = FinIborFRA(startDate, endDate, -0.00234, dcType)
    fras.append(fra)

    startDate = startDate.addMonths(1)
    endDate = startDate.addMonths(1)
    fra = FinIborFRA(startDate, endDate, -0.00225, dcType)
    fras.append(fra)

    startDate = startDate.addMonths(1)
    endDate = startDate.addMonths(1)
    fra = FinIborFRA(startDate, endDate, -0.00226, dcType)
    fras.append(fra)

    startDate = startDate.addMonths(1)
    endDate = startDate.addMonths(1)
    fra = FinIborFRA(startDate, endDate, -0.00219, dcType)
    fras.append(fra)

    startDate = startDate.addMonths(1)
    endDate = startDate.addMonths(1)
    fra = FinIborFRA(startDate, endDate, -0.00213, dcType)
    fras.append(fra)

    startDate = startDate.addMonths(1)
    endDate = startDate.addMonths(1)
    fra = FinIborFRA(startDate, endDate, -0.00186, dcType)
    fras.append(fra)

    startDate = startDate.addMonths(1)
    endDate = startDate.addMonths(1)
    fra = FinIborFRA(startDate, endDate, -0.00189, dcType)
    fras.append(fra)

    startDate = startDate.addMonths(1)
    endDate = startDate.addMonths(1)
    fra = FinIborFRA(startDate, endDate, -0.00175, dcType)
    fras.append(fra)

    startDate = startDate.addMonths(1)
    endDate = startDate.addMonths(1)
    fra = FinIborFRA(startDate, endDate, -0.00143, dcType)
    fras.append(fra)

    startDate = startDate.addMonths(1)
    endDate = startDate.addMonths(1)
    fra = FinIborFRA(startDate, endDate, -0.00126, dcType)
    fras.append(fra)

    startDate = startDate.addMonths(1)
    endDate = startDate.addMonths(1)
    fra = FinIborFRA(startDate, endDate, -0.00126, dcType)
    fras.append(fra)

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

    fixedFreq = FinFrequencyTypes.ANNUAL
    dcType = FinDayCountTypes.THIRTY_E_360
    fixedLegType = FinSwapTypes.PAY

    #######################################
    maturityDate = settlementDate.addMonths(24)
    swapRate = -0.001506
    swap1 = FinIborSwap(settlementDate, maturityDate, fixedLegType, swapRate,
                        fixedFreq, dcType)
    swaps.append(swap1)

    #######################################
    maturityDate = settlementDate.addMonths(36)
    swapRate = -0.000185
    swap2 = FinIborSwap(settlementDate, maturityDate, fixedLegType, swapRate,
                        fixedFreq, dcType)
    swaps.append(swap2)

    #######################################
    maturityDate = settlementDate.addMonths(48)
    swapRate = 0.001358
    swap3 = FinIborSwap(settlementDate, maturityDate, fixedLegType, swapRate,
                        fixedFreq, dcType)
    swaps.append(swap3)

    #######################################
    maturityDate = settlementDate.addMonths(60)
    swapRate = 0.0027652
    swap4 = FinIborSwap(settlementDate, maturityDate, fixedLegType, swapRate,
                        fixedFreq, dcType)
    swaps.append(swap4)

    #######################################
    maturityDate = settlementDate.addMonths(72)
    swapRate = 0.0041539
    swap5 = FinIborSwap(settlementDate, maturityDate, fixedLegType, swapRate,
                        fixedFreq, dcType)
    swaps.append(swap5)

    #######################################
    maturityDate = settlementDate.addMonths(84)
    swapRate = 0.0054604
    swap6 = FinIborSwap(settlementDate, maturityDate, fixedLegType, swapRate,
                        fixedFreq, dcType)
    swaps.append(swap6)

    #######################################
    maturityDate = settlementDate.addMonths(96)
    swapRate = 0.006674
    swap7 = FinIborSwap(settlementDate, maturityDate, fixedLegType, swapRate,
                        fixedFreq, dcType)
    swaps.append(swap7)

    #######################################
    maturityDate = settlementDate.addMonths(108)
    swapRate = 0.007826
    swap8 = FinIborSwap(settlementDate, maturityDate, fixedLegType, swapRate,
                        fixedFreq, dcType)
    swaps.append(swap8)

    #######################################
    maturityDate = settlementDate.addMonths(120)
    swapRate = 0.008821
    swap9 = FinIborSwap(settlementDate, maturityDate, fixedLegType, swapRate,
                        fixedFreq, dcType)
    swaps.append(swap9)

    #######################################
    maturityDate = settlementDate.addMonths(132)
    swapRate = 0.0097379
    swap10 = FinIborSwap(settlementDate, maturityDate, fixedLegType, swapRate,
                         fixedFreq, dcType)
    swaps.append(swap10)

    #######################################
    maturityDate = settlementDate.addMonths(144)
    swapRate = 0.0105406
    swap11 = FinIborSwap(settlementDate, maturityDate, fixedLegType, swapRate,
                         fixedFreq, dcType)
    swaps.append(swap11)

    #######################################
    maturityDate = settlementDate.addMonths(180)
    swapRate = 0.0123927
    swap12 = FinIborSwap(settlementDate, maturityDate, fixedLegType, swapRate,
                         fixedFreq, dcType)
    swaps.append(swap12)

    #######################################
    maturityDate = settlementDate.addMonths(240)
    swapRate = 0.0139882
    swap13 = FinIborSwap(settlementDate, maturityDate, fixedLegType, swapRate,
                         fixedFreq, dcType)
    swaps.append(swap13)

    #######################################
    maturityDate = settlementDate.addMonths(300)
    swapRate = 0.0144972
    swap14 = FinIborSwap(settlementDate, maturityDate, fixedLegType, swapRate,
                         fixedFreq, dcType)
    swaps.append(swap14)

    #######################################
    maturityDate = settlementDate.addMonths(360)
    swapRate = 0.0146081
    swap15 = FinIborSwap(settlementDate, maturityDate, fixedLegType, swapRate,
                         fixedFreq, dcType)
    swaps.append(swap15)

    #######################################
    maturityDate = settlementDate.addMonths(420)
    swapRate = 0.01461897
    swap16 = FinIborSwap(settlementDate, maturityDate, fixedLegType, swapRate,
                         fixedFreq, dcType)
    swaps.append(swap16)

    #######################################
    maturityDate = settlementDate.addMonths(480)
    swapRate = 0.014567455
    swap17 = FinIborSwap(settlementDate, maturityDate, fixedLegType, swapRate,
                         fixedFreq, dcType)
    swaps.append(swap17)

    #######################################
    maturityDate = settlementDate.addMonths(540)
    swapRate = 0.0140826
    swap18 = FinIborSwap(settlementDate, maturityDate, fixedLegType, swapRate,
                         fixedFreq, dcType)
    swaps.append(swap18)

    #######################################
    maturityDate = settlementDate.addMonths(600)
    swapRate = 0.01436822
    swap19 = FinIborSwap(settlementDate, maturityDate, fixedLegType, swapRate,
                         fixedFreq, dcType)
    swaps.append(swap19)

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

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

    testCases.header("LABEL", "DATE", "VALUE")
    ''' Check calibration '''
    for depo in depos:
        v = depo.value(settlementDate, liborCurve)
        testCases.print("DEPO VALUE:", depo._maturityDate, v)

    for fra in fras:
        v = fra.value(settlementDate, liborCurve)
        testCases.print("FRA VALUE:", fra._maturityDate, v)

    for swap in swaps:
        v = swap.value(settlementDate, liborCurve)
        testCases.print("SWAP VALUE:", swap._maturityDate, v)

    return liborCurve
def test_swapValuationExample():

    # Example from
    # https://blog.deriscope.com/index.php/en/excel-interest-rate-swap-price-dual-bootstrapping-curve

    vBloomberg = 388147

    valuation_date = Date(30, 11, 2018)

    start_date = Date(27, 12, 2017)
    maturity_date = Date(27, 12, 2067)
    notional = 10 * ONE_MILLION
    fixed_legType = FinSwapTypes.RECEIVE

    fixedRate = 0.0150
    fixedDCCType = DayCountTypes.THIRTY_360_BOND
    fixedFreqType = FrequencyTypes.ANNUAL

    floatSpread = 0.0
    floatDCCType = DayCountTypes.ACT_360
    floatFreqType = FrequencyTypes.SEMI_ANNUAL

    offMarketSwap = FinIborSwap(start_date, maturity_date, fixed_legType,
                                fixedRate, fixedFreqType, fixedDCCType,
                                notional, floatSpread, floatFreqType,
                                floatDCCType)

    interp_type = FinInterpTypes.LINEAR_ZERO_RATES

    depoDCCType = DayCountTypes.ACT_360
    depos = []

    ###########################################################################
    # MARKET
    ###########################################################################

    spotDays = 0
    settlement_date = valuation_date.addWeekDays(spotDays)
    depo = FinIborDeposit(settlement_date, "6M", -0.2510 / 100.0, depoDCCType)
    depos.append(depo)

    fras = []
    fraDCCType = DayCountTypes.ACT_360

    fra = FinIborFRA(settlement_date.addTenor("1M"), "6M", -0.2450 / 100.0,
                     fraDCCType)
    fras.append(fra)
    fra = FinIborFRA(settlement_date.addTenor("2M"), "6M", -0.2435 / 100.0,
                     fraDCCType)
    fras.append(fra)
    fra = FinIborFRA(settlement_date.addTenor("3M"), "6M", -0.2400 / 100.0,
                     fraDCCType)
    fras.append(fra)
    fra = FinIborFRA(settlement_date.addTenor("4M"), "6M", -0.2360 / 100.0,
                     fraDCCType)
    fras.append(fra)
    fra = FinIborFRA(settlement_date.addTenor("5M"), "6M", -0.2285 / 100.0,
                     fraDCCType)
    fras.append(fra)
    fra = FinIborFRA(settlement_date.addTenor("6M"), "6M", -0.2230 / 100.0,
                     fraDCCType)
    fras.append(fra)
    fra = FinIborFRA(settlement_date.addTenor("7M"), "6M", -0.2110 / 100.0,
                     fraDCCType)
    fras.append(fra)
    fra = FinIborFRA(settlement_date.addTenor("8M"), "6M", -0.1990 / 100.0,
                     fraDCCType)
    fras.append(fra)
    fra = FinIborFRA(settlement_date.addTenor("9M"), "6M", -0.1850 / 100.0,
                     fraDCCType)
    fras.append(fra)
    fra = FinIborFRA(settlement_date.addTenor("10M"), "6M", -0.1680 / 100.0,
                     fraDCCType)
    fras.append(fra)
    fra = FinIborFRA(settlement_date.addTenor("11M"), "6M", -0.1510 / 100.0,
                     fraDCCType)
    fras.append(fra)
    fra = FinIborFRA(settlement_date.addTenor("12M"), "6M", -0.1360 / 100.0,
                     fraDCCType)
    fras.append(fra)

    swaps = []
    fixed_legType = FinSwapTypes.PAY
    fixedDCCType = DayCountTypes.THIRTY_360_BOND
    fixedFreqType = FrequencyTypes.ANNUAL

    swap = FinIborSwap(settlement_date, "2Y", fixed_legType, -0.1525 / 100.0,
                       fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinIborSwap(settlement_date, "3Y", fixed_legType, -0.0185 / 100.0,
                       fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinIborSwap(settlement_date, "4Y", fixed_legType, 0.1315 / 100.0,
                       fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinIborSwap(settlement_date, "5Y", fixed_legType, 0.2745 / 100.0,
                       fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinIborSwap(settlement_date, "6Y", fixed_legType, 0.4135 / 100.0,
                       fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinIborSwap(settlement_date, "7Y", fixed_legType, 0.5439 / 100.0,
                       fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinIborSwap(settlement_date, "8Y", fixed_legType, 0.6652 / 100.0,
                       fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinIborSwap(settlement_date, "9Y", fixed_legType, 0.7784 / 100.0,
                       fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinIborSwap(settlement_date, "10Y", fixed_legType, 0.8799 / 100.0,
                       fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinIborSwap(settlement_date, "11Y", fixed_legType, 0.9715 / 100.0,
                       fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinIborSwap(settlement_date, "12Y", fixed_legType, 1.0517 / 100.0,
                       fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinIborSwap(settlement_date, "15Y", fixed_legType, 1.2369 / 100.0,
                       fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinIborSwap(settlement_date, "20Y", fixed_legType, 1.3965 / 100.0,
                       fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinIborSwap(settlement_date, "25Y", fixed_legType, 1.4472 / 100.0,
                       fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinIborSwap(settlement_date, "30Y", fixed_legType, 1.4585 / 100.0,
                       fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinIborSwap(settlement_date, "35Y", fixed_legType, 1.4595 / 100.0,
                       fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinIborSwap(settlement_date, "40Y", fixed_legType, 1.4535 / 100.0,
                       fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinIborSwap(settlement_date, "45Y", fixed_legType, 1.4410 / 100.0,
                       fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinIborSwap(settlement_date, "50Y", fixed_legType, 1.4335 / 100.0,
                       fixedFreqType, fixedDCCType)
    swaps.append(swap)

    iborDepos = depos.copy()
    iborFras = fras.copy()
    iborSwaps = swaps.copy()

    iborCurve = IborSingleCurve(valuation_date, iborDepos, iborFras, iborSwaps,
                                interp_type)
    v1 = offMarketSwap.value(valuation_date, iborCurve, iborCurve,
                             -0.268 / 100.0)

    testCases.banner("DERISCOPE EXAMPLE REPLICATION")
    testCases.header("LABEL", "VALUE")
    testCases.print("BBG VALUE", vBloomberg)
    testCases.print("FP ONE CURVE VALUE", v1)

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

    depoDCCType = DayCountTypes.ACT_360
    depos = []

    spotDays = 0
    settlement_date = valuation_date.addWeekDays(spotDays)
    depo = FinIborDeposit(settlement_date, "1D", -0.3490 / 100.0, depoDCCType)
    depos.append(depo)

    fras = []

    swaps = []
    fixed_legType = FinSwapTypes.PAY
    fixedDCCType = DayCountTypes.ACT_365F
    fixedFreqType = FrequencyTypes.ANNUAL

    # Standard OIS with standard annual terms
    swap = FinOIS(settlement_date, "2W", fixed_legType, -0.3600 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "1M", fixed_legType, -0.3560 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "2M", fixed_legType, -0.3570 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "3M", fixed_legType, -0.3580 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "4M", fixed_legType, -0.3575 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "5M", fixed_legType, -0.3578 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "6M", fixed_legType, -0.3580 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "7M", fixed_legType, -0.3600 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "8M", fixed_legType, -0.3575 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "9M", fixed_legType, -0.3569 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "10M", fixed_legType, -0.3553 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "11M", fixed_legType, -0.3534 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "12M", fixed_legType, -0.3496 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "18M", fixed_legType, -0.3173 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)

    swap = FinOIS(settlement_date, "2Y", fixed_legType, -0.2671 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "30M", fixed_legType, -0.2070 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "3Y", fixed_legType, -0.1410 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "4Y", fixed_legType, -0.0060 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "5Y", fixed_legType, 0.1285 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "6Y", fixed_legType, 0.2590 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "7Y", fixed_legType, 0.3830 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "8Y", fixed_legType, 0.5020 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "9Y", fixed_legType, 0.6140 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "10Y", fixed_legType, 0.7160 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "11Y", fixed_legType, 0.8070 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "12Y", fixed_legType, 0.8890 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "15Y", fixed_legType, 1.0790 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "20Y", fixed_legType, 1.2460 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "25Y", fixed_legType, 1.3055 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "30Y", fixed_legType, 1.3270 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "35Y", fixed_legType, 1.3315 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "40Y", fixed_legType, 1.3300 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)
    swap = FinOIS(settlement_date, "50Y", fixed_legType, 1.3270 / 100.0,
                  fixedFreqType, fixedDCCType)
    swaps.append(swap)

    oisDepos = depos.copy()
    oisFras = fras.copy()
    oisSwaps = swaps.copy()

    #    oisCurveFF = FinOISCurve(valuation_date, oisDepos, oisFras, oisSwaps, interp_type)

    iborDualCurve = IborDualCurve(valuation_date, oisCurveFF, iborDepos,
                                  iborFras, iborSwaps, interp_type)