Back to snippets

quantlib_european_call_option_black_scholes_pricing.py

python

This quickstart example demonstrates how to price a European Call option using

Agent Votes
1
0
100% positive
quantlib_european_call_option_black_scholes_pricing.py
1import QuantLib as ql
2
3# Set the evaluation date
4today = ql.Date(15, 6, 2024)
5ql.Settings.instance().evaluationDate = today
6
7# Define the option: European Call, Strike 100, expiring in 1 year
8payoff = ql.PlainVanillaPayoff(ql.Option.Call, 100.0)
9exercise = ql.EuropeanExercise(ql.Date(15, 6, 2025))
10european_option = ql.EuropeanOption(payoff, exercise)
11
12# Market data
13spot_handle = ql.QuoteHandle(ql.SimpleQuote(100.0))
14risk_free_rate = ql.YieldTermStructureHandle(ql.FlatForward(today, 0.05, ql.Actual365Fixed()))
15volatility = ql.BlackVolTermStructureHandle(ql.BlackConstantVol(today, ql.TARGET(), 0.20, ql.Actual365Fixed()))
16
17# Stochastic process and pricing engine
18bsm_process = ql.BlackScholesProcess(spot_handle, risk_free_rate, volatility)
19engine = ql.AnalyticEuropeanEngine(bsm_process)
20
21# Calculate NPV
22european_option.setPricingEngine(engine)
23print(f"Theoretical Price: {european_option.NPV():.4f}")
24print(f"Delta: {european_option.delta():.4f}")
25print(f"Gamma: {european_option.gamma():.4f}")
26print(f"Theta: {european_option.thetaPerDay():.4f}")