Exemplo n.º 1
0
def test_FinCapVolCurve():

    # Reproduces example in Table 32.1 of Hull Book
    valuationDate = FinDate(1, 1, 2020)

    capVolDates = []
    capletVolTenor = "1Y"
    numPeriods = 10
    capletDt = valuationDate

    capVolDates.append(valuationDate)

    for i in range(0, numPeriods):
        capletDt = capletDt.addTenor(capletVolTenor)
        capVolDates.append(capletDt)

    capVolatilities = [
        0.0, 15.50, 18.25, 17.91, 17.74, 17.27, 16.79, 16.30, 16.01, 15.76,
        15.54
    ]
    capVolatilities = np.array(capVolatilities) / 100.0

    dayCountType = FinDayCountTypes.ACT_ACT_ISDA
    volCurve = FinLiborCapVolCurve(valuationDate, capVolDates, capVolatilities,
                                   dayCountType)

    testCases.header("DATE", "CAPVOL", "CAPLETVOL")
    for dt in capVolDates:
        capFloorVol = volCurve.capVol(dt)
        capFloorLetVol = volCurve.capletVol(dt)
        testCases.print("%s" % dt, "%7.3f" % (capFloorVol * 100.0),
                        "%7.2f" % (capFloorLetVol * 100.0))
Exemplo n.º 2
0
def test_FinLiborCapFloorVolCurve():
    ''' Aim here is to price cap and caplets using cap and caplet vols and to
    demonstrate they are the same - NOT SURE THAT HULLS BOOKS FORMULA WORKS FOR
    OPTIONS. '''

    todayDate = FinDate(20, 6, 2019)
    valuationDate = todayDate
    maturityDate = valuationDate.addTenor("3Y")
    dayCountType = FinDayCountTypes.THIRTY_E_360
    frequency = FinFrequencyTypes.ANNUAL

    k = 0.04
    capFloorType = FinLiborCapFloorTypes.CAP
    capFloor = FinLiborCapFloor(valuationDate, maturityDate, capFloorType, k,
                                None, frequency, dayCountType)

    capVolDates = FinSchedule(valuationDate, valuationDate.addTenor("10Y"),
                              frequency)._generate()

    flatRate = 0.04
    liborCurve = FinDiscountCurveFlat(valuationDate, flatRate, frequency,
                                      dayCountType)

    flat = False
    if flat is True:
        capVolatilities = [20.0] * 11
        capVolatilities[0] = 0.0
    else:
        capVolatilities = [
            0.00, 15.50, 18.25, 17.91, 17.74, 17.27, 16.79, 16.30, 16.01,
            15.76, 15.54
        ]

    capVolatilities = np.array(capVolatilities) / 100.0
    capVolatilities[0] = 0.0

    volCurve = FinLiborCapVolCurve(valuationDate, capVolDates, capVolatilities,
                                   dayCountType)

    print(volCurve._capletGammas)

    # Value cap using a single flat cap volatility
    tcap = (maturityDate - valuationDate) / gDaysInYear
    vol = volCurve.capVol(maturityDate)
    model = FinModelBlack(vol)
    valueCap = capFloor.value(valuationDate, liborCurve, model)
    print("CAP T", tcap, "VOL:", vol, "VALUE OF CAP:", valueCap)

    # Value cap by breaking it down into caplets using caplet vols
    vCaplets = 0.0
    capletStartDate = capFloor._capFloorLetDates[1]
    testCases.header("START", "END", "VOL", "VALUE")

    for capletEndDate in capFloor._capFloorLetDates[2:]:
        vol = volCurve.capletVol(capletEndDate)
        modelCaplet = FinModelBlack(vol)
        vCaplet = capFloor.valueCapletFloorLet(valuationDate, capletStartDate,
                                               capletEndDate, liborCurve,
                                               modelCaplet)

        vCaplets += vCaplet
        testCases.print("%12s" % capletStartDate, "%s" % capletEndDate,
                        "%9.5f" % (vol * 100.0), "%9.5f" % vCaplet)

        capletStartDate = capletEndDate

    testCases.header("LABEL", "VALUE")
    testCases.print("CAPLETS->CAP: ", vCaplets)