[Python] How to get implied volatility of a cap Quantlib Python

Discussão em 'Python' iniciado por Stack, Março 11, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following lists given:

    - dates_3M starting at ql.Date(25,11,2019)
    - rates_3M
    - dates_ois starting at ql.Date(25,11,2019)
    - rates_ois


    And this is my code:

    ref_date = ql.Date(25,11,2019)
    ql.Settings.instance().evaluationDate = reference_date

    calendar = ql.TARGET()
    curve_ois = ql.ZeroCurve(dates_ois, rates_ois, ql.Actual360(), calendar, ql.Linear(), ql.Compounded, ql.Annual)
    curve_ois_handle = ql.YieldTermStructureHandle(curve_ois)
    curve_3M = ql.ZeroCurve(dates_3M, rates_3M, ql.Actual360(), calendar, ql.Linear(), ql.Compounded, ql.Annual)
    curve_3M_handle = ql.YieldTermStructureHandle(curve_3M)

    startDate = ref_date + 2
    endDate = calendar.advance(startdate, ql.Period('72M')
    schedule = ql.Schedule(startDate, endDate, ql.Period(ql.Quarterly), calendar, ql.ModifiedFollowing, ql.ModifiedFollowing, ql.DateGeneration.Forward, False)
    nom = 1000000
    capRate = 0.03

    cap = ql.Cap(ql.IborLeg([nominal], schedule, ql.Euribor3M(curve_3M_handle)), [capRate])
    vola = ql.QuoteHandle(ql.SimpleQuote(0.003064))
    engine = ql.BachelierCapFloorEngine(curve_ois_handle, vola)
    cap.setPricingEngine(engine)
    cap_npv = cap.NPV()


    Now I would like to compute the implied vola by using

    cap.impliedVolatility(cap_npv, curve_ois_handle, vola)


    where the last argument is supposed to be the initial guess. help(cap) tells me that this should work, however I am getting the error "Wrong number or type of arguments for overloaded function 'CapFloor_impliedVolatility'". It seems the first argument has to be a real (which is correct in my case), the second one a YieldTermStructure Handle, which is also correct in my case and the 3rd argument should be of type Volatility. However, that is not a type. All the other arguments seem to be optional.

    Continue reading...

Compartilhe esta Página