Skip to content

About

Black-Scholes option pricing engine with Monte Carlo simulation and implied volatility surface, written in Python with a Streamlit ui

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Option Pricing Engine

A quantitative finance project implementing a full option pricing engine in Python, featuring Black-Scholes analytical pricing, Monte Carlo simulation with antithetic variance reduction, and an implied volatility surface, all wrapped in an interactive Streamlit dashboard.

Live Demo

Run locally with:

streamlit run app.py

Project Overview

This engine prices European options using two independent methods and compares their results:

  1. Black-Scholes — closed-form analytical solution with all five Greeks
  2. Monte Carlo — Geometric Brownian Motion simulation with antithetic variance reduction
  3. Implied Volatility — Newton-Raphson solver with Brent's method fallback, used to construct a full volatility surface

Dashboard Features

  • Pricing & Greeks tab — real-time BS price and Greeks (delta, gamma, vega, theta, rho) with interactive Greeks vs spot price chart
  • Monte Carlo tab — side-by-side BS vs MC vs antithetic pricing with 95% confidence intervals and convergence analysis chart
  • Vol Surface tab — interactive 3D implied volatility surface showing volatility smile and term structure, with color-coded table view
  • Price Surface tab — 3D option price surface and heatmap across spot prices and expiries

Mathematical Foundation

Black-Scholes Model

The stock price follows Geometric Brownian Motion:

$$dS = \mu S , dt + \sigma S , dW$$

The closed-form solution for a European call:

$$C = S \cdot N(d_1) - Ke^{-rT} \cdot N(d_2)$$

$$d_1 = \frac{\ln(S/K) + (r + \sigma^2/2)T}{\sigma\sqrt{T}}, \quad d_2 = d_1 - \sigma\sqrt{T}$$

Where:

  • S — current stock price
  • K — strike price
  • T — time to expiration (years)
  • r — risk-free interest rate
  • σ — volatility
  • N(·) — cumulative standard normal distribution

Monte Carlo Simulation

Simulates terminal stock prices using the GBM closed-form solution:

$$S_T = S_0 \cdot \exp\left[\left(r - \frac{\sigma^2}{2}\right)T + \sigma\sqrt{T} \cdot Z\right], \quad Z \sim N(0,1)$$

Option price estimated as the discounted average payoff across all simulations:

$$\hat{C} = e^{-rT} \cdot \frac{1}{N}\sum_{i=1}^{N} \max(S_T^{(i)} - K, 0)$$

Variance reduction via antithetic variates: each

Greeks

Greek Formula Interpretation
Delta (Δ) ∂V/∂S = N(d₁) Price change per $1 move in stock. Hedge ratio.
Gamma (Γ) ∂²V/∂S² = φ(d₁)/(Sσ√T) Rate of change of delta. Same for calls and puts.
Vega (ν) ∂V/∂σ = Sφ(d₁)√T/100 Price change per 1 vol point move.
Theta (Θ) ∂V/∂t Daily time decay. Almost always negative for long options.
Rho (ρ) ∂V/∂r Price change per 1% rate move.

Installation

# Clone the repository
git clone https://github.com/Alec-Teff/option-pricing-engine.git
cd option-pricing-engine

# Create and activate virtual environment
python -m venv .venv
.venv\Scripts\Activate.ps1  # Windows
source .venv/bin/activate    # Mac/Linux

# Install dependencies
pip install -r requirements.txt

# Run the dashboard
streamlit run app.py

Testing

22 unit tests covering put-call parity, Greeks behavior, Monte Carlo convergence, and implied volatility recovery:

pytest tests/ -v

Key Results

Validated against live AAPL market data:

Method Price Std Error
Black-Scholes $3.80 exact
Monte Carlo (100k paths) $3.81 0.0919
Antithetic (100k paths) $3.76 0.0911

Monte Carlo convergence: price estimate stabilizes to within $0.01 of Black-Scholes at 100,000 simulations.

Tech Stack

  • Python 3.14
  • NumPy — vectorized simulation and math
  • SciPy — normal distribution functions, Brent's method root-finder
  • Streamlit — interactive web dashboard
  • Plotly — 3D surface plots and heatmaps
  • yfinance — live market data

Concepts Demonstrated

  • Black-Scholes PDE derivation and no-arbitrage pricing
  • Risk-neutral measure and why option prices don't depend on expected returns
  • Geometric Brownian Motion and Ito's Lemma
  • Monte Carlo variance reduction techniques
  • Numerical root-finding (Newton-Raphson, Brent's method)
  • Volatility smile and term structure
  • Greeks and delta hedging

Author

Alec Teff — Georgia Tech, Class of 2029, BS Mathematics, BS Chemical Engineering. Built as a quantitative finance portfolio project during Summer 2026

About

Black-Scholes option pricing engine with Monte Carlo simulation and implied volatility surface, written in Python with a Streamlit ui

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages