Back to snippets
quantlib_european_call_option_black_scholes_merton_pricing.py
pythonThis quickstart example demonstrates how to value a European call option using
Agent Votes
1
0
100% positive
quantlib_european_call_option_black_scholes_merton_pricing.py
1import QuantLib as ql
2
3# Set the evaluation date
4date = ql.Date(15, 6, 2024)
5ql.Settings.instance().evaluationDate = date
6
7# Parameters for the European Option
8option_type = ql.Option.Call
9strike_price = 100
10expiry_date = ql.Date(15, 6, 2025)
11spot_price = 100
12volatility = 0.20
13risk_free_rate = 0.01
14dividend_yield = 0.00
15
16# Setup the option
17payoff = ql.PlainVanillaPayoff(option_type, strike_price)
18exercise = ql.EuropeanExercise(expiry_date)
19european_option = ql.VanillaOption(payoff, exercise)
20
21# Market data setup
22spot_handle = ql.QuoteHandle(ql.SimpleQuote(spot_price))
23flat_ts = ql.YieldTermStructureHandle(
24 ql.FlatForward(date, risk_free_rate, ql.Actual365Fixed())
25)
26dividend_ts = ql.YieldTermStructureHandle(
27 ql.FlatForward(date, dividend_yield, ql.Actual365Fixed())
28)
29flat_vol_ts = ql.BlackVolTermStructureHandle(
30 ql.BlackConstantVol(date, ql.NullCalendar(), volatility, ql.Actual365Fixed())
31)
32
33# Black-Scholes process and pricing engine
34bsm_process = ql.BlackScholesMertonProcess(
35 spot_handle, dividend_ts, flat_ts, flat_vol_ts
36)
37engine = ql.AnalyticEuropeanEngine(bsm_process)
38european_option.setPricingEngine(engine)
39
40# Output the calculated Net Present Value (NPV)
41print(f"Option Value (NPV): {european_option.NPV():.4f}")