# Option price quantlib

I am lookin at https://github.com/lballabio/QuantLib/blob/master/Examples/EquityOption/EquityOption.cpp . I want plot a graph of the option price for different underlying prices. Other than changing the Real underlying = 36; for each of the different underlying prices I want to calculate , is there any way to decrease the time this calculation would take. I want to plot a graph of the option price for different underlyin prices.

• Do you really care about computational time for generation one-off graphs? Aug 3 '20 at 18:18
• I am doing it for a large number of graphs Aug 3 '20 at 18:23

Doing it in python is fast enough so not sure why it would take long in c++.

import QuantLib as ql
import matplotlib.pyplot as plt

today = ql.Date().todaysDate()
strike = 100.0
maturity= ql.Date(15,6,2021)
option_type = ql.Option.Call
payoff = ql.PlainVanillaPayoff(option_type, strike)

europeanExercise = ql.EuropeanExercise(maturity)
europeanOption = ql.VanillaOption(payoff, europeanExercise)

spot = ql.SimpleQuote(100)
riskFreeTS = ql.YieldTermStructureHandle(ql.FlatForward(today, 0.01, ql.Actual365Fixed()))
volTS = ql.BlackVolTermStructureHandle(ql.BlackConstantVol(today, ql.NullCalendar(), 0.2, ql.Actual365Fixed()))
process = ql.BlackScholesProcess(ql.QuoteHandle(spot), riskFreeTS, volTS)
engine = ql.AnalyticEuropeanEngine(process)
europeanOption.setPricingEngine(engine)
europeanOption.NPV()

prices = []
for n in range(50,200):
spot.setValue(n)
prices.append(europeanOption.NPV())

plt.plot(range(50,200), prices);


• I have different options which I would like to plot so for doing onr or two it is okay but when I have to do lots of these graphs it becomes an issue. The graphs are not being looked at by humans . It is for a model. Aug 3 '20 at 21:54
• In my opinion, it is matplotlib that takes most of the time, not the C++ core. How long does it take if you drop the plot? Aug 3 '20 at 22:01
• Are you generating graphs for the computer to look at? This seems convoluted to me. Aug 4 '20 at 6:21
• I'm guessing he wants to feed them in them into a CNN and have it 'learn' vanilla options pricing from price graphs (I guess it does make sense to do this with simulated graphs before using real market graphs...) Aug 4 '20 at 14:27
• Vanilla option pricing can be learned by a pretty simple "vanilla" Neural Network. I any case, why have the network interpret a graph if you can feed it the data? Aug 4 '20 at 20:30