|
From: Luigi B. <lui...@gm...> - 2019-06-05 15:51:18
|
I was about to suggest to use a root solver from scipy, but I see from Stack Overflow that you already did... Luigi On Sat, Jun 1, 2019 at 12:15 PM Robin Schreur <rob...@ho...> wrote: > Hi All, > > I have posted an question at stack exchange regarding retrieving the > implied swaption vol from a swaption price ( > https://stackoverflow.com/questions/56362943/retrieving-black-vol-from-quantlib-bachelierswaption-price). > Probably the mailinglist has more users who have an answer. > > My question: > > 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 > > 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) > > 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() > > > Many thanks, > > Robin > _______________________________________________ > QuantLib-users mailing list > Qua...@li... > https://lists.sourceforge.net/lists/listinfo/quantlib-users > |