Ejemplo n.º 1
0
def test_LiborSwap():

    # I have tried to reproduce the example from the blog by Ioannis Rigopoulos
    # https://blog.deriscope.com/index.php/en/excel-interest-rate-swap-price-dual-bootstrapping-curve
    startDate = FinDate(27, 12, 2017)
    endDate = FinDate(27, 12, 2067)

    fixedCoupon = 0.015
    fixedFreqType = FinFrequencyTypes.ANNUAL
    fixedDayCountType = FinDayCountTypes.THIRTY_E_360

    floatSpread = 0.0
    floatFreqType = FinFrequencyTypes.SEMI_ANNUAL
    floatDayCountType = FinDayCountTypes.ACT_360
    firstFixing = -0.00268

    swapCalendarType = FinCalendarTypes.WEEKEND
    busDayAdjustType = FinBusDayAdjustTypes.FOLLOWING
    dateGenRuleType = FinDateGenRuleTypes.BACKWARD
    fixedLegType = FinSwapTypes.RECEIVE

    notional = 10.0 * ONE_MILLION

    swap = FinIborSwap(startDate, endDate, fixedLegType, fixedCoupon,
                       fixedFreqType, fixedDayCountType, notional, floatSpread,
                       floatFreqType, floatDayCountType, swapCalendarType,
                       busDayAdjustType, dateGenRuleType)
    ''' Now perform a valuation after the swap has seasoned but with the
    same curve being used for discounting and working out the implied
    future Libor rates. '''

    valuationDate = FinDate(30, 11, 2018)
    settlementDate = valuationDate.addDays(2)
    liborCurve = buildIborSingleCurve(valuationDate)
    v = swap.value(settlementDate, liborCurve, liborCurve, firstFixing)

    v_bbg = 388147.0
    testCases.header("LABEL", "VALUE")
    testCases.print("SWAP_VALUE USING ONE_CURVE", v)
    testCases.print("BLOOMBERG VALUE", v_bbg)
    testCases.print("DIFFERENCE VALUE", v_bbg - v)
Ejemplo n.º 2
0
def test_dp_example():

    #  http://www.derivativepricing.com/blogpage.asp?id=8

    startDate = FinDate(14, 11, 2011)
    endDate = FinDate(14, 11, 2016)
    fixedFreqType = FinFrequencyTypes.SEMI_ANNUAL
    swapCalendarType = FinCalendarTypes.TARGET
    busDayAdjustType = FinBusDayAdjustTypes.MODIFIED_FOLLOWING
    dateGenRuleType = FinDateGenRuleTypes.BACKWARD
    fixedDayCountType = FinDayCountTypes.THIRTY_E_360_ISDA
    fixedLegType = FinSwapTypes.PAY
    fixedCoupon = 0.0124
    notional = ONE_MILLION

    swap = FinIborSwap(startDate,
                       endDate,
                       fixedLegType,
                       fixedCoupon=fixedCoupon,
                       fixedFreqType=fixedFreqType,
                       fixedDayCountType=fixedDayCountType,
                       floatFreqType=FinFrequencyTypes.SEMI_ANNUAL,
                       floatDayCountType=FinDayCountTypes.ACT_360,
                       notional=notional,
                       calendarType=swapCalendarType,
                       busDayAdjustType=busDayAdjustType,
                       dateGenRuleType=dateGenRuleType)

    #    swap.printFixedLegFlows()

    dts = [
        FinDate(14, 11, 2011),
        FinDate(14, 5, 2012),
        FinDate(14, 11, 2012),
        FinDate(14, 5, 2013),
        FinDate(14, 11, 2013),
        FinDate(14, 5, 2014),
        FinDate(14, 11, 2014),
        FinDate(14, 5, 2015),
        FinDate(16, 11, 2015),
        FinDate(16, 5, 2016),
        FinDate(14, 11, 2016)
    ]

    dfs = [
        0.9999843, 0.9966889, 0.9942107, 0.9911884, 0.9880738, 0.9836490,
        0.9786276, 0.9710461, 0.9621778, 0.9514315, 0.9394919
    ]

    valuationDate = startDate

    curve = FinDiscountCurve(valuationDate, dts, np.array(dfs),
                             FinInterpTypes.FLAT_FWD_RATES)

    v = swap.value(valuationDate, curve, curve)

    #    swap.printFixedLegPV()
    #    swap.printFloatLegPV()

    # This is essentially zero
    testCases.header("LABEL", "VALUE")
    testCases.print("Swap Value on a Notional of $1M:", v)
Ejemplo n.º 3
0
def test_swapValuationExample():

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

    vBloomberg = 388147

    valuationDate = FinDate(30, 11, 2018)

    startDate = FinDate(27, 12, 2017)
    maturityDate = FinDate(27, 12, 2067)
    notional = 10 * ONE_MILLION
    fixedLegType = FinSwapTypes.RECEIVE

    fixedRate = 0.0150
    fixedDCCType = FinDayCountTypes.THIRTY_360_BOND
    fixedFreqType = FinFrequencyTypes.ANNUAL

    floatSpread = 0.0
    floatDCCType = FinDayCountTypes.ACT_360
    floatFreqType = FinFrequencyTypes.SEMI_ANNUAL

    offMarketSwap = FinIborSwap(startDate, maturityDate, fixedLegType,
                                fixedRate, fixedFreqType, fixedDCCType,
                                notional, floatSpread, floatFreqType,
                                floatDCCType)

    interpType = FinInterpTypes.LINEAR_ZERO_RATES

    depoDCCType = FinDayCountTypes.ACT_360
    depos = []

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

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

    fras = []
    fraDCCType = FinDayCountTypes.ACT_360

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

    swaps = []
    fixedLegType = FinSwapTypes.PAY
    fixedDCCType = FinDayCountTypes.THIRTY_360_BOND
    fixedFreqType = FinFrequencyTypes.ANNUAL

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

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

    iborCurve = FinIborSingleCurve(valuationDate, iborDepos, iborFras,
                                   iborSwaps, interpType)
    v1 = offMarketSwap.value(valuationDate, 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 = FinDayCountTypes.ACT_360
    depos = []

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

    fras = []

    swaps = []
    fixedLegType = FinSwapTypes.PAY
    fixedDCCType = FinDayCountTypes.ACT_365F
    fixedFreqType = FinFrequencyTypes.ANNUAL

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

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

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

    #    oisCurveFF = FinOISCurve(valuationDate, oisDepos, oisFras, oisSwaps, interpType)

    iborDualCurve = FinIborDualCurve(valuationDate, oisCurveFF, iborDepos,
                                     iborFras, iborSwaps, interpType)
Ejemplo n.º 4
0
def test_FinIborBermudanSwaptionBKModel():
    ''' Replicate examples in paper by Leif Andersen which can be found at
    file:///C:/Users/Dominic/Downloads/SSRN-id155208.pdf '''

    valuationDate = FinDate(1, 1, 2011)
    settlementDate = valuationDate
    exerciseDate = settlementDate.addYears(1)
    swapMaturityDate = settlementDate.addYears(4)

    swapFixedCoupon = 0.060
    swapFixedFrequencyType = FinFrequencyTypes.SEMI_ANNUAL
    swapFixedDayCountType = FinDayCountTypes.ACT_365F

    liborCurve = FinDiscountCurveFlat(valuationDate, 0.0625,
                                      FinFrequencyTypes.SEMI_ANNUAL,
                                      FinDayCountTypes.ACT_365F)

    fwdPAYSwap = FinIborSwap(exerciseDate, swapMaturityDate, FinSwapTypes.PAY,
                             swapFixedCoupon, swapFixedFrequencyType,
                             swapFixedDayCountType)

    fwdSwapValue = fwdPAYSwap.value(settlementDate, liborCurve, liborCurve)

    testCases.header("LABEL", "VALUE")
    testCases.print("FWD SWAP VALUE", fwdSwapValue)

    # fwdPAYSwap.printFixedLegPV()

    # Now we create the European swaptions
    fixedLegType = FinSwapTypes.PAY
    europeanSwaptionPay = FinIborSwaption(settlementDate, exerciseDate,
                                          swapMaturityDate, fixedLegType,
                                          swapFixedCoupon,
                                          swapFixedFrequencyType,
                                          swapFixedDayCountType)

    fixedLegType = FinSwapTypes.RECEIVE
    europeanSwaptionRec = FinIborSwaption(settlementDate, exerciseDate,
                                          swapMaturityDate, fixedLegType,
                                          swapFixedCoupon,
                                          swapFixedFrequencyType,
                                          swapFixedDayCountType)

    ###########################################################################
    ###########################################################################
    ###########################################################################
    # BLACK'S MODEL
    ###########################################################################
    ###########################################################################
    ###########################################################################

    testCases.banner("======= ZERO VOLATILITY ========")
    model = FinModelBlack(0.0000001)
    testCases.print("Black Model", model._volatility)

    valuePay = europeanSwaptionPay.value(settlementDate, liborCurve, model)
    testCases.print("EUROPEAN BLACK PAY VALUE ZERO VOL:", valuePay)

    valueRec = europeanSwaptionRec.value(settlementDate, liborCurve, model)
    testCases.print("EUROPEAN BLACK REC VALUE ZERO VOL:", valueRec)

    payRec = valuePay - valueRec
    testCases.print("PAY MINUS RECEIVER :", payRec)

    testCases.banner("======= 20%% BLACK VOLATILITY ========")

    model = FinModelBlack(0.20)
    testCases.print("Black Model", model._volatility)

    valuePay = europeanSwaptionPay.value(settlementDate, liborCurve, model)
    testCases.print("EUROPEAN BLACK PAY VALUE:", valuePay)

    valueRec = europeanSwaptionRec.value(settlementDate, liborCurve, model)
    testCases.print("EUROPEAN BLACK REC VALUE:", valueRec)

    payRec = valuePay - valueRec
    testCases.print("PAY MINUS RECEIVER :", payRec)

    ###########################################################################
    ###########################################################################
    ###########################################################################
    # BK MODEL
    ###########################################################################
    ###########################################################################
    ###########################################################################

    testCases.banner("=======================================================")
    testCases.banner("=======================================================")
    testCases.banner("==================== BK MODEL =========================")
    testCases.banner("=======================================================")
    testCases.banner("=======================================================")

    testCases.banner("======= 0% VOLATILITY EUROPEAN SWAPTION BK MODEL ======")

    # Used BK with constant short-rate volatility
    sigma = 0.000000001
    a = 0.01
    numTimeSteps = 100
    model = FinModelRatesBK(sigma, a, numTimeSteps)

    valuePay = europeanSwaptionPay.value(valuationDate, liborCurve, model)
    testCases.print("EUROPEAN BK PAY VALUE:", valuePay)

    valueRec = europeanSwaptionRec.value(valuationDate, liborCurve, model)
    testCases.print("EUROPEAN BK REC VALUE:", valueRec)

    payRec = valuePay - valueRec
    testCases.print("PAY MINUS RECEIVER :", payRec)

    testCases.banner(
        "======= 20% VOLATILITY EUROPEAN SWAPTION BK MODEL ========")

    # Used BK with constant short-rate volatility
    sigma = 0.20
    a = 0.01
    model = FinModelRatesBK(sigma, a, numTimeSteps)

    testCases.banner("BK MODEL SWAPTION CLASS EUROPEAN EXERCISE")

    valuePay = europeanSwaptionPay.value(valuationDate, liborCurve, model)
    testCases.print("EUROPEAN BK PAY VALUE:", valuePay)

    valueRec = europeanSwaptionRec.value(valuationDate, liborCurve, model)
    testCases.print("EUROPEAN BK REC VALUE:", valueRec)

    payRec = valuePay - valueRec
    testCases.print("PAY MINUS RECEIVER :", payRec)

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

    # Now we create the Bermudan swaptions but only allow European exercise
    fixedLegType = FinSwapTypes.PAY
    exerciseType = FinExerciseTypes.EUROPEAN

    bermudanSwaptionPay = FinIborBermudanSwaption(settlementDate, exerciseDate,
                                                  swapMaturityDate,
                                                  fixedLegType, exerciseType,
                                                  swapFixedCoupon,
                                                  swapFixedFrequencyType,
                                                  swapFixedDayCountType)

    fixedLegType = FinSwapTypes.RECEIVE
    exerciseType = FinExerciseTypes.EUROPEAN

    bermudanSwaptionRec = FinIborBermudanSwaption(settlementDate, exerciseDate,
                                                  swapMaturityDate,
                                                  fixedLegType, exerciseType,
                                                  swapFixedCoupon,
                                                  swapFixedFrequencyType,
                                                  swapFixedDayCountType)

    testCases.banner(
        "======= 0% VOLATILITY BERMUDAN SWAPTION EUROPEAN EXERCISE BK MODEL ========"
    )

    # Used BK with constant short-rate volatility
    sigma = 0.000001
    a = 0.01
    model = FinModelRatesBK(sigma, a, numTimeSteps)

    testCases.banner("BK MODEL BERMUDAN SWAPTION CLASS EUROPEAN EXERCISE")
    valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN BK PAY VALUE:", valuePay)

    valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN BK REC VALUE:", valueRec)

    payRec = valuePay - valueRec
    testCases.print("PAY MINUS RECEIVER :", payRec)

    testCases.banner(
        "======= 20% VOLATILITY BERMUDAN SWAPTION EUROPEAN EXERCISE BK MODEL ========"
    )

    # Used BK with constant short-rate volatility
    sigma = 0.2
    a = 0.01
    model = FinModelRatesBK(sigma, a, numTimeSteps)

    testCases.banner("BK MODEL BERMUDAN SWAPTION CLASS EUROPEAN EXERCISE")
    valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN BK PAY VALUE:", valuePay)

    valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN BK REC VALUE:", valueRec)

    payRec = valuePay - valueRec
    testCases.print("PAY MINUS RECEIVER :", payRec)

    ###########################################################################
    # Now we create the Bermudan swaptions but allow Bermudan exercise
    ###########################################################################

    fixedLegType = FinSwapTypes.PAY
    exerciseType = FinExerciseTypes.BERMUDAN

    bermudanSwaptionPay = FinIborBermudanSwaption(settlementDate, exerciseDate,
                                                  swapMaturityDate,
                                                  fixedLegType, exerciseType,
                                                  swapFixedCoupon,
                                                  swapFixedFrequencyType,
                                                  swapFixedDayCountType)

    fixedLegType = FinSwapTypes.RECEIVE
    exerciseType = FinExerciseTypes.BERMUDAN

    bermudanSwaptionRec = FinIborBermudanSwaption(settlementDate, exerciseDate,
                                                  swapMaturityDate,
                                                  fixedLegType, exerciseType,
                                                  swapFixedCoupon,
                                                  swapFixedFrequencyType,
                                                  swapFixedDayCountType)

    testCases.banner(
        "======= ZERO VOLATILITY BERMUDAN SWAPTION BERMUDAN EXERCISE BK MODEL ========"
    )

    # Used BK with constant short-rate volatility
    sigma = 0.000001
    a = 0.01
    model = FinModelRatesBK(sigma, a, numTimeSteps)

    testCases.banner("BK MODEL BERMUDAN SWAPTION CLASS BERMUDAN EXERCISE")
    valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN BK PAY VALUE:", valuePay)

    valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN BK REC VALUE:", valueRec)

    payRec = valuePay - valueRec
    testCases.print("PAY MINUS RECEIVER :", payRec)

    testCases.banner(
        "======= 20% VOLATILITY BERMUDAN SWAPTION BERMUDAN EXERCISE BK MODEL ========"
    )

    # Used BK with constant short-rate volatility
    sigma = 0.20
    a = 0.01
    model = FinModelRatesBK(sigma, a, numTimeSteps)

    testCases.banner("BK MODEL BERMUDAN SWAPTION CLASS BERMUDAN EXERCISE")
    valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN BK PAY VALUE:", valuePay)

    valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN BK REC VALUE:", valueRec)

    payRec = valuePay - valueRec
    testCases.print("PAY MINUS RECEIVER :", payRec)

    ###########################################################################
    ###########################################################################
    ###########################################################################
    # BDT MODEL
    ###########################################################################
    ###########################################################################
    ###########################################################################

    testCases.banner("=======================================================")
    testCases.banner("=======================================================")
    testCases.banner("======================= BDT MODEL =====================")
    testCases.banner("=======================================================")
    testCases.banner("=======================================================")

    testCases.banner("====== 0% VOLATILITY EUROPEAN SWAPTION BDT MODEL ======")

    # Used BK with constant short-rate volatility
    sigma = 0.00001
    numTimeSteps = 200
    model = FinModelRatesBDT(sigma, numTimeSteps)

    valuePay = europeanSwaptionPay.value(valuationDate, liborCurve, model)
    testCases.print("EUROPEAN BDT PAY VALUE:", valuePay)

    valueRec = europeanSwaptionRec.value(valuationDate, liborCurve, model)
    testCases.print("EUROPEAN BDT REC VALUE:", valueRec)

    payRec = valuePay - valueRec
    testCases.print("PAY MINUS RECEIVER :", payRec)

    testCases.banner("===== 20% VOLATILITY EUROPEAN SWAPTION BDT MODEL ======")

    # Used BK with constant short-rate volatility
    sigma = 0.20
    a = 0.01
    model = FinModelRatesBDT(sigma, numTimeSteps)

    testCases.banner("BDT MODEL SWAPTION CLASS EUROPEAN EXERCISE")

    valuePay = europeanSwaptionPay.value(valuationDate, liborCurve, model)
    testCases.print("EUROPEAN BDT PAY VALUE:", valuePay)

    valueRec = europeanSwaptionRec.value(valuationDate, liborCurve, model)
    testCases.print("EUROPEAN BDT REC VALUE:", valueRec)

    payRec = valuePay - valueRec
    testCases.print("PAY MINUS RECEIVER :", payRec)

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

    # Now we create the Bermudan swaptions but only allow European exercise
    fixedLegType = FinSwapTypes.PAY
    exerciseType = FinExerciseTypes.EUROPEAN

    bermudanSwaptionPay = FinIborBermudanSwaption(settlementDate, exerciseDate,
                                                  swapMaturityDate,
                                                  fixedLegType, exerciseType,
                                                  swapFixedCoupon,
                                                  swapFixedFrequencyType,
                                                  swapFixedDayCountType)

    fixedLegType = FinSwapTypes.RECEIVE
    bermudanSwaptionRec = FinIborBermudanSwaption(settlementDate, exerciseDate,
                                                  swapMaturityDate,
                                                  fixedLegType, exerciseType,
                                                  swapFixedCoupon,
                                                  swapFixedFrequencyType,
                                                  swapFixedDayCountType)

    testCases.banner(
        "======= 0% VOLATILITY BERMUDAN SWAPTION EUROPEAN EXERCISE BDT MODEL ========"
    )

    # Used BK with constant short-rate volatility
    sigma = 0.000001
    model = FinModelRatesBDT(sigma, numTimeSteps)

    testCases.banner("BK MODEL BERMUDAN SWAPTION CLASS EUROPEAN EXERCISE")
    valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN BDT PAY VALUE:", valuePay)

    valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN BDT REC VALUE:", valueRec)

    payRec = valuePay - valueRec
    testCases.print("PAY MINUS RECEIVER :", payRec)

    testCases.banner(
        "======= 20% VOLATILITY BERMUDAN SWAPTION EUROPEAN EXERCISE BDT MODEL ========"
    )

    # Used BK with constant short-rate volatility
    sigma = 0.2
    model = FinModelRatesBDT(sigma, numTimeSteps)

    testCases.banner("BDT MODEL BERMUDAN SWAPTION CLASS EUROPEAN EXERCISE")
    valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN BDT PAY VALUE:", valuePay)

    valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN BDT REC VALUE:", valueRec)

    payRec = valuePay - valueRec
    testCases.print("PAY MINUS RECEIVER :", payRec)

    ###########################################################################
    # Now we create the Bermudan swaptions but allow Bermudan exercise
    ###########################################################################

    fixedLegType = FinSwapTypes.PAY
    exerciseType = FinExerciseTypes.BERMUDAN

    bermudanSwaptionPay = FinIborBermudanSwaption(settlementDate, exerciseDate,
                                                  swapMaturityDate,
                                                  fixedLegType, exerciseType,
                                                  swapFixedCoupon,
                                                  swapFixedFrequencyType,
                                                  swapFixedDayCountType)

    fixedLegType = FinSwapTypes.RECEIVE
    bermudanSwaptionRec = FinIborBermudanSwaption(settlementDate, exerciseDate,
                                                  swapMaturityDate,
                                                  fixedLegType, exerciseType,
                                                  swapFixedCoupon,
                                                  swapFixedFrequencyType,
                                                  swapFixedDayCountType)

    testCases.banner(
        "======= ZERO VOLATILITY BERMUDAN SWAPTION BERMUDAN EXERCISE BDT MODEL ========"
    )

    # Used BK with constant short-rate volatility
    sigma = 0.000001
    a = 0.01
    model = FinModelRatesBDT(sigma, numTimeSteps)

    testCases.banner("BK MODEL BERMUDAN SWAPTION CLASS BERMUDAN EXERCISE")
    valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN BDT PAY VALUE:", valuePay)

    valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN BDT REC VALUE:", valueRec)

    payRec = valuePay - valueRec
    testCases.print("PAY MINUS RECEIVER :", payRec)

    testCases.banner(
        "======= 20% VOLATILITY BERMUDAN SWAPTION BERMUDAN EXERCISE BDT MODEL ========"
    )

    # Used BK with constant short-rate volatility
    sigma = 0.20
    a = 0.01
    model = FinModelRatesBDT(sigma, numTimeSteps)

    #    print("BDT MODEL BERMUDAN SWAPTION CLASS BERMUDAN EXERCISE")
    valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN BDT PAY VALUE:", valuePay)

    valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN BDT REC VALUE:", valueRec)

    payRec = valuePay - valueRec
    testCases.print("PAY MINUS RECEIVER :", payRec)

    ###########################################################################
    ###########################################################################
    ###########################################################################
    # BDT MODEL
    ###########################################################################
    ###########################################################################
    ###########################################################################

    testCases.banner("=======================================================")
    testCases.banner("=======================================================")
    testCases.banner("======================= HW MODEL ======================")
    testCases.banner("=======================================================")
    testCases.banner("=======================================================")

    testCases.banner("====== 0% VOLATILITY EUROPEAN SWAPTION HW MODEL ======")

    sigma = 0.0000001
    a = 0.1
    numTimeSteps = 200
    model = FinModelRatesHW(sigma, a, numTimeSteps)

    valuePay = europeanSwaptionPay.value(valuationDate, liborCurve, model)
    testCases.print("EUROPEAN HW PAY VALUE:", valuePay)

    valueRec = europeanSwaptionRec.value(valuationDate, liborCurve, model)
    testCases.print("EUROPEAN HW REC VALUE:", valueRec)

    payRec = valuePay - valueRec
    testCases.print("PAY MINUS RECEIVER :", payRec)

    testCases.banner("===== 20% VOLATILITY EUROPEAN SWAPTION BDT MODEL ======")

    # Used BK with constant short-rate volatility
    sigma = 0.01
    a = 0.01
    model = FinModelRatesHW(sigma, a, numTimeSteps)

    testCases.banner("HW MODEL SWAPTION CLASS EUROPEAN EXERCISE")

    valuePay = europeanSwaptionPay.value(valuationDate, liborCurve, model)
    testCases.print("EUROPEAN HW PAY VALUE:", valuePay)

    valueRec = europeanSwaptionRec.value(valuationDate, liborCurve, model)
    testCases.print("EUROPEAN HW REC VALUE:", valueRec)

    payRec = valuePay - valueRec
    testCases.print("PAY MINUS RECEIVER :", payRec)

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

    # Now we create the Bermudan swaptions but only allow European exercise
    fixedLegType = FinSwapTypes.PAY
    exerciseType = FinExerciseTypes.EUROPEAN

    bermudanSwaptionPay = FinIborBermudanSwaption(settlementDate, exerciseDate,
                                                  swapMaturityDate,
                                                  fixedLegType, exerciseType,
                                                  swapFixedCoupon,
                                                  swapFixedFrequencyType,
                                                  swapFixedDayCountType)

    fixedLegType = FinSwapTypes.RECEIVE
    bermudanSwaptionRec = FinIborBermudanSwaption(settlementDate, exerciseDate,
                                                  swapMaturityDate,
                                                  fixedLegType, exerciseType,
                                                  swapFixedCoupon,
                                                  swapFixedFrequencyType,
                                                  swapFixedDayCountType)

    testCases.banner(
        "======= 0% VOLATILITY BERMUDAN SWAPTION EUROPEAN EXERCISE HW MODEL ========"
    )

    sigma = 0.000001
    model = FinModelRatesHW(sigma, a, numTimeSteps)

    testCases.banner("BK MODEL BERMUDAN SWAPTION CLASS EUROPEAN EXERCISE")
    valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN BDT PAY VALUE:", valuePay)

    valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN BDT REC VALUE:", valueRec)

    payRec = valuePay - valueRec
    testCases.print("PAY MINUS RECEIVER :", payRec)

    testCases.banner(
        "======= 100bp VOLATILITY BERMUDAN SWAPTION EUROPEAN EXERCISE HW MODEL ========"
    )

    # Used BK with constant short-rate volatility
    sigma = 0.01
    model = FinModelRatesHW(sigma, a, numTimeSteps)

    testCases.banner("BDT MODEL BERMUDAN SWAPTION CLASS EUROPEAN EXERCISE")
    valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN BDT PAY VALUE:", valuePay)

    valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN BDT REC VALUE:", valueRec)

    payRec = valuePay - valueRec
    testCases.print("PAY MINUS RECEIVER :", payRec)

    ###########################################################################
    # Now we create the Bermudan swaptions but allow Bermudan exercise
    ###########################################################################

    fixedLegType = FinSwapTypes.PAY
    exerciseType = FinExerciseTypes.BERMUDAN

    bermudanSwaptionPay = FinIborBermudanSwaption(settlementDate, exerciseDate,
                                                  swapMaturityDate,
                                                  fixedLegType, exerciseType,
                                                  swapFixedCoupon,
                                                  swapFixedFrequencyType,
                                                  swapFixedDayCountType)

    fixedLegType = FinSwapTypes.RECEIVE
    bermudanSwaptionRec = FinIborBermudanSwaption(settlementDate, exerciseDate,
                                                  swapMaturityDate,
                                                  fixedLegType, exerciseType,
                                                  swapFixedCoupon,
                                                  swapFixedFrequencyType,
                                                  swapFixedDayCountType)

    testCases.banner(
        "======= ZERO VOLATILITY BERMUDAN SWAPTION BERMUDAN EXERCISE HW MODEL ========"
    )

    # Used BK with constant short-rate volatility
    sigma = 0.000001
    a = 0.01
    model = FinModelRatesHW(sigma, a, numTimeSteps)

    testCases.banner("HW MODEL BERMUDAN SWAPTION CLASS BERMUDAN EXERCISE")
    valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN HW PAY VALUE:", valuePay)

    valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN HW REC VALUE:", valueRec)

    payRec = valuePay - valueRec
    testCases.print("PAY MINUS RECEIVER :", payRec)

    testCases.banner(
        "======= 100bps VOLATILITY BERMUDAN SWAPTION BERMUDAN EXERCISE HW MODEL ========"
    )

    # Used BK with constant short-rate volatility
    sigma = 0.01
    a = 0.01
    model = FinModelRatesHW(sigma, a, numTimeSteps)

    testCases.banner("HW MODEL BERMUDAN SWAPTION CLASS BERMUDAN EXERCISE")
    valuePay = bermudanSwaptionPay.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN HW PAY VALUE:", valuePay)

    valueRec = bermudanSwaptionRec.value(valuationDate, liborCurve, model)
    testCases.print("BERMUDAN HW REC VALUE:", valueRec)

    payRec = valuePay - valueRec
    testCases.print("PAY MINUS RECEIVER :", payRec)