Monte Carlo simulation and probabilistic programming packages

I’m trying to find Julia packages to perform (financial) quantitative analysis under uncertainty, typicaly by Monte Carlo simulation. Somewhat similar to Oracle Crystal Ball or Palisade @RISK. Found MCHammer.jl that seems great. However the last commit was almost two years ago and the documentation link appears to be broken. I am wondering if alternatively, Turing, Gen or some other probabilistic programming package could be easily adapted for this purpose. Any suggestion would be much appreciated!

1 Like

Not sure what these libraries are doing exactly, but from a quick look on Crystal Ball it seems to do little more than propagation parameter uncertainties forward. To this end, I would start with MonteCarloMeasurements for representing uncertain numeric quantities:

using MonteCarloMeasurements

function npv(cashflow, interest_rate)
    d = 1 / (1 + interest_rate)
    sum(v * d^t for (t, v) in pairs(cashflow))
end
julia> r = 0.02 ± 0.003  # 2% ± 30 basis points
0.02 ± 0.003 Particles{Float64, 2000}

julia> cashflow = Dict(0:3 .=> [-2, 1, 1, 1]);

julia> npv(cashflow, r)
0.883966 ± 0.0169 Particles{Float64, 2000}

In case, you need to simulate more complicated stochastic model DifferentialEquations.jl has stochastic differential equations. For fitting/calibrating models, Turing.jl or similar libraries would be a good start.

It might well be that libraries more specific to financial modeling exist, I’m just not aware of them.

3 Likes

While primarily known for Bayesian inference, I am wondering if Turing.jl can also be used for uncertainty propagation through Bayesian methods?

Turing is a tool for solving the inverse problem, i.e., given some output, infer the distribution of the input. This is a much harder problem in general, and typically makes use of a much wider set of tools, e.g., automatic differentiation and HMC.

1 Like