Lesson 3 of 15
Monte Carlo VaR
Monte Carlo VaR
Monte Carlo simulation estimates VaR by generating thousands of synthetic return scenarios from an assumed distribution, then taking the empirical percentile. It is more flexible than the parametric approach and can handle non-linear instruments.
Box-Muller Transform
To generate standard normal samples from uniform randoms U1, U2 ∈ (0,1):
Z1 = sqrt(-2 ln U1) · cos(2π U2)
Z2 = sqrt(-2 ln U1) · sin(2π U2)
Each pair (Z1, Z2) gives two independent standard normals.
Algorithm
- Set random seed for reproducibility
- Generate
n_simreturns:r = μ + σ · Z - Sort simulated returns
- VaR = −return at index
int((1 − confidence) × n_sim)
Example
μ = 0.001, σ = 0.02, n = 10000, seed = 42, 95% confidence → VaR ≈ 0.0316
Python runtime loading...
Loading...
Click "Run" to execute your code.