QuantLib XL implied volatility

Asked by At

I am using QuantLib to price various equity options. I am using both Python and QuantLib XL. In Python, it is easy to construct an option, create a Black Scholes process and then calculate either a price or calculate implied volatility from a price.

Simply:

from QuantLib import *

exercise = EuropeanExercise(Date(3,August,2019))
payoff = PlainVanillaPayoff(Option.Call, 105.0)
option = EuropeanOption(payoff,exercise)


#spot
S = QuoteHandle(SimpleQuote(100.0))
#risk free
r = YieldTermStructureHandle(FlatForward(0, TARGET(), 0.03, 
                              Actual360()))
#dividend
q = YieldTermStructureHandle(FlatForward(0, TARGET(), 0.01, 
                              Actual360()))
#vol handle
sigma = BlackVolTermStructureHandle(BlackConstantVol(0, 
                                     TARGET(), 0.20, 
                                     Actual360()))
#BS process    
process = BlackScholesMertonProcess(S,q,r,sigma)

#Now calculate implied volatility
option.impliedVolatility(25.0, process)

#Alternatively, 
engine = AnalyticEuropeanEngine(process)
option.setPricingEngine(engine)
option.NPV()

This can be done in XL in a similar way using =qlGeneralizedBlackScholesProcess(). Pricing and Greeks are straightforward using =qlInstrumentNPV() and qlVega(), etc. However, it isn't clear how you calculate implied volatility from price. What is the best way to do this?

0 Answers