# Monte Carlo simulation and probabilistic programming packages

**URL:** https://discourse.julialang.org/t/monte-carlo-simulation-and-probabilistic-programming-packages/111408
**Category:** Modelling & Simulations
**Tags:** turing
**Created:** [March 10, 2024, 12:49am UTC](https://discourse.julialang.org/t/monte-carlo-simulation-and-probabilistic-programming-packages/111408 "2024-03-10T00:49:13Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![askvorts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/askvorts/32/7120_2.png) [@askvorts](https://discourse.julialang.org/u/askvorts)
#### Post date: [March 10, 2024, 12:49am UTC](https://discourse.julialang.org/t/monte-carlo-simulation-and-probabilistic-programming-packages/111408/1 "2024-03-10T00:49:13Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![bertschi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bertschi/32/33462_2.png) [@bertschi](https://discourse.julialang.org/u/bertschi)
#### Post date: [March 10, 2024, 9:00am UTC](https://discourse.julialang.org/t/monte-carlo-simulation-and-probabilistic-programming-packages/111408/2 "2024-03-10T09:00:01Z")

</div>

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](https://github.com/baggepinnen/MonteCarloMeasurements.jl) for representing uncertain numeric quantities:

```julia
using MonteCarloMeasurements

function npv(cashflow, interest_rate)
    d = 1 / (1 + interest_rate)
    sum(v * d^t for (t, v) in pairs(cashflow))
end

```

```julia-repl
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.

---

<div class="post-metadata">

### Author: ![askvorts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/askvorts/32/7120_2.png) [@askvorts](https://discourse.julialang.org/u/askvorts)
#### Post date: [April 4, 2024, 10:16pm UTC](https://discourse.julialang.org/t/monte-carlo-simulation-and-probabilistic-programming-packages/111408/3 "2024-04-04T22:16:32Z")

</div>

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

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [April 5, 2024, 6:12am UTC](https://discourse.julialang.org/t/monte-carlo-simulation-and-probabilistic-programming-packages/111408/4 "2024-04-05T06:12:11Z")

</div>

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.
