Examples#

This gallery walks through every public feature of financialkit.monte_carlo: crude Monte Carlo with error bars, variance reduction, quasi-Monte Carlo, Monte Carlo Greeks and multilevel Monte Carlo. Each script illustrates one dated breakthrough from the history page.

See also the narrative tutorial:

Each script in this gallery is self-contained and can be run directly with python examples/monte_carlo/<section>/<script>.py.

Sections#

  • basics – the Monte Carlo method of Metropolis and Ulam, Box-Muller normal variates and Boyle’s option prices.

  • variance_reduction – Neyman stratification, importance sampling, antithetic variates, Latin hypercube sampling, control variates and moment matching.

  • quasi_monte_carlo – Halton and Sobol sequences, the Koksma-Hlawka inequality, Owen scrambling, Paskov-Traub’s high-dimensional integrals and the Brownian bridge.

  • greeks – likelihood-ratio and pathwise Greeks.

  • multilevel – Giles’s multilevel Monte Carlo.

Crude Monte Carlo#

Expectations as sample means with standard errors and confidence intervals, normal variates from uniforms, and option prices by simulation.

Metropolis-Ulam: the Monte Carlo method

Metropolis-Ulam: the Monte Carlo method

Box-Muller normal variates

Box-Muller normal variates

Boyle: options by Monte Carlo

Boyle: options by Monte Carlo

Monte Carlo Greeks#

Sensitivities without bump-and-reprice: the likelihood-ratio and pathwise estimators, checked against the Black-Scholes Greeks.

Glynn: likelihood-ratio Greeks

Glynn: likelihood-ratio Greeks

Broadie-Glasserman pathwise Greeks

Broadie-Glasserman pathwise Greeks

Multilevel Monte Carlo#

Giles’s telescoping sum over Euler discretisations of increasing resolution, and its cost against standard Monte Carlo.

Giles multilevel Monte Carlo

Giles multilevel Monte Carlo

Quasi-Monte Carlo#

Low-discrepancy points instead of random ones: Halton and Sobol sequences, the Koksma-Hlawka error bound, randomized QMC with error bars, and high-dimensional path integrals with and without the Brownian bridge.

Halton sequences

Halton sequences

Koksma-Hlawka and discrepancy

Koksma-Hlawka and discrepancy

Sobol sequences

Sobol sequences

Owen scrambling: randomized QMC

Owen scrambling: randomized QMC

Paskov-Traub: QMC in high dimension

Paskov-Traub: QMC in high dimension

Caflisch-Moskowitz Brownian bridge

Caflisch-Moskowitz Brownian bridge

Variance reduction#

The same expectation from fewer samples: stratification, importance sampling, antithetic variates, Latin hypercubes, control variates and moment matching, each compared with crude Monte Carlo.

Neyman stratification

Neyman stratification

Kahn-Marshall importance sampling

Kahn-Marshall importance sampling

Hammersley-Morton antithetic variates

Hammersley-Morton antithetic variates

McKay-Beckman-Conover Latin hypercube

McKay-Beckman-Conover Latin hypercube

Lavenberg-Welch control variates

Lavenberg-Welch control variates

Barraquand moment matching

Barraquand moment matching

Gallery generated by Sphinx-Gallery