# Optimize Monte Carlo Simulation

**URL:** <https://discourse.julialang.org/t/optimize-monte-carlo-simulation/112032>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [March 24, 2024, 6:15am UTC](https://discourse.julialang.org/t/optimize-monte-carlo-simulation/112032 "2024-03-24T06:15:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fourier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fourier/32/38176_2.png) [@Fourier](https://discourse.julialang.org/u/Fourier)\
**Post date:** [March 24, 2024, 6:15am UTC](https://discourse.julialang.org/t/optimize-monte-carlo-simulation/112032/1 "2024-03-24T06:15:51Z")

</div>

I have a monte carlo simulation that runs in an external program that I can call using julia. I would like to optiize the simulation result with respect to parameters in the simulation input.  
The values I get out of it, of course have a certain error, so there might not be a disctinct maximum at the current resolution and running the code twice will not give you the same result. However the error is within the 1% range.  
Depending on the resulution the simulation can take several seconds to run.

What would be a good way to tackle this challenge? Are there any julia packages that can help me?

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [March 24, 2024, 7:42am UTC](https://discourse.julialang.org/t/optimize-monte-carlo-simulation/112032/2 "2024-03-24T07:42:40Z")

</div>

Key questions:

- How many parameters are there to optimize?
- Is there a way to get gradients of your simulation code?

At first glance this sounds like a typical use case for Bayesian Optimization but I’m no expert in this part of the ecosystem

---

<div class="post-metadata">

**Author:** ![Fourier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fourier/32/38176_2.png) [@Fourier](https://discourse.julialang.org/u/Fourier)\
**Post date:** [March 24, 2024, 7:55am UTC](https://discourse.julialang.org/t/optimize-monte-carlo-simulation/112032/3 "2024-03-24T07:55:20Z")

</div>

Thanks for the tip 😃. We will focus on 4 parameters, two of which should allready be pretty optimal. No unfortunately it is impossible to get the gradient, as the code is written in C++.

Thanks a lot, basian optimization seems to be what I am looking for!

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [March 24, 2024, 9:49am UTC](https://discourse.julialang.org/t/optimize-monte-carlo-simulation/112032/4 "2024-03-24T09:49:05Z")

</div>

Honestly for such a low-dimensional input you may even want to look at black box, derivative-free optimization

---

<div class="post-metadata">

**Author:** ![PeterSimon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petersimon/32/25193_2.png) [@PeterSimon](https://discourse.julialang.org/u/PeterSimon)\
**Post date:** [March 24, 2024, 3:15pm UTC](https://discourse.julialang.org/t/optimize-monte-carlo-simulation/112032/5 "2024-03-24T15:15:23Z")

</div>

Concur. I suggest the OP have a look at [NOMAD](https://github.com/bbopt/NOMAD.jl), which is designed for expensive black box optimization.
