0
$\begingroup$

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.

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

1 Answer 1

0
$\begingroup$

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);

enter image description here

$\endgroup$
5
  • $\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
    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
    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
    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
    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$ Aug 4, 2020 at 20:30

Your Answer

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

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