← Back to Blog
Quantitative Finance

Monte Carlo Simulation for Portfolio Risk: From Theory to Production API

April 2025·12 min read·MainState Labs

Monte Carlo is the workhorse of modern risk management. Banks run millions of simulations nightly to compute VaR. Here is how to use the same techniques in your own applications without a quant team.

Why Monte Carlo Instead of Analytical Models

Analytical models like Black-Scholes work beautifully for single assets with simple payoffs. The moment you introduce path dependency — Asian options, barrier options, early exercise — the closed-form solution either does not exist or becomes intractable. Monte Carlo sidesteps this entirely by simulating thousands of possible price paths and averaging the outcomes.

For portfolio risk, the advantage is even clearer. A portfolio of 50 correlated assets has a covariance structure that no analytical formula captures cleanly. Monte Carlo handles it naturally: simulate correlated returns using Cholesky decomposition of the covariance matrix, run 10,000 scenarios, read off the distribution of portfolio P&L.

The tradeoff is compute time. A naive implementation of 10,000 paths for a 50-asset portfolio takes seconds in Python. The MainState Labs Monte Carlo endpoint runs the same simulation in under 300ms using vectorized NumPy operations and pre-compiled Numba kernels.

Value at Risk and Expected Shortfall

The two most important outputs from a Monte Carlo risk simulation are Value at Risk (VaR) and Expected Shortfall (ES, also called CVaR).

VaR at the 95% confidence level answers: "What is the maximum loss I should expect on 95% of trading days?" If your 1-day 95% VaR is $50,000, you expect to lose more than $50,000 only 5% of the time — about 12 trading days per year.

Expected Shortfall answers a better question: "When I do have a bad day, how bad is it on average?" ES is the mean of the losses in the worst 5% of scenarios. It is a coherent risk measure — unlike VaR, it satisfies subadditivity, meaning the risk of a combined portfolio is never greater than the sum of the individual risks.

Basel III note

The Basel III framework (FRTB) replaced VaR with Expected Shortfall at the 97.5% confidence level as the primary market risk measure for bank capital requirements. If you are building risk infrastructure for a regulated entity, ES is the number that matters.

Geometric Brownian Motion and Its Limits

The standard Monte Carlo model for equity prices is Geometric Brownian Motion (GBM). It assumes log-returns are normally distributed and independent across time. This is a convenient approximation, not a description of reality.

Real equity returns have fat tails — extreme events happen far more often than a normal distribution predicts. The 2008 financial crisis, the March 2020 COVID crash, the 2022 rate shock — all of these were multi-sigma events under GBM assumptions that occurred within a 15-year window.

More sophisticated approaches use Student's t-distribution for the innovations (capturing fat tails), GARCH models for time-varying volatility, or jump-diffusion processes for sudden price gaps. The MainState Labs Monte Carlo endpoint supports configurable return distributions, letting you choose between normal, Student-t, and historical bootstrap methods.

Practical Use Cases

Robo-advisors use Monte Carlo to project retirement portfolio outcomes — showing users a distribution of possible portfolio values at age 65 rather than a single optimistic number. Wealth management platforms in India, Southeast Asia, and Latin America are building exactly this kind of tool as retail investing grows in those markets.

Crypto trading platforms use Monte Carlo for position sizing and risk limits. The same mathematics that applies to equity portfolios applies to BTC/ETH portfolios, with the added complexity of much higher volatility and correlation instability.

Corporate treasury teams use it for FX risk — simulating the distribution of USD/JPY or EUR/USD over a 12-month horizon to set hedging ratios. This is a $7 trillion daily market, and most mid-size companies have no systematic risk framework at all.

Run Monte Carlo simulations via REST API in under 300ms.

Try the Finance API →