I am new to quantlib as well as option price modelling. I need to get premium from black scholes model and found this code in internet
import QuantLib as ql
S=1100
strike=[1000,1100,1110,1120]
v=0.2
ri=0.04
for K in strike:
today = ql.Date(20, 7, 2019)
ql.Settings.instance().evaluationDate = today
# The Instrument
option = ql.EuropeanOption( ql.PlainVanillaPayoff(ql.Option.Call, K),
ql.EuropeanExercise(ql.Date(25, 7, 2019)))
# The Market
u = ql.SimpleQuote(S) # set todays value of the underlying
r = ql.SimpleQuote(ri) # set risk-free rate
sigma = ql.SimpleQuote(v) # set volatility
riskFreeCurve = ql.FlatForward(0, ql.TARGET(), ql.QuoteHandle(r), ql.Actual360())
volatility = ql.BlackConstantVol(0, ql.TARGET(), ql.QuoteHandle(sigma), ql.Actual360())
# The Model
process = ql.BlackScholesProcess( ql.QuoteHandle(u),
ql.YieldTermStructureHandle(riskFreeCurve),
ql.BlackVolTermStructureHandle(volatility))
# The Pricing Engine
engine = ql.AnalyticEuropeanEngine(process)
# The Result
option.setPricingEngine(engine)
print(option.NPV())
With output
100.33327806116641
8.195213254652364
4.131971032227009
1.7912417047751839
But when I did a comparison study with an online Black Scholes calculator, I got differen result
100.55
10.57
6.29
3.43
What is wrong with my code? How to I properly model for premium in quantlib? Did quantlib implementblack76
model?