FinancialMonteCarlo.jl

Monte Carlo Pricing and Risk for Equity Derivatives

Simulate Black–Scholes, Heston and Lévy models, price anything from forwards to American options, and get sensitivities by automatic differentiation, on threads, processes or a GPU.

model = HestonProcess(0.4, 0.2, 0.0, 1.5, -0.7, 0.04)
mc    = MonteCarloConfiguration(100_000, 50)
price = pricer(model, Underlying(100.0), ZeroRate(0.02), mc, AmericanOption(1.0, 100.0, false))
Simulated paths of a Heston model, coloured by their final value Simulated paths of a Heston model, coloured by their final value
coloured by the spot at one year 160 paths of a Heston model over one year, simulated with FinancialMonteCarlo.jl when this site was built.
6.2 ms
100 000 paths × 50 steps on a laptop GPU, Float32
39×
GPU in Float32 against one CPU thread, at a million paths
9 models
Black–Scholes, Heston, Kou, Merton, VG, NIG, mixtures, plus copulas
7
AD backends through the simulation, Enzyme and Mooncake included

European call under Black–Scholes, Intel Core i7-8550U and NVIDIA MX150, see Performance.

What it does

Everything is built around a small set of composable objects: any model with any payoff, simulation method or parallel mode, and parameters that can be dual numbers.

Single-name models

Black–Scholes, Bachelier, Heston, Kou, Merton, Variance Gamma, NIG, lognormal mixtures, and any of them shifted, on Brownian engines.

From textbook to jumps and stochastic volatility with one interface.

Multivariate

Gaussian copulas over any single-name models, for baskets and portfolios.

Correlated underlyings without a new model.

Payoffs

Forwards, European, binary, barrier, Asian, Bermudan and American (Longstaff–Schwartz), baskets and smiles.

Every metric works for every payoff.

Positions and portfolios

Payoffs combine with + and *; portfolios on many underlyings price against a market data set.

A book priced in one call, from one stream of random numbers.

Sampling

Standard, antithetic, control variates, Sobol sequences, any AbstractRNG.

Variance reduction without touching the model.

Threads, processes, GPU

MultiThreading, MultiProcess and CudaMode: the mode is part of the configuration.

Results that do not depend on the number of threads or workers.

Automatic differentiation

DualNumbers, HyperDualNumbers, TaylorSeries, ForwardDiff, ReverseDiff, Mooncake, Enzyme.

Pathwise Greeks of any payoff from the price function.

Custom SDEs

Any SDE written with StochasticDiffEq.jl, priced like the built-in ones.

Prototype a model before writing its simulation.

How it fits together

Every metric reduces to one pipeline: simulate the paths, evaluate the payoff on them, average.

  1. 01Market dataUnderlying, ZeroRate, curves
  2. 02ModelHestonProcess, KouProcess, …
  3. 03Configurationpaths, steps, sampling, mode
    MonteCarloConfiguration
  4. 04Pathssimulate: N × (steps + 1)
  5. 05Payoffdiscounted, path by path
  6. 06Metricspricer, variance, confinter, delta; AD
FinancialFFT.jl, VibratoMonteCarlo.jl and FinancialCalibrator.jl add their own methods to the same pricer ← one interface for simulation, Fourier and calibration

Results

Simulated with the package when this site is built.

Simulated paths of three modelsSimulated paths of three models
Paths. Twenty-four paths of Heston, Kou and Variance Gamma over one year.
Monte Carlo price and confidence interval against the formulaMonte Carlo price and confidence interval against the formula
Convergence. A Black–Scholes call against the number of paths, with its 95% confidence interval from confinter.
Density of the log-return at maturity for three modelsDensity of the log-return at maturity for three models
Distributions. The density of the log-return at one year, from 20 000 paths of each model.

Keep in mind

Keep in mind

First order automatic differentiation works with every payoff, including those for which the derivative of the Monte Carlo estimator is meaningless (e.g. binary and barrier options). Second order automatic differentiation works too, but the results are seldom useful. Multi-currency is not supported.

Quick start

Five steps, every output computed when this site was built.

1

Install the package

From the General registry.

] add FinancialMonteCarlo
2

Describe the market and the model

σ = 20%, S₀ = 100, a dividend yield of 1%, a flat rate of 2%.

using FinancialMonteCarlo

model = BlackScholesProcess(0.2)
underlying = Underlying(100.0, 0.01)
rfCurve = ZeroRate(0.02)
3

Configure the simulation

10 000 paths of 30 steps.

mcConfig = MonteCarloConfiguration(10_000, 30)
4

Price an option

And its 95% confidence interval.

option = EuropeanOption(1.0, 100.0)
(price = pricer(model, underlying, rfCurve, mcConfig, option), interval = confinter(model, underlying, rfCurve, mcConfig, option, 0.95))
(price = 8.243560026581395, interval = (7.982721737614266, 8.504398315548524))
5

Price a position

Payoffs on the same underlying combine into one contract.

position = EuropeanOption(1.0, 100.0) - 2 * BinaryEuropeanOption(1.0, 110.0)
pricer(model, underlying, rfCurve, mcConfig, position)
7.670535882166266

The ecosystem

FinancialFFT.jl (Fourier methods), VibratoMonteCarlo.jl (smooth Greeks) and FinancialCalibrator.jl (calibration) extend the pricer of this package with methods of their own, on the same models and payoffs. The test suite runs with ] test FinancialMonteCarlo. More projects at rcalxrc08.github.io.