Monte Carlo simulation
Seeded Monte Carlo of geometric Brownian motion, with antithetic variates, and the nonparametric bootstrap of a mean, median or standard deviation.
- Model id
foundations.simulation, version 1- Domain
- Foundations
- Evidence
- standard
- Cost class
- heavy: Estimation or simulation; a hosted run may take up to 30 seconds.
Formula
Where
- The value at time t
- The value now
initial_value - Drift per year
drift - Volatility per year
volatility - The length of one step, in years
- A standard normal draw
- The expected value at the horizon, which the simulated mean estimates
terminal_mean - Horizon, in years
horizon - Standard error of the simulated mean
standard_error - Standard deviation of the simulated values at the horizon
terminal_std - Number of simulated paths
paths_simulated - Bootstrap standard error of the statistic
standard_error - Number of resamples
resamples - The statistic computed on resample b
- One less the confidence level
Each symbol's field is named beside it; the inputs and outputs, with their units and bounds, are under Variables, and the citations give each formula's source.
Variables
Rates, returns and yields are decimals: 0.05 is five percent. Bounds in brackets include their end; in parentheses they exclude it.
Inputs
Monte Carlo of geometric Brownian motion (gbm): 11 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Monte Carlo of geometric Brownian motion | |
Initial valueinitial_valueindex_level · [0.01, 1e+06] | index_level | [0.01, 1e+06] | Value at time 0 |
Driftdriftrate · [-1, 1] | rate | [-1, 1] | Expected growth rate mu, continuous, per year |
Volatilityvolatilityvolatility · (0, 3] | volatility | (0, 3] | Volatility per year |
Horizonhorizonyears · (0, 30] | years | (0, 30] | Time to the horizon, in years |
Stepsstepscount · [1, 1000] | count | [1, 1000] | Time steps per path |
Pathspathscount · [4, 100000] | count | [4, 100000] | Number of simulated paths |
Antitheticantitheticflag | flag | Pair each path with its mirror image (rounds paths up to even) | |
Percentilespercentilesprobability (array) · length min 1, max 99; each [0, 1] | probability (array) | length min 1, max 99; each [0, 1] | Probabilities at which to report terminal quantiles |
Levellevelindex_level · [0.01, 1e+09] | index_level | [0.01, 1e+09] | Level for the probability of ending below; null for the start |
Seedseedcount · [0, 9.0072e+15] | count | [0, 9.0072e+15] | Random seed (ADR-0008 decision 7): the same seed, the same draws |
Nonparametric bootstrap of a statistic (bootstrap): 6 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Nonparametric bootstrap of a statistic | |
Samplesampleratio (array) · length min 2, max 1000; each [-1e+06, 1e+06] | ratio (array) | length min 2, max 1000; each [-1e+06, 1e+06] | The observed sample |
Statisticstatistictext | text | The statistic to bootstrap (standard deviation: n - 1) | |
Resamplesresamplescount · [2, 10000] | count | [2, 10000] | Number of bootstrap resamples |
Confidenceconfidenceprobability · [0.5, 0.999] | probability | [0.5, 0.999] | Coverage of the percentile interval |
Seedseedcount · [0, 9.0072e+15] | count | [0, 9.0072e+15] | Random seed (ADR-0008 decision 7): the same seed, the same draws |
Outputs
Monte Carlo of geometric Brownian motion (gbm): 9 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Monte Carlo of geometric Brownian motion | |
Terminal meanterminal_meanindex_level · [0, 1e+30] | index_level | [0, 1e+30] | Mean terminal value |
Terminal stdterminal_stdindex_level · [0, 1e+30] | index_level | [0, 1e+30] | Standard deviation of terminal values |
Standard errorstandard_errorindex_level · [0, 1e+30] | index_level | [0, 1e+30] | Standard error of the mean (from pair averages with antithetic variates) |
Terminal minterminal_minindex_level · [0, 1e+30] | index_level | [0, 1e+30] | Smallest terminal value |
Terminal maxterminal_maxindex_level · [0, 1e+30] | index_level | [0, 1e+30] | Largest terminal value |
Percentile valuespercentile_valuesindex_level (array) · length max 99; each [0, 1e+30] | index_level (array) | length max 99; each [0, 1e+30] | Terminal quantiles at the requested probabilities |
Probability belowprobability_belowprobability · [0, 1] | probability | [0, 1] | Share of paths ending below the level |
Paths simulatedpaths_simulatedcount · [4, 100000] | count | [4, 100000] | Paths simulated |
Nonparametric bootstrap of a statistic (bootstrap): 5 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Nonparametric bootstrap of a statistic | |
Estimateestimateratio · [-1e+07, 1e+07] | ratio | [-1e+07, 1e+07] | Statistic of the sample |
Standard errorstandard_errorratio · [0, 1e+07] | ratio | [0, 1e+07] | Standard deviation of the bootstrap replicates (B - 1) |
Interval lowerinterval_lowerratio · [-1e+07, 1e+07] | ratio | [-1e+07, 1e+07] | Percentile interval, lower |
Interval upperinterval_upperratio · [-1e+07, 1e+07] | ratio | [-1e+07, 1e+07] | Percentile interval, upper |
Calculator
Run the model on your own inputs, starting from its example. Rates are decimals: 0.05 is five percent. The run goes to the pyeconomics API on this site: your values travel only in the request, and nothing is stored.
Loading the calculator…
Worked example
Example one_year_of_a_stock. Inputs:
{
"antithetic": false,
"calculation": "gbm",
"drift": 0.05,
"horizon": 1,
"initial_value": 100,
"level": null,
"paths": 2000,
"percentiles": [0.05, 0.5, 0.95],
"seed": 7,
"steps": 12,
"volatility": 0.2
}Outputs:
{
"calculation": "gbm",
"paths_simulated": 2000,
"percentile_values": [
73.61582146069588,
102.76159375756552,
143.84852061860636
],
"probability_below": 0.453,
"standard_error": 0.4798508476040338,
"terminal_max": 210.5863233759353,
"terminal_mean": 104.70859694696195,
"terminal_min": 55.613885982355285,
"terminal_std": 21.459582286070233
}Assumptions
- GBM steps are exact in log space, so the terminal distribution is lognormal for any number of steps; steps change the draws only.
- With antithetic variates each path is paired with its mirror image, and the standard error comes from the pair averages.
- The bootstrap resamples the sample with replacement; quantiles interpolate linearly between order statistics.
- The same seed gives the same result under one NumPy feature release.
Limitations
- Results are estimates with Monte Carlo error, which the standard error measures; a different seed gives a different estimate.
- Sizes are capped (100,000 paths of 1,000 steps; 10,000 resamples of 1,000 observations); a terminal statistic above 1e30 raises DomainError.
- A percentile interval from a small sample can under-cover; the bootstrap does not correct its bias.
Evidence
Status: standard. Textbook consensus, such as bond duration or the CAPM formula.
Every model declares one status: standard (textbook consensus), practitioner (a widely used convention), contested (under active debate), rejected (failed out of sample) or historical (a superseded methodology).
Syllabus
The 2027 CFA® Program's topic areas this model relates to, as factual tags. Each links to CFA Institute's page for its level; pyeconomics holds none of the curriculum's text.
Citations
- Glasserman, P. (2003). Monte Carlo Methods in Financial Engineering. Springer. https://openlibrary.org/isbn/9780387004518 (Section 3.2 (geometric Brownian motion) and Section 4.2 (antithetic variates)). ISBN 9780387004518
- Efron, B. and Tibshirani, R. J. (1993). An Introduction to the Bootstrap. Chapman & Hall. https://openlibrary.org/isbn/9780412042317 (Chapter 6 (the bootstrap estimate of standard error) and Chapter 13 (percentile intervals)). ISBN 9780412042317
Changelog
- Version 1: First version.
Use it elsewhere
- Documentation
- The model's reference page
- REST API
GET or POST /v1/models/foundations.simulation/run- MCP tool
run_modelwith the model's id,foundations.simulation. Connect an assistant- Command line
pyeconomics models run foundations.simulation --help
The worked example, from Python and from the command line:
import pyeconomics
inputs = {
"antithetic": False,
"calculation": "gbm",
"drift": 0.05,
"horizon": 1,
"initial_value": 100,
"level": None,
"paths": 2000,
"percentiles": [0.05, 0.5, 0.95],
"seed": 7,
"steps": 12,
"volatility": 0.2,
}
result = pyeconomics.run("foundations.simulation", inputs)
print(result.to_json())
pyeconomics models run foundations.simulation --inputs - <<'JSON'
{
"antithetic": false,
"calculation": "gbm",
"drift": 0.05,
"horizon": 1,
"initial_value": 100,
"level": null,
"paths": 2000,
"percentiles": [0.05, 0.5, 0.95],
"seed": 7,
"steps": 12,
"volatility": 0.2
}
JSON