Skip to main content

Module montecarlo

Module montecarlo 

Source
Expand description

Asset-agnostic Monte Carlo machinery, one concern per file — usable as a standalone simulation toolkit and consumed by the equity pricers.

Nothing in this module knows about options, spots or curves: it deals in uniforms, normals, Brownian increments and estimator statistics, so rates, FX, commodity or credit simulations plug in the same way equities do.

  • paths: the public sample_paths API — materialized path matrices over any process, plus the per-path Brownian increment source (PathDraws) the pricing engines share;
  • process: the generic Itô-process / SDE abstraction — drift and diffusion coefficients live in the process, Euler / Milstein are written once against them, closed-form transitions and model-specific schemes are per-process overrides;
  • rng: deterministic pseudo-random generation — SplitMix64 stream derivation and per-path PCG64 streams (bit-reproducible under any thread scheduling), plus seeded standard-normal draws;
  • sobol: multi-dimensional Sobol low-discrepancy sequences (Gray-code, direction numbers, optional seeded digital-shift scrambling), and the 1-D van der Corput normals;
  • halton: Halton sequences with Cranley-Patterson rotation — the arbitrary-dimension quasi-random fallback;
  • brownian_bridge: Brownian-bridge path construction, so the best low-discrepancy coordinates carry each path’s coarse structure;
  • variance_reduction: antithetic pairing, moment matching, and the generic regression-based control-variate estimator;
  • sampling: stratified sampling and Latin hypercube designs;
  • stats: simulation statistics — mean / standard error from accumulated sums and a Welford running accumulator.

Re-exports§

pub use brownian_bridge::BrownianBridge;
pub use halton::QmcSequence;
pub use paths::sample_paths;
pub use paths::sample_paths_1d;
pub use paths::MultiPaths;
pub use paths::PathDraws;
pub use paths::Paths;
pub use paths::SampleConfig;
pub use paths::Sampler;
pub use process::DiscretizationScheme;
pub use process::StochasticProcess;
pub use process::StochasticProcess1D;
pub use rng::path_normals;
pub use rng::path_rng;
pub use rng::pseudo_normal_matrix;
pub use rng::pseudo_normals;
pub use rng::splitmix64;
pub use sampling::latin_hypercube;
pub use sampling::stratified_normals;
pub use sampling::stratified_uniforms;
pub use sobol::sobol_normals;
pub use sobol::SobolSequence;
pub use stats::mean_std_err;
pub use stats::RunningStats;
pub use stats::SimStats;
pub use variance_reduction::control_variate_estimate;
pub use variance_reduction::moment_match;

Modules§

brownian_bridge
Brownian-bridge path construction: the first draw fixes the terminal value, subsequent draws fill midpoints by bisection, so low-discrepancy coordinates are spent on the dimensions that matter most. Weights are precomputed once and shared across paths.
halton
Halton low-discrepancy sequences: prime radical inverses with a seeded Cranley-Patterson rotation. Any number of dimensions, so this is the quasi-random workhorse when the problem’s dimension exceeds the embedded Sobol table (SobolSequence).
paths
Public path generation over the stochastic-process traits — the library’s sample_paths API (the TF-Quant-Finance idiom): give it a process, an initial state and a sampling configuration, get back the simulated paths as a dense matrix, generated in parallel with the same deterministic draw discipline the pricing engines use.
process
Generic Itô-process abstraction: the SDE’s coefficients live in the process object and the discretization schemes are written once against them — the QuantLib StochasticProcess / TF Quant Finance GenericItoProcess pattern.
rng
Deterministic pseudo-random generation for simulation.
sampling
Stratified sampling and Latin hypercube designs — seeded, exact stratification of the unit interval / hypercube.
sobol
Multi-dimensional Sobol low-discrepancy sequences.
stats
Simulation statistics: mean / standard error from accumulated sums (the shape parallel path loops naturally produce) and a numerically stable Welford accumulator for streaming use.
variance_reduction
Variance-reduction building blocks: moment matching and the generic regression-based control-variate estimator. (Antithetic pairing lives where draws are generated — see pseudo_normals — and low-discrepancy sampling in sobol / halton is itself the strongest variance reduction for smooth payoffs.)