Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

33 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

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

Packages

Contributors

Languages