Python implementation of the numerical examples from the Master thesis:
Nested Multilevel Monte Carlo Simulation Nicolai Ehrhardt, TU Kaiserslautern, 2018 Supervised by Prof. Dr. Klaus Ritter, AG Computational Stochastics
This repository contains implementations and visualizations of Multilevel Monte Carlo (MLMC) methods applied to nested simulation problems arising in financial risk measurement, specifically the approximation of Value-at-Risk via nested expectations.
The underlying model is the Black-Scholes model with geometric Brownian motion. The code demonstrates:
- Brownian motion simulation and fine/coarse path coupling
- Euler-Maruyama and Milstein strong approximation schemes for SDEs
- Smoothing functions for indicator function approximation (Chapter 4)
- MLMC estimators for path-independent (European call) and path-dependent (lookback) options
- Nested simulation: outer real-world scenarios + inner risk-neutral pricing
- Convergence rate verification: MSE, level variance, and level mean
The goal is to compute quantities of the form
where
In general,
In the financial setting, let
which gives the expected payoff at maturity
Thus, estimating VaR reduces to approximating the distribution function of
This is exactly the nested expectation problem with
The numerical examples use the one-dimensional Black-Scholes model:
with explicit solution
The Euler-Maruyama scheme approximates
while the Milstein method adds a correction term for higher-order strong convergence:
The MLMC estimator is based on the telescoping decomposition
where
Since the indicator function
so that
Outer real-world scenarios (left of the vertical line) fan out into multiple inner risk-neutral pricing scenarios:
GBM paths with the log-normal terminal distribution emerging at maturity:
The multilevel method exploits coupled fine/coarse discretizations of the same Brownian path:
Polynomial approximations of the indicator function for different smoothness parameters r and smoothing widths delta:
MSE of Euler-Maruyama (slope -1) vs Milstein (slope -2) confirms the theoretical strong convergence orders:
MLMC level variance and level mean decay at the predicted rates:
Approximation of the distribution function of h(X) using the Black-Scholes pricing formula, converging with increasing sample size:
core.py # Core functions (simulation, MLMC, smoothing, Black-Scholes)
plot_brownian_paths.py # Figures 6 & 7: Independent and fine/coarse Brownian paths
plot_gbm.py # Figure 8: GBM Euler vs Milstein approximation
plot_gbm_distribution.py # Figures 4 & 16: GBM paths with log-normal distribution, empirical CDF
plot_nested_simulation.py # Figure 9: Nested simulation (outer + inner scenarios)
plot_nested_arrow.py # Figure 1: Schematic nested simulation diagram
plot_smoothing.py # Figures 2 & 3: Smoothing of indicator function
plot_mse_convergence.py # Figure 5: MSE convergence of Euler and Milstein
plot_level_variance.py # Figures 10 & 11: Level variance and level mean
matlab/ # Original MATLAB scripts
output/ # Pre-generated plots
pip install -r requirements.txt
python plot_brownian_paths.py
python plot_smoothing.py
python plot_nested_simulation.py
# ...The numerical experiments confirm the theoretical convergence rates from the thesis:
| Method | Quantity | Observed rate | Theoretical rate |
|---|---|---|---|
| Euler-Maruyama | MSE at terminal time | -1.02 | -1 (Thm 5.2) |
| Milstein | MSE at terminal time | -1.99 | -2 (Thm 5.5) |
| Euler MLMC | Level variance | -0.96 | -1 (Rem 5.9) |
| Milstein MLMC | Level variance | -1.92 | -2 (Rem 5.13) |
- M. B. Giles. Multilevel Monte Carlo methods. Acta Numerica, 2015.
- M. B. Giles, T. Nagapetyan, K. Ritter. Multilevel Monte Carlo Approximation of Distribution Functions and Densities. SIAM/ASA J. Uncertainty Quantification, 2015.
- P. Kloeden, E. Platen. Numerical Solution of Stochastic Differential Equations. Springer, 1999.
- T. Mueller-Gronbach, E. Novak, K. Ritter. Monte Carlo-Algorithmen. Springer, 2012.
MIT








