I want to retrieve a Black Vol from a swaption price calculated by the Quantlib BachelierSwaptionEngine. It looks like this can be done in Quantlib via an optimizer (such as the newton method) or direct via the impliedVolatility method. I'm unable to use the Quantlib optimizer or the impliedVolatility method within Quantlib Python.
The code below shows how I calculate the swaption price in Quantlib. From there I need to retrieve a Black vol based on the swaption price calculated in the code
import Quantlib as ql
from scipy import optimize
calc_date = ql.Date(29,3,2019)
rate = ql.SimpleQuote(0.01)
rate_handle = ql.QuoteHandle(rate)
dc = ql.Actual365Fixed()
spot_curve = ql.FlatForward(calc_date, rate_handle, dc)
start = 10
length = 10
start_date = ql.TARGET().advance(calc_date, start, ql.Years)
maturity_date = start_date + ql.Period(length, ql.Years)
fixed_schedule = ql.Schedule(start_date, maturity_date,
ql.Period(1, ql.Years), ql.TARGET(), ql.Unadjusted,
ql.Unadjusted,ql.DateGeneration.Forward, False)
floating_schedule = ql.Schedule(start_date, maturity_date,
ql.Period(6, ql.Months), ql.TARGET(),
ql.ModifiedFollowing, ql.ModifiedFollowing,
ql.DateGeneration.Forward, True)
index6m = ql.Euribor6M(ql.YieldTermStructureHandle(spot_curve))
rate = 1.45 / 100
swap = ql.VanillaSwap(ql.VanillaSwap.Receiver, 10000000,
fixed_schedule, rate, ql.Thirty360(ql.Thirty360.BondBasis),
floating_schedule, index6m, 0.0, index6m.dayCounter())
swap.setPricingEngine(ql.DiscountingSwapEngine(
ql.YieldTermStructureHandle(spot_curve)))
swaption_normal_model = ql.Swaption(swap,
ql.EuropeanExercise(swap.startDate()))
normal_vol = ql.SimpleQuote(0.005266)
swaption_normal_model.setPricingEngine
(ql.BachelierSwaptionEngine(ql.YieldTermStructureHandle(spot_curve),
ql.QuoteHandle(normal_vol)))
swaption_normal_model_value = swaption_normal_model.NPV()