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
Interactive web application with real-time pricing, Greeks calculation, tree visualization, and convergence analysis.
- 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
- 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
- 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
- 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
- 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
- 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
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
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
# 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.txtstreamlit run streamlit_app.pyThe application will open automatically in your browser at http://localhost:8501
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
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
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
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
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.txtThe 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 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)
- Time Complexity: O(NΒ²) for tree construction and backward induction
- Space Complexity: O(NΒ²) for storing node values (with pruning: O(N))
- 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
- N=100: ~10 ms
- N=400: ~150 ms
- N=1000: ~900 ms
(Performance varies with CPU and pruning settings)
- 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