This repository contains a production-grade pricing engine for Multi-Asset Autocallable Reverse Convertibles (MARC).
In the modern equity derivatives landscape, structurers face significant risks when pricing barrier-contingent payoffs. Legacy systems (often C++ wrapped in Excel) struggle to price the "Worst-Of" correlation exposure and American Barriers with sufficient speed and accuracy.
This engine leverages the Python numerical stack (specifically Numba) to achieve nanosecond latency comparable to C++, while maintaining the flexibility of a scripting language. It explicitly handles:
- Path Dependency: American barriers and Autocall triggers.
- Skew Risk: Local Volatility (Dupire) modeling.
- Negative Gamma: Advanced risk visualizations for "Pin Risk" and "Gap Risk."
The engine moves beyond standard Black-Scholes assumptions to model the true behavior of multi-asset baskets.
The product performance is linked to the asset with the lowest return in the basket. The pricing kernel treats the correlation matrix as a first-order pricing parameter.
To ensure market-consistent pricing, we employ:
-
Local Volatility (Dupire): We construct a smooth Implied Volatility Surface using Bicubic Splines and pre-compute a Local Volatility grid. This allows the simulation to "ride" the skew, returning higher volatilities as the spot drops toward the barrier (Knock-In).
$$\sigma_{loc}^2(K,T) = \frac{\frac{\partial C}{\partial T} + (r-q)K\frac{\partial C}{\partial K} + qC}{\frac{1}{2}K^2\frac{\partial^2 C}{\partial K^2}}$$ - Cholesky Decomposition: Used to simulate correlated Brownian motions. The engine includes spectral decomposition (Higham's Algorithm) to project non-PSD correlation matrices onto the nearest valid PSD matrix.
To achieve convergence (Standard Error < 0.1%) without computational bloat, we utilize:
-
Antithetic Variates: Simulating path pairs
$(Z, -Z)$ to reduce variance at zero cost. - Control Variates: We use a Geometric Basket Option (which has an analytical closed-form solution) as a control to correct the Monte Carlo error for the "Worst-Of" simulation.
This project strictly follows a Model-View-Controller (MVC) pattern to separate mathematical kernels from UI logic.
- Language: Python 3.9+
- JIT Compilation:
Numba(Used for the Monte Carlo loop to avoid Python's branching overhead). - Visualization:
Streamlit(Dashboard) &Plotly(Interactive Greeks).
We utilize Numba over standard Numpy vectorization. While Numpy is efficient for arrays, Numba allows for optimized "Early Exit" branching—essential for Autocall structures where paths terminate early, saving significant computational resources.
MARC_Pricing_Engine/
├── data/
│ ├── config.yaml # Simulation parameters (N paths, time steps)
│ ├── market_data.parquet # Historical price data (Yahoo Finance)
│ └── market_vols.parquet # Generated local volatility surfaces
├── src/
│ ├── __init__.py
│ ├── simulation.py # Main simulation wrapper (Pricing & Plotting modes)
│ ├── math_core/
│ │ ├── __init__.py
│ │ ├── cholesky.py # Correlation matrix PSD fixes & decomposition
│ │ ├── gbm_numba.py # The compiled JIT Monte Carlo kernel
│ │ └── spline_vol.py # Cubic spline volatility surface interpolation
│ ├── instruments/
│ │ ├── __init__.py
│ │ ├── marc.py # Product definition class (Barriers, Coupons, Maturity)
│ │ ├── market.py # Market Environment data class
│ │ └── payoff.py # Payoff logic (Autocall, Knock-In, Memory Coupons)
│ ├── analytics/
│ │ ├── greeks.py # Finite Difference Greeks (Delta, Vega)
│ │ └── variance_reduction.py # Control Variate (Martingale) regression logic
│ └── app/
│ ├── dashboard.py # Streamlit Web UI entry point
│ ├── plots.py # Matplotlib/Plotly visualization wrappers
│ └── reporting.py # PDF Term Sheet generator (FPDF)
├── tests/
│ ├── test_analytical.py # Unit tests: MC vs Black-Scholes benchmark
│ └── test_barriers.py # Unit tests: Barrier hit logic verification
├── fetch_data.py # Script to download prices & generate volatility surfaces
├── main.py # CLI entry point for running the engine locally
├── requirements.txt # Project dependencies
└── README.md # Project documentation