A Python implementation of the Black-Scholes European options pricing model, Monte Carlo simulation, Greeks calculation, implied volatility extraction, and delta hedging simulation.
Built as a learning project to understand the mathematical foundations of quantitative finance.
black-scholes-mc/
notebooks/
01_black_scholes.ipynb # BS theory, implementation, sensitivity analysis
02_monte_carlo.ipynb # GBM simulation, convergence analysis, path visualization
03_greeks_and_implied_vol.ipynb # Greeks curves, implied vol extraction
04_delta_hedging.ipynb # Hedging simulation, PnL distribution, frequency analysis
src/
black_scholes.py # Closed-form BS pricer for calls and puts
monte_carlo.py # Monte Carlo simulation using GBM
greeks.py # Delta, Gamma, Vega, Theta, Rho
implied_vol.py # Implied volatility extraction via Brent's method
visualize.py # GBM price path visualization
visualize_greeks.py # Greeks curves across stock prices
delta_hedge.py # Dynamic delta hedging simulation
plots/
price_paths.png
greeks.png
vol_smile.png
delta_hedge.png
requirements.txt
The Black-Scholes model prices a call option under the assumption that stock prices follow Geometric Brownian Motion:
where
The closed-form call price is:
The formula has a clean interpretation: it is the expected stock contribution to the payoff minus the discounted expected cost of exercising, each weighted by their relevant probability.
-
$N(d_2)$ - risk-neutral probability the option expires in the money -
$N(d_1)$ - probability weighted by the size of the stock's contribution to the payoff
Put prices follow from put-call parity, which holds exactly by no-arbitrage:
Instead of the closed-form solution, we simulate
The MC price converges to the BS price as
Sensitivities of the option price to each input:
| Greek | Measures | Formula |
|---|---|---|
| Delta | Sensitivity to stock price | |
| Gamma | Rate of change of Delta | |
| Vega | Sensitivity to volatility | |
| Theta | Time decay per day | See src/greeks.py |
| Rho | Sensitivity to interest rates |
where
Delta follows an S-curve from 0 to 1 as the stock price rises through the strike. Gamma and Vega both peak at the money, where the option is most sensitive to changes in the underlying.
Volatility is the only unobservable input to Black-Scholes. Given a market price, we invert the formula numerically using Brent's method to extract the implied volatility, the market's collective estimate of future uncertainty.
A delta hedge eliminates directional exposure to the stock. If you sell a call with Delta 0.50, you buy 0.50 shares per option sold. As the stock moves, Delta changes (Gamma), so the hedge must be rebalanced periodically.
With weekly rebalancing (52 steps) over 200 simulated paths, the mean hedging PnL is approximately $0.01 with a standard deviation of ~$1.10, demonstrating that discrete delta hedging closely replicates the theoretical zero-cost continuous hedge of Black-Scholes.
git clone https://github.com/AgustinMagarinos/black-scholes-mc.git
cd black-scholes-mc
pip install -r requirements.txt# Run the Black-Scholes pricer
python src/black_scholes.py
# Run Monte Carlo simulation
python src/monte_carlo.py
# Calculate Greeks
python src/greeks.py
# Extract implied volatility
python src/implied_vol.py
# Generate visualizations
python src/visualize.py
python src/visualize_greeks.py
python src/delta_hedge.py- Log-normal stock price modeling under risk-neutral measure
- No-arbitrage pricing and put-call parity
- Monte Carlo convergence as a function of simulation count
- Greeks as partial derivatives of the pricing formula
- Volatility skew as evidence of Black-Scholes model limitations
- Discrete delta hedging error as a function of rebalancing frequency
- Black, F. & Scholes, M. (1973). The Pricing of Options and Corporate Liabilities
- Hull, J. (2022). Options, Futures, and Other Derivatives
- Shreve, S. (2004). Stochastic Calculus for Finance