A Python project that prices European call options using Monte Carlo simulation under Geometric Brownian Motion (GBM) and validates the results against the closed-form Black-Scholes analytical solution.
bs_monte_carlo/
├── main.py # Entry point — run the full pipeline
├── data/ # Raw / cached market data
├── src/
│ ├── __init__.py
│ ├── data_loader.py # Load historical prices from archive CSVs
│ ├── volatility.py # Historical & rolling volatility estimation
│ ├── gbm_simulator.py # Geometric Brownian Motion path simulation
│ ├── option_pricer.py # Monte Carlo call & put pricing
│ ├── black_scholes.py # Closed-form BS pricing & Greeks
│ └── plots.py # Visualisation (paths, payoff, convergence, vol)
├── dashboard.py # Interactive Streamlit dashboard
├── outputs/ # Generated plots and summary
├── requirements.txt
└── README.md
# Clone or download the project, then install dependencies:
pip install -r requirements.txtrequirements.txt includes: numpy, pandas, matplotlib, scipy, streamlit.
cd bs_monte_carlo
python main.pyThe pipeline will:
- Load 5 years of daily prices for the selected ticker from
archive/(falls back to hardcodedS0 = 150, σ = 0.25if the archive data can't be loaded). - Estimate annualised volatility from historical log-returns.
- Price an at-the-money European call via Monte Carlo (10 000 paths).
- Compute the Black-Scholes closed-form price and Greeks.
- Print a comparison table and save it to
outputs/summary.txt. - Generate four plots in
outputs/:gbm_paths.png— sample simulated price pathspayoff_distribution.png— terminal price histogram (ITM / OTM)convergence.png— MC price convergence as N growsrolling_volatility.png— 30-day rolling volatility
| Module | Description |
|---|---|
data_loader.py |
Loads adjusted-close prices from local Kaggle CSVs in archive/ and computes log-returns. |
volatility.py |
Estimates annualised historical volatility and rolling volatility windows. |
gbm_simulator.py |
Generates Monte Carlo price paths using the GBM SDE. |
option_pricer.py |
Computes discounted payoffs to price European calls and puts via MC. |
black_scholes.py |
Analytical Black-Scholes formulas for call/put prices and Greeks (Δ, Γ, ν, Θ). |
plots.py |
Four visualisation functions for paths, payoffs, convergence, and rolling vol. |
Edit the constants at the top of main.py to adjust:
- Ticker — stock symbol to load from
archive/(default:RELIANCE, override viaTICKERenv var) - Risk-free rate — annualised rate (default: 5 %)
- Time to maturity — option expiry in years (default: 1.0)
- Number of paths — Monte Carlo simulations (default: 10 000)
The project includes an interactive Streamlit dashboard where you can adjust parameters with sliders and see results update in real time:
streamlit run dashboard.pyThe dashboard provides metric cards, four interactive plots, a full summary table, and a one-click CSV download of results.