Price a European Option - Quantlib Typing CST Test
Loading…
Price a European Option — Quantlib Code
Prices a European call option using Black-Scholes model.
spot = 100
strike = 100
maturity = ql.Date(1,12,2026)
vol = 0.2
risk_free = 0.01
calendar = ql.TARGET()
day_count = ql.Actual360()
option_type = ql.Option.Call
payoff = ql.PlainVanillaPayoff(option_type, strike)
exercise = ql.EuropeanExercise(maturity)
option = ql.VanillaOption(payoff, exercise)
spot_handle = ql.QuoteHandle(ql.SimpleQuote(spot))
dividend_yield = ql.YieldTermStructureHandle(ql.FlatForward(date, 0.0, day_count))
risk_free_rate = ql.YieldTermStructureHandle(ql.FlatForward(date, risk_free, day_count))
volatility = ql.BlackVolTermStructureHandle(ql.BlackConstantVol(date, calendar, vol, day_count))
process = ql.BlackScholesMertonProcess(spot_handle, dividend_yield, risk_free_rate, volatility)
engine = ql.AnalyticEuropeanEngine(process)
option.setPricingEngine(engine)
npv = option.NPV()Quantlib Language Guide
QuantLib is an open-source library for quantitative finance, providing tools for modeling, trading, and risk management in C++ with bindings for Python, R, and other languages.
Primary Use Cases
- ▸Pricing complex derivatives and fixed-income products
- ▸Risk management and sensitivity analysis
- ▸Portfolio modeling and scenario analysis
- ▸Developing custom quantitative finance models
- ▸Backtesting trading strategies and models
Notable Features
- ▸Wide range of instruments: bonds, options, swaps, FX, equity derivatives
- ▸Term structures and yield curves modeling
- ▸Stochastic processes for financial modeling
- ▸Monte Carlo, finite difference, and tree-based methods
- ▸Date and calendar management for financial schedules
Origin & Creator
Developed by a community of quantitative finance practitioners led by Luigi Ballabio, first released in 2000 to provide an open-source alternative to commercial quantitative libraries.
Industrial Note
Essential for quantitative finance professionals, financial engineers, and developers needing accurate, efficient, and extensible tools for pricing, risk, and derivatives modeling.