Skip to content

About

An options pricing model based on Monte Carlo's Equation

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Monte Carlo Options Pricing Simulator

A Python-based options pricing tool that uses Monte Carlo simulation to estimate European call and put option prices, validates them against the Black-Scholes analytical model, and computes the full suite of Options Greeks — all visualized through an interactive dark-themed chart.


Theory & Background

Monte Carlo Simulation

Monte Carlo methods use repeated random sampling to estimate numerical results that are deterministic in principle but too complex to solve analytically in practice. In the context of options pricing:

  1. The underlying stock price is modelled as a Geometric Brownian Motion (GBM):

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

  1. Thousands of possible future price paths are simulated by discretising the SDE above.
  2. At expiration, the payoff of each path is calculated:
    • Call: $\max(S_T - K, , 0)$
    • Put: $\max(K - S_T, , 0)$
  3. The option price is the discounted average of all simulated payoffs:

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

Where:

Symbol Definition
$S$ Stock price at time $t$
$\mu$ Drift (expected return) of the stock
$\sigma$ Volatility (annualised standard deviation of log-returns)
$dW$ Increment of a Wiener process (Brownian motion)
$S_T^{(i)}$ Simulated stock price at expiry for the $i$-th path
$K$ Strike price of the option
$r$ Risk-free interest rate (annualised, continuously compounded)
$T$ Time to maturity (in years)
$N$ Total number of simulated paths
$e^{-rT}$ Discount factor to bring future payoffs to present value

Monte Carlo is especially powerful because it scales to exotic options and multi-asset derivatives where closed-form solutions do not exist.


Black-Scholes Model

The Black-Scholes-Merton (BSM) model provides an analytical (closed-form) solution for European option prices under specific assumptions:

Assumption Description
Log-normal prices Stock prices follow a GBM
Constant volatility $\sigma$ does not change over the option's life
No dividends The underlying pays no dividends
Risk-free rate A constant, known, risk-free interest rate $r$ exists
No arbitrage Markets are frictionless and efficient

The closed-form pricing formulas are:

$$C = S_0 , N(d_1) - K , e^{-rT} , N(d_2)$$

$$P = K , e^{-rT} , N(-d_2) - S_0 , N(-d_1)$$

Where:

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

Symbol Definition
$C$ Call option price
$P$ Put option price
$S_0$ Current stock (spot) price
$K$ Strike price
$r$ Risk-free interest rate
$\sigma$ Volatility
$T$ Time to maturity
$N(x)$ Cumulative distribution function (CDF) of the standard normal distribution
$d_1, d_2$ Intermediate variables that capture the moneyness, time, volatility, and rate
$e^{-rT}$ Discount factor

This project uses the BSM price as a benchmark to validate the accuracy of the Monte Carlo estimates.


Options Greeks

Greeks measure the sensitivity of an option's price to changes in underlying parameters. This simulator computes the following:

Greek Symbol Measures Sensitivity To Formula (Call)
Delta $\Delta$ Underlying price $N(d_1)$
Gamma $\Gamma$ Delta's rate of change $\frac{N'(d_1)}{S_0 \sigma \sqrt{T}}$
Vega $\nu$ Volatility (per 1%) $\frac{S_0 , N'(d_1) \sqrt{T}}{100}$
Theta $\Theta$ Time decay (per day) $\frac{-S_0 , N'(d_1) \sigma}{2\sqrt{T}} - rKe^{-rT}N(d_2)$ ÷ 365
Rho $\rho$ Risk-free rate (per 1%) $\frac{KTe^{-rT}N(d_2)}{100}$

Input Parameters

The simulator prompts for the following parameters at runtime. Press Enter to accept the default value.

Symbol Parameter Description Default Unit
S0 Stock Price Current spot price of the underlying asset 100.0 Currency (e.g. USD)
K Strike Price Price at which the option can be exercised 100.0 Currency
σ Volatility Annualised standard deviation of the asset's log-returns 0.20 Decimal (20%)
r Risk-Free Rate Annualised continuously-compounded risk-free interest rate 0.05 Decimal (5%)
T Time to Maturity Remaining life of the option 1.0 Years
— Time Steps Number of discrete intervals to divide T into for path simulation 252 Count (≈ trading days/year)
— Simulations Number of random GBM paths to generate 10000 Count

Tip: The default values represent a typical at-the-money (ATM) European option scenario. Increase the number of simulations for higher accuracy at the cost of longer runtime.


Workflow

┌─────────────────────────────────────────────────────────────────┐
│  1. USER INPUT                                                  │
│     Collect parameters with sensible defaults:                  │
│     S0, K, σ, r, T, time steps, number of simulations           │
├─────────────────────────────────────────────────────────────────┤
│  2. GBM PATH SIMULATION  (utils.simulate_gbm_paths)             │
│     Generate N vectorised stock-price paths via GBM             │
│     using cumulative log-returns for performance                │
├─────────────────────────────────────────────────────────────────┤
│  3. MONTE CARLO PRICING  (utils.monte_carlo_price)              │
│     Compute discounted average payoff across all paths          │
│     → MC Call Price, MC Put Price                               │
├─────────────────────────────────────────────────────────────────┤
│  4. BLACK-SCHOLES PRICING  (utils.black_scholes)                │
│     Analytical closed-form solution as benchmark                │
│     → BS Call Price, BS Put Price                               │
├─────────────────────────────────────────────────────────────────┤
│  5. GREEKS COMPUTATION  (utils.compute_greeks)                  │
│     Δ (Delta), Γ (Gamma), ν (Vega), Θ (Theta), ρ (Rho)          │
│     for both call and put options                               │
├─────────────────────────────────────────────────────────────────┤
│  6. CONSOLE OUTPUT                                              │
│     Formatted comparison table: MC vs BS prices + Greeks        │
├─────────────────────────────────────────────────────────────────┤
│  7. VISUALIZATION                                               │
│     Dark-themed matplotlib chart with:                          │
│     • 50 sample GBM paths                                       │
│     • Strike & spot price reference lines                       │
│     • Parameter, price comparison & Greeks annotation boxes     │
└─────────────────────────────────────────────────────────────────┘

Directory Structure

monte-carlo-options-pricing-simulator/
├── main.py             # Entry point — orchestrates input, simulation, output & plot
├── utils.py            # Core math — GBM simulation, BS pricing, MC pricing, Greeks
├── requirements.txt    # Python dependencies
└── README.md           # Project Documentation

Installation

Prerequisites

  • Python 3.8+ (tested on 3.10+)
  • pip (Python package manager)

Steps

  1. Clone the repository

    git clone https://github.com/drunktrader/monte-carlo-options-pricing-simulator.git
    cd monte-carlo-options-pricing-simulator
  2. Create a virtual environment (recommended)

    python -m venv venv
    
    # Windows
    venv\Scripts\activate
    
    # macOS / Linux
    source venv/bin/activate
  3. Install dependencies

    pip install -r requirements.txt

Running the Simulator

python main.py

You will be prompted to enter option parameters. Press Enter to accept the default values shown in brackets:

Stock Price       (S0)    [100.0] :
Strike Price      (K)     [100.0] :
Volatility        (sigma) [0.20]  :
Risk-Free Rate    (r)     [0.05]  :
Time to Maturity  (T)     [1.0]   :
Number of Time Steps      [252]   :
Number of Simulations     [10000] :

Sample Output

============================================================
Option Price Comparison:
         Method      Call Price      Put Price
    Monte Carlo     10.438291      5.563102
  Black-Scholes     10.450584      5.573526

  Call Price Difference (MC - BS): -0.0123
  Put Price Difference  (MC - BS): -0.0104
============================================================
Options Greeks (Black-Scholes):
    Delta  (Call):  0.6368
    Delta  (Put):  -0.3632
    Gamma:          0.0188
    Vega:           0.3752
    Theta  (Call):  -0.0174  (per day)
    Theta  (Put):   -0.0041  (per day)
    Rho    (Call):  0.5323
    Rho    (Put):  -0.4189
============================================================

A matplotlib window will then display 50 sample GBM paths with annotated pricing and Greeks information.


Dependencies

Package Purpose
numpy Vectorised numerical computation & random number generation
scipy Normal distribution CDF/PDF for Black-Scholes & Greeks
matplotlib Dark-themed stock price path visualization

License

This project is open-source. Feel free to use, modify, and distribute.

About

An options pricing model based on Monte Carlo's Equation

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages