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))
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.
- 01Market data
Underlying,ZeroRate, curves - 02Model
HestonProcess,KouProcess, … - 03Configurationpaths, steps, sampling, mode
MonteCarloConfiguration - 04Paths
simulate: N × (steps + 1) - 05Payoffdiscounted, path by path
- 06Metrics
pricer,variance,confinter,delta; AD
Results
Simulated with the package when this site is built.
confinter.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.
Install the package
From the General registry.
] add FinancialMonteCarloDescribe 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)Configure the simulation
10 000 paths of 30 steps.
mcConfig = MonteCarloConfiguration(10_000, 30)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))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.670535882166266The 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.