Skip to content

Options pricing engine based on a trinomial tree, supporting European and American contracts with model calibration and Greeks computation. Pricer Website :

Notifications You must be signed in to change notification settings

theov07/Trinomial_Tree_Options_Pricer_Engine

Repository files navigation

Trinomial Options Pricer

Advanced options pricing application using trinomial tree model with real-time visualization and convergence analysis.

Academic project - Paris Dauphine University - Master 2 in Financial Engineering - Major in Quantitative Finance


🚀 Live Application

→ Launch Streamlit App

Interactive web application with real-time pricing, Greeks calculation, tree visualization, and convergence analysis.


Features

Pricing Models

  • European & American Options: Call and Put options with early exercise detection
  • Trinomial Tree: Cox-Ross-Rubinstein extended model with node recombination
  • Black-Scholes Comparison: Real-time benchmarking against theoretical prices
  • Dividend Handling: Discrete dividend payments with ex-dividend date support

Greeks & Sensitivity Analysis

  • Complete Greeks Suite: Delta, Gamma, Theta, Vega, Rho
  • Numerical Precision: Finite difference methods with adaptive step size
  • Real-time Computation: Interactive calculation with configurable parameters

Visualizations & Analysis

  • Interactive Tree Display: Plotly-based trinomial tree with node details
    • Spot price at each node
    • Option value and intrinsic payoff
    • Transition probabilities (up/mid/down)
  • Convergence Analysis: Price convergence as tree steps increase
  • Performance Metrics: Computation time, node count, pruning efficiency
  • Data Export: CSV export for nodes and edges

Advanced Features

  • Pruning Optimization: Reduce computational complexity with probability thresholds
  • Flexible Time Parameters: Date-based maturity calculation
  • Parameter Sensitivity: Multiple analysis tabs for deep exploration
  • Professional Interface: Clean, intuitive Streamlit UI

Technical Implementation

Core Financial Models

  • Trinomial Tree: Variable time steps with recombining nodes
  • Black-Scholes: Closed-form solution for European options
  • Greeks Computation: Finite difference methods with numerical stability
  • Risk Management: Comprehensive sensitivity analysis

Technology Stack

  • Application: Streamlit (interactive web framework)
  • Computation: Python 3.11, NumPy, Pandas
  • Visualization: Plotly (interactive charts)
  • Financial Models: Custom implementation (Core/ modules)
  • Deployment: Local or cloud-ready

Code Architecture

Core/
  ├── Market.py          # Market parameters and dividend handling
  ├── Option.py          # Option contract specifications
  ├── Tree.py            # Trinomial tree construction and pricing
  ├── BlackScholes.py    # Black-Scholes analytical pricing
  └── Greeks.py          # Greeks calculation engine

streamlit_app.py         # Main Streamlit application
requirements.txt         # Python dependencies

Usage

Option 1: Streamlit Application (Recommended)

The Streamlit application provides a modern, interactive interface with all features accessible through an intuitive UI.

Access Options:

  • Online (No installation required): Launch the deployed app
  • Local Installation: Follow the instructions below to run on your machine

Local Installation

# Clone repository
git clone https://github.com/theov07/Pricer-M2-272-Verdelhan-LeNet.git
cd Pricer-M2-272-Verdelhan-LeNet

# Install dependencies
pip install -r requirements.txt

Launch Application

streamlit run streamlit_app.py

The application will open automatically in your browser at http://localhost:8501

Features Guide

1. Configure Parameters (Left Sidebar)

  • Market Parameters: Spot price, strike, risk-free rate, volatility
  • Time Parameters: Start date, maturity date (automatic year fraction calculation)
  • Tree Parameters: Number of steps (N), pruning threshold
  • Dividends: Optional discrete dividend with ex-dividend date
  • Option Type: Call/Put, European/American

2. Calculate Price Click "Calculate Price" to run the trinomial pricing engine. Results display:

  • Trinomial price vs Black-Scholes price
  • Price difference and percentage deviation
  • Computation time and tree statistics

3. Calculate Greeks Click "Calculate Greeks" to compute sensitivity measures:

  • Delta: Sensitivity to underlying price change
  • Gamma: Rate of change of delta
  • Theta: Time decay (per day)
  • Vega: Sensitivity to volatility change
  • Rho: Sensitivity to interest rate change

4. Visualize Tree Click "Display Tree" to see interactive trinomial structure:

  • Hover over nodes to see spot price, option value, payoff, and probabilities
  • Color-coded by option value intensity
  • Adjustable display depth for large trees

5. Advanced Analysis (5 Tabs)

  • Convergence: See how trinomial price converges to Black-Scholes as N increases
  • Node Count: Visualize tree size growth
  • Execution Time: Performance analysis across different N values
  • Precision: Absolute error vs Black-Scholes reference
  • Raw Data: Export tree nodes and edges to CSV

Example Configuration

European Call Example:

Spot Price: 100
Strike: 102
Risk-free Rate: 0.05 (5%)
Volatility: 0.30 (30%)
Maturity: 1 year from start date
Steps: 400

Expected Price: ~10.45

With Dividend:

Dividend: 3.0
Ex-Dividend Date: 6 months from start

Expected Price: ~8.73


Option 2: Flask API (Legacy - Deprecated)

The original Flask API deployment on Railway is no longer active. For API-based integration, consider:

  • Running the Streamlit app locally and accessing it programmatically
  • Using the Core modules directly in your Python code
  • Building a custom API wrapper around the Core pricing engine

Project Structure

Trinomial-Tree-Options-Pricer/
│
├── streamlit_app.py              # Streamlit web application (main entry point)
├── app.py                        # Flask API (legacy, deprecated)
├── requirements.txt              # Python dependencies
├── README.md                     # This file
│
├── Core/                         # Financial computation engine
│   ├── Market.py                 # Market parameters and dynamics
│   ├── Option.py                 # Option specifications
│   ├── Tree.py                   # Trinomial tree pricing
│   ├── Node.py                   # Tree node structure
│   ├── BlackScholes.py           # Analytical pricing
│   └── Greeks.py                 # Sensitivity calculations
│
├── API/                          # Flask API infrastructure (legacy)
│   ├── routes/                   # API endpoints
│   ├── visualization/            # Tree visualization helpers
│   └── web/                      # Static files and templates
│
└── Debug/                        # Testing and validation scripts
    └── tester_pricer.py          # Unit tests for pricing engine

Dependencies

streamlit>=1.28.0
pandas>=2.0.0
plotly>=5.0.0
numpy>=1.24.0
scipy>=1.10.0

Install all dependencies:

pip install -r requirements.txt

Mathematical Background

Trinomial Tree Model

The trinomial tree extends the binomial model with three possible price movements at each step:

Price Movements:

  • Up: S × u (with probability pᵤ)
  • Middle: S × m (with probability pₘ)
  • Down: S × d (with probability pₐ)

Standard Parameterization:

u = exp(σ√(2Δt))
d = 1/u
m = 1

Where:

  • σ = volatility
  • Δt = T/N (time step)
  • T = time to maturity
  • N = number of steps

Risk-Neutral Probabilities:

pᵤ = [(exp(rΔt/2) - exp(-σ√(Δt/2))) / (exp(σ√(Δt/2)) - exp(-σ√(Δt/2)))]²
pₐ = [(exp(σ√(Δt/2)) - exp(rΔt/2)) / (exp(σ√(Δt/2)) - exp(-σ√(Δt/2)))]²
pₘ = 1 - pᵤ - pₐ

Backward Induction: Option values are computed recursively from maturity to present:

V(S,t) = exp(-rΔt)[pᵤVᵤ + pₘVₘ + pₐVₐ]

For American options, apply early exercise check:

V(S,t) = max(Intrinsic Value, Continuation Value)

Greeks Computation

Greeks are calculated using finite difference approximations:

Delta (∂V/∂S): First derivative with respect to spot

Δ = (V(S+h) - V(S-h)) / (2h)

Gamma (∂²V/∂S²): Second derivative with respect to spot

Γ = (V(S+h) - 2V(S) + V(S-h)) / h²

Theta (∂V/∂t): Time decay

Θ = (V(t+Δt) - V(t)) / Δt

Vega (∂V/∂σ): Volatility sensitivity

ν = (V(σ+h) - V(σ-h)) / (2h)

Rho (∂V/∂r): Interest rate sensitivity

ρ = (V(r+h) - V(r-h)) / (2h)

Performance Considerations

Computational Complexity

  • Time Complexity: O(N²) for tree construction and backward induction
  • Space Complexity: O(N²) for storing node values (with pruning: O(N))

Optimization Techniques

  • Node Recombination: Reduces exponential growth to quadratic
  • Pruning: Eliminates nodes with probability below threshold
  • Sparse Storage: Only active nodes stored in memory
  • Vectorization: NumPy operations for numerical efficiency

Typical Performance

  • N=100: ~10 ms
  • N=400: ~150 ms
  • N=1000: ~900 ms

(Performance varies with CPU and pruning settings)


References

Implementation Notes

  • Trinomial tree implementation follows Cox-Ross-Rubinstein extended methodology
  • Greeks computation uses central difference for improved accuracy
  • Dividend handling assumes discrete cash payments on ex-dividend dates
  • American option pricing uses optimal stopping at each node

Authors: VERDELHAN Théo & LE NET Arthur
Institution: Paris Dauphine University - Master 2 in Financial Engineering - Major in Quantitative Finance

About

Options pricing engine based on a trinomial tree, supporting European and American contracts with model calibration and Greeks computation. Pricer Website :

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published