Skip to content

sreesh-codes/Stochastic-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Black-Scholes Monte Carlo Simulation

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.

Project Structure

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

Installation

# Clone or download the project, then install dependencies:
pip install -r requirements.txt

requirements.txt includes: numpy, pandas, matplotlib, scipy, streamlit.

How to Run

cd bs_monte_carlo
python main.py

The pipeline will:

  1. Load 5 years of daily prices for the selected ticker from archive/ (falls back to hardcoded S0 = 150, σ = 0.25 if the archive data can't be loaded).
  2. Estimate annualised volatility from historical log-returns.
  3. Price an at-the-money European call via Monte Carlo (10 000 paths).
  4. Compute the Black-Scholes closed-form price and Greeks.
  5. Print a comparison table and save it to outputs/summary.txt.
  6. Generate four plots in outputs/:
    • gbm_paths.png — sample simulated price paths
    • payoff_distribution.png — terminal price histogram (ITM / OTM)
    • convergence.png — MC price convergence as N grows
    • rolling_volatility.png — 30-day rolling volatility

Modules

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.

Configuration

Edit the constants at the top of main.py to adjust:

  • Ticker — stock symbol to load from archive/ (default: RELIANCE, override via TICKER env 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)

Running the Dashboard

The project includes an interactive Streamlit dashboard where you can adjust parameters with sliders and see results update in real time:

streamlit run dashboard.py

The dashboard provides metric cards, four interactive plots, a full summary table, and a one-click CSV download of results.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages