Manual 01 A few composable objects

Overview

Every computation in FinancialMonteCarlo.jl combines four objects:

modelcurveconfigurationpayoff
ObjectRoleExamples
modelhow the underlying evolvesBlackScholesProcess, HestonProcess, GaussianCopulaNVariateProcess
underlyingspot price and dividendsUnderlying
zero rate curvediscounting and risk neutral driftZeroRate of a number or of a curve
Monte Carlo configurationnumber of paths and steps, method, rng, parallelismMonteCarloConfiguration
payoffthe contractEuropeanOption, BarrierOptionDownOut, positions and portfolios

and a metric applied to them, e.g. pricer:

price = pricer(model, underlying, rfCurve, mcConfig, payoff)

What happens inside pricer

  1. the random number generator in mcConfig is reset to its seed, so results are reproducible;
  2. simulate generates an Nsim × (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);
  3. payoff maps each path to its discounted payout;
  4. 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 mcConfig uses StandardMC() 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:

PackageEnables
CUDAGPU simulation of several models with CudaMode
DistributedMultiProcess parallel mode
StochasticDiffEqMonteCarloDiffEqModel, see StochasticDiffEq.jl
DualNumberscompatibility methods for this number type
VectorizedRNGfast vectorized random number generation