Manual 01 A few composable objects
Overview
Every computation in FinancialMonteCarlo.jl combines four objects:
| Object | Role | Examples |
|---|---|---|
| model | how the underlying evolves | BlackScholesProcess, HestonProcess, GaussianCopulaNVariateProcess |
| underlying | spot price and dividends | Underlying |
| zero rate curve | discounting and risk neutral drift | ZeroRate of a number or of a curve |
| Monte Carlo configuration | number of paths and steps, method, rng, parallelism | MonteCarloConfiguration |
| payoff | the contract | EuropeanOption, BarrierOptionDownOut, positions and portfolios |
and a metric applied to them, e.g. pricer:
price = pricer(model, underlying, rfCurve, mcConfig, payoff)What happens inside pricer
- the random number generator in
mcConfigis reset to its seed, so results are reproducible; simulategenerates anNsim × (Nstep + 1)matrix of paths of the underlying, from time zero up to the maturity of the payoff (or the largest maturity, when pricing several payoffs);payoffmaps each path to its discounted payout;- the average over the paths is returned.
All the other metrics (variance, confinter, delta, rho, ...) reuse the same steps.
Choosing the implementation by dispatch
There is no switch statement anywhere: the right simulation is selected by multiple dispatch on the types of the arguments. For example, the same simulate call on a BlackScholesProcess runs
- standard Monte Carlo when
mcConfigusesStandardMC()sampling, - antithetic sampling when it uses
AntitheticMC(), - Sobol low discrepancy sequences when it uses
SobolMC(), - a GPU kernel when its mode is a
CudaMode(with CUDA.jl loaded),
and accounts for time dependent rates when rfCurve is a curve instead of a scalar.
Generic number types
All structs are parametric in the type of each of their numeric fields, and the numeric type of the output is inferred from all the inputs. A dual number anywhere (volatility, spot, rate, maturity, strike, ...) therefore propagates through the whole computation, see Automatic differentiation.
Optional integrations
Some features are package extensions, loaded only when the corresponding package is loaded in the same session:
| Package | Enables |
|---|---|
CUDA | GPU simulation of several models with CudaMode |
Distributed | MultiProcess parallel mode |
StochasticDiffEq | MonteCarloDiffEqModel, see StochasticDiffEq.jl |
DualNumbers | compatibility methods for this number type |
VectorizedRNG | fast vectorized random number generation |