🎲 Monte Carlo Estimation: From π to Financial Risk
Watch genuine Monte Carlo simulation run live in 3D: estimate π by scattering random points in a circle, estimate a definite integral by sampling a surface, and compute real financial Value-at-Risk from thousands of simulated price paths — all converging at the classic 1/√N rate.
About Monte Carlo Estimation
Monte Carlo estimation replaces exact calculation with repeated random sampling, justified by the law of large numbers: as the number of independent samples N grows, the sample average converges to the true expected value. The error of a Monte Carlo estimate shrinks at the characteristic rate O(1/√N), regardless of how many dimensions the underlying problem has — quadrupling the sample count only halves the error. This is its decisive advantage over grid-based numerical integration (quadrature), whose cost explodes exponentially with dimensionality (the "curse of dimensionality"); a Monte Carlo estimator pays no such penalty, which is why it dominates in high-dimensional finance, physics and machine-learning problems.
This simulator runs three linked demos with genuine live random sampling — no pre-baked results. The π mode scatters random points into a unit square and counts the fraction landing inside the inscribed quarter circle: that fraction times 4 estimates π. The Integral mode samples a 3D surface z=f(x,y) at random (x,y) and averages the sampled heights, scaling by the domain area to estimate the volume underneath — the definite integral. The VaR mode simulates thousands of random asset-price paths under geometric Brownian motion (dS=μS dt+σS dW), the standard model for stock prices, and reads the 5th percentile of the simulated final-price distribution as an empirical Value-at-Risk. Switch modes, adjust the sampling rate, and watch each estimate's standard error shrink live as N grows.
Frequently Asked Questions
What is Monte Carlo estimation?
Monte Carlo estimation approximates a quantity that is hard to compute analytically — an area, an integral, a probability, a risk measure — by drawing many independent random samples and averaging a function of them. The law of large numbers guarantees the average converges to the true value as the sample count N grows; the accuracy improves predictably even when no closed-form solution exists.
Why does the error shrink as 1/√N, and why doesn't dimensionality matter?
By the central limit theorem, the standard error of a Monte Carlo average is σ/√N, where σ is the standard deviation of the sampled quantity — this holds however many input dimensions the problem has, because it only depends on the variance of the single output being averaged. Grid-based numerical integration, by contrast, needs a number of grid points that grows exponentially with the number of dimensions to hold accuracy fixed — the "curse of dimensionality" — which is why Monte Carlo overtakes quadrature once a problem has more than a handful of dimensions.
How does the π-estimation demo work?
Points are drawn uniformly at random inside a unit square. A point (x,y) lies inside the inscribed quarter circle of radius 1 exactly when x²+y²≤1. Since the quarter circle covers a fraction π/4 of the square's area, four times the observed fraction of points landing inside is an unbiased estimator of π — this simulator counts hits and misses live and recomputes the estimate every frame.
How does the integral-estimation demo work?
For a function f(x,y) over a domain of area A, the mean value theorem for integrals says the average value of f over the domain, times A, equals the double integral of f. The demo samples (x,y) uniformly at random, evaluates f at each point, keeps a running average, and multiplies by A — the domain area — to estimate the volume under the surface without ever evaluating f on a fixed grid.
What is geometric Brownian motion, and why is it used for stock prices?
Geometric Brownian motion (GBM) models an asset price S as dS = μS dt + σS dW, where μ is the annualised drift, σ the annualised volatility, and dW a Wiener process increment (Gaussian noise). It is the standard building block of the Black–Scholes framework because it keeps prices positive and gives log-returns that are Normally distributed, matching the rough shape of real return data reasonably well over short-to-medium horizons.
What is Value-at-Risk (VaR) and how is it computed here?
Value-at-Risk at the 5% level is the loss that should not be exceeded with 95% confidence over a given horizon. This simulator estimates it empirically: it simulates many independent GBM price paths, collects their final prices, and reads off the 5th percentile of that empirical distribution — the loss at that percentile is the simulated VaR. A theoretical VaR is also shown, computed in closed form from the known lognormal distribution of GBM's terminal price.
What are the criticisms and limitations of VaR as a risk metric?
VaR is one of the most widely used risk metrics in finance, but it has well-known weaknesses: it says nothing about how bad losses beyond the threshold can be (it is not "coherent" in the technical sense, unlike Expected Shortfall/CVaR), it can encourage risk concentration in the tail, and real markets exhibit fat tails, volatility clustering and jumps that a simple GBM model understates. It remains standard because it is intuitive and simple to compute, but risk managers usually pair it with other measures.
How is Monte Carlo different from grid-based numerical integration?
Grid quadrature evaluates a function at deterministic, evenly spaced points and combines them with fixed weights; its error typically shrinks polynomially in the number of grid points per dimension, but the total number of points needed to cover a d-dimensional grid grows exponentially in d. Monte Carlo instead evaluates the function at random points; its error shrinks as O(1/√N) independent of dimension, so it becomes the more efficient choice once a problem has more than roughly 3–4 dimensions — a big reason it dominates in finance and physics, where models often have dozens or thousands of dimensions.
Is Monte Carlo simulation "real" science, or just a numerical trick?
It is both rigorous and practical. Its convergence properties are proven by the law of large numbers and the central limit theorem, giving quantifiable error bars (the standard error shown live in this simulator), not just a plausible-looking answer. Monte Carlo methods are used throughout physics (particle transport, statistical mechanics), engineering (reliability analysis), and finance (derivative pricing, risk management) precisely because their accuracy can be estimated and controlled by choosing N.
Watch genuine Monte Carlo simulation run live in 3D: estimate π, estimate a definite integral, and compute real financial Value-at-Risk from simulated price paths.
2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install