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.

  • $\begingroup$ Do you really care about computational time for generation one-off graphs? $\endgroup$ Commented Aug 3, 2020 at 18:18
  • $\begingroup$ I am doing it for a large number of graphs $\endgroup$
    – roller
    Commented Aug 3, 2020 at 18:23

1 Answer 1


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)

prices = []
for n in range(50,200):
plt.plot(range(50,200), prices);

enter image description here

  • $\begingroup$ 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. $\endgroup$
    – roller
    Commented Aug 3, 2020 at 21:54
  • $\begingroup$ 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? $\endgroup$
    – Lisa Ann
    Commented Aug 3, 2020 at 22:01
  • 1
    $\begingroup$ Are you generating graphs for the computer to look at? This seems convoluted to me. $\endgroup$
    – Bob Jansen
    Commented Aug 4, 2020 at 6:21
  • $\begingroup$ 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...) $\endgroup$
    – StackG
    Commented Aug 4, 2020 at 14:27
  • $\begingroup$ 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? $\endgroup$ Commented Aug 4, 2020 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.