Turning a calculation into an experiment
A Monte Carlo method replaces a quantity you cannot easily compute with an expectation you can estimate by repeated random sampling: draw samples from the right distribution, average some function of them, and let the law of large numbers guarantee the average converges to the true expected value as the number of samples grows. The name dates to Los Alamos in the 1940s, where Stanislaw Ulam realised that a hard combinatorial question about solitaire was far easier to answer by dealing hands and counting than by exact enumeration, and John von Neumann saw the same trick applied directly to neutron transport.
π from a square and a quarter circle
The simplest concrete case, and the one that gives the whole family its intuition: inscribe a quarter circle of radius 1 in a unit square and drop points uniformly at random into the square. The probability a point lands inside the quarter circle equals the ratio of the two areas, π/4, so counting hits and scaling gives an estimator for π:
let inside = 0;
for (let i = 0; i < n; i++) {
const x = Math.random(), y = Math.random();
if (x*x + y*y <= 1) inside++;
}
piEstimate = 4 * inside / n;
standard error ≈ 1.64 / sqrt(n) (falls with 1/sqrt(n), independent of dimension)
That last property — the error's total indifference to dimension — is the entire reason Monte Carlo matters beyond toy demonstrations. A grid-based numerical integration rule needs mᵈ points to place m points along each of d axes, so its cost explodes with dimension (the curse of dimensionality); a Monte Carlo estimate's 1/√n error bound literally does not contain d. In two dimensions that indifference to dimension is a mild curiosity; in the twenty, two hundred or two thousand dimensions of a real risk model, a Bayesian posterior or a light-transport integral, it is very often the only method that works at all.
General integration: any integral is an area
Nothing above is specific to circles. Any definite integral ∫f(x)dx over a bounded region can be written as an expectation, E[f(X)] · (volume of the region), for X drawn uniformly from that region — so the same three-line loop that estimates π generalises immediately to estimating any integral, in any number of dimensions, just by sampling from the right region and averaging f instead of counting hits:
∫_a^b f(x) dx ≈ (b − a) · (1/n) Σ f(Xi), Xi ~ Uniform(a, b)
From area to money: Value at Risk
The same machinery answers a very different question in finance: what is the worst loss a portfolio is likely to suffer over some horizon, with a given confidence level — its Value at Risk (VaR)? Rather than assume a closed-form distribution for the portfolio's future value, Monte Carlo VaR simulates thousands of plausible future price paths directly. A standard model for a single asset's price is geometric Brownian motion (GBM), the stochastic differential equation
dS = μ S dt + σ S dW (μ = drift, σ = volatility, dW = Wiener increment) discretised (Euler–Maruyama / exact GBM step): S(t+Δt) = S(t) · exp( (μ − σ²/2)Δt + σ√Δt · Z ), Z ~ N(0,1)
Simulate many thousands of independent price paths this way to the horizon date, compute the portfolio's profit or loss on each simulated path, and sort the resulting distribution of outcomes. The 95% VaR is simply the loss at the 5th percentile of that simulated distribution — the loss you expect to be exceeded only 5% of the time. This Monte Carlo approach handles path-dependent instruments (options with early-exercise or barrier features, structured products) that closed-form formulas cannot, at the cost of needing enough simulated paths for the tail percentile itself to be estimated reliably, since the tail is by definition where you have the fewest samples.
Expected shortfall (also called Conditional VaR) goes one step further and asks: given that the loss did exceed the VaR threshold, what is its average size? It answers a question VaR itself cannot — how bad is bad, past the threshold — and is estimated from the same simulated paths by simply averaging the losses that fall beyond the VaR percentile instead of just reporting that one percentile.
Buying accuracy without buying more samples
Because the 1/√n law is fixed, the only lever left is shrinking the variance of what you are averaging, and several standard techniques do exactly that for the same sample budget: importance sampling draws more heavily from the region that matters most (e.g. deep in the loss tail for VaR) and reweights to correct the bias; antithetic variates pairs each random draw Z with its mirror −Z, so their errors partially cancel; stratified sampling forces samples to cover the domain evenly rather than leaving it to chance; and control variates subtract off a correlated quantity whose true mean is already known exactly, using only the residual difference as the random part of the estimate.
The generator matters as much as the method
A Monte Carlo answer is only as trustworthy as the randomness feeding it. Three practical rules apply everywhere this technique is used: use a well-tested generator rather than a hand-rolled one (naive linear congruential generators are notorious for falling into visible hyperplanes when their output is plotted in more than a couple of dimensions); seed it explicitly and record the seed, since an unreproducible Monte Carlo run cannot be debugged or audited; and, in risk applications specifically, be honest that the whole estimate inherits whatever assumptions went into the price-path model — a GBM VaR estimate is exactly as good as the assumption that returns are lognormal with constant volatility, which real markets violate most dramatically in precisely the tail events VaR is meant to warn about.
Frequently asked questions
Why does Monte Carlo integration work in high dimensions when grid methods don't?
A grid-based rule needs a number of points that grows as (points per axis) raised to the power of the dimension, so its cost explodes as dimension increases — the curse of dimensionality. Monte Carlo's error bound, roughly 1/sqrt(n), does not depend on dimension at all: the same number of random samples gives roughly the same accuracy whether you are integrating over 2 dimensions or 200, which is why it dominates in high-dimensional problems like risk simulation and light transport.
What does 95% Value at Risk actually mean?
It is the loss level that a portfolio's simulated outcomes exceed only 5% of the time over the chosen horizon — the loss at the 5th percentile of the simulated profit-and-loss distribution. It says nothing about how large losses beyond that threshold might be; that question is answered by Expected Shortfall (Conditional VaR), which averages the losses that do exceed the VaR threshold.
Why does Monte Carlo's accuracy improve so slowly with more samples?
Because the standard error of a Monte Carlo average falls as 1/sqrt(n): to cut the error in half you need four times as many samples, and to add one more decimal digit of accuracy you need roughly a hundred times more samples. Variance-reduction techniques such as importance sampling, antithetic variates and stratified sampling reduce the constant in front of that 1/sqrt(n), which is the only lever available once the sample count itself becomes too expensive to keep raising.
Try it live
Everything above runs in your browser — open Monte Carlo Estimation and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.
▶ Open Monte Carlo Estimation simulation