Skip to content

Foundations

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

St+Δt=Stexp⁡((μ−12σ2)Δt+σΔt Z)S_{t + \Delta t} = S_t \exp\left((\mu - \tfrac{1}{2}\sigma^2)\Delta t + \sigma \sqrt{\Delta t}\, Z\right)E[ST]=S0eμT,SE=s/NE[S_T] = S_0 e^{\mu T}, \quad \mathrm{SE} = s / \sqrt{N}se^B=1B−1∑b(θ^b∗−θˉ∗)2,[θ^(α/2)∗,θ^(1−α/2)∗]\widehat{se}_B = \sqrt{\frac{1}{B - 1}\sum_b (\hat\theta^*_b - \bar\theta^*)^2}, \quad [\hat\theta^*_{(\alpha/2)}, \hat\theta^*_{(1-\alpha/2)}]

Where

StS_t
The value at time t
S0S_0
The value now initial_value
μ\mu
Drift per year drift
σ\sigma
Volatility per year volatility
Δt\Delta t
The length of one step, in years
ZZ
A standard normal draw
E[ST]E[S_T]
The expected value at the horizon, which the simulated mean estimates terminal_mean
TT
Horizon, in years horizon
SE\mathrm{SE}
Standard error of the simulated mean standard_error
ss
Standard deviation of the simulated values at the horizon terminal_std
NN
Number of simulated paths paths_simulated
se^B\widehat{se}_B
Bootstrap standard error of the statistic standard_error
BB
Number of resamples resamples
θ^b∗\hat\theta^*_b
The statistic computed on resample b
α\alpha
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
Inputs of the calculation gbm
NameDescription
CalculationcalculationtextMonte Carlo of geometric Brownian motion
Initial valueinitial_valueindex_level · [0.01, 1e+06]Value at time 0
Driftdriftrate · [-1, 1]Expected growth rate mu, continuous, per year
Volatilityvolatilityvolatility · (0, 3]Volatility per year
Horizonhorizonyears · (0, 30]Time to the horizon, in years
Stepsstepscount · [1, 1000]Time steps per path
Pathspathscount · [4, 100000]Number of simulated paths
AntitheticantitheticflagPair each path with its mirror image (rounds paths up to even)
Percentilespercentilesprobability (array) · length min 1, max 99; each [0, 1]Probabilities at which to report terminal quantiles
Levellevelindex_level · [0.01, 1e+09]Level for the probability of ending below; null for the start
Seedseedcount · [0, 9.0072e+15]Random seed (ADR-0008 decision 7): the same seed, the same draws
Nonparametric bootstrap of a statistic (bootstrap): 6 inputs
Inputs of the calculation bootstrap
NameDescription
CalculationcalculationtextNonparametric bootstrap of a statistic
Samplesampleratio (array) · length min 2, max 1000; each [-1e+06, 1e+06]The observed sample
StatisticstatistictextThe statistic to bootstrap (standard deviation: n - 1)
Resamplesresamplescount · [2, 10000]Number of bootstrap resamples
Confidenceconfidenceprobability · [0.5, 0.999]Coverage of the percentile interval
Seedseedcount · [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
Outputs of the calculation gbm
NameDescription
CalculationcalculationtextMonte Carlo of geometric Brownian motion
Terminal meanterminal_meanindex_level · [0, 1e+30]Mean terminal value
Terminal stdterminal_stdindex_level · [0, 1e+30]Standard deviation of terminal values
Standard errorstandard_errorindex_level · [0, 1e+30]Standard error of the mean (from pair averages with antithetic variates)
Terminal minterminal_minindex_level · [0, 1e+30]Smallest terminal value
Terminal maxterminal_maxindex_level · [0, 1e+30]Largest terminal value
Percentile valuespercentile_valuesindex_level (array) · length max 99; each [0, 1e+30]Terminal quantiles at the requested probabilities
Probability belowprobability_belowprobability · [0, 1]Share of paths ending below the level
Paths simulatedpaths_simulatedcount · [4, 100000]Paths simulated
Nonparametric bootstrap of a statistic (bootstrap): 5 outputs
Outputs of the calculation bootstrap
NameDescription
CalculationcalculationtextNonparametric bootstrap of a statistic
Estimateestimateratio · [-1e+07, 1e+07]Statistic of the sample
Standard errorstandard_errorratio · [0, 1e+07]Standard deviation of the bootstrap replicates (B - 1)
Interval lowerinterval_lowerratio · [-1e+07, 1e+07]Percentile interval, lower
Interval upperinterval_upperratio · [-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

  1. 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
  2. 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_model with 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:

Python
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())
Command line
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