選項
期權價格 quantlib
我正在查看https://github.com/lballabio/QuantLib/blob/master/Examples/EquityOption/EquityOption.cpp。我想繪製不同基礎價格的期權價格圖表。除了更改
Real underlying = 36;
我要計算的每個不同標的價格之外,還有什麼方法可以減少此計算所需的時間。我想繪製不同底層價格的期權價格圖表。
在 python 中執行它足夠快,所以不確定為什麼在 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);