Monte Carlo Simulation Theory and Applications in Python

The Monte Carlo Simulation is a numerical analysis technique aimed at estimating the possible outcomes of a certain random event. It is a very powerful method of evaluating integrals where there are no known solutions.
The main idea behind this simulation is that the results are computed based on repeated random sampling and statistical analysis. The technique relies on random sampling, the Law of Large Numbers and the Central Limit Theorem.
1. Monte Carlo Approximation
Suppose we wanted to evaluate the integral:

over the domain set 𝐴
We can do so using two different points of view.
a. Using Expectation
We can express this integral as:

Where,
- 𝑋 is a random variable with a probability density function given by ℎ(𝑥)
- 𝐸[𝑔(𝑋);𝐴] represents the expected value of 𝑔(𝑥) over the set 𝐴
This means we can re-express the integral as an expectation of a function of a random variable over a given set
Suppose we have i.i.d. random variables 𝑋1,𝑋2,… with:

meaning the expectation is equal to the mean
Then, as the number of random variables we simulate increases towards infinity, the sample mean converges to the expected value of the function of the random variables:

b. Using a Simple Average
We can take the mean of a function with one variable to understand how to apply the Monte Carlo numerical method to solve for the integral of the function.
Let A be the domain (𝑎,𝑏)

By rearranging the distance of the domain 𝑏−𝑎 to the left-hand side we get:

If we were to represent the different outcomes of this function on a uniformly distributed grid and we take the limit as the distribution goes to zero then we would get as a result the solution to this integral.
However, this is extremely computationally expensive, especially when dealing with multiple dimensions.
Approximating the integral:
By expanding the left-hand side and expressing the mean of 𝑓 as the definition of the average, we get a solution that approximates the actual solution of the integral.

We can approximate the integral by making the 𝑥𝑖 values be a random 𝑥 value on the interval (𝑎,𝑏) and if we take the limit that the number of these 𝑥 values goes to infinity, we will get the value of the integral
2. Simple Integration using the Mean of a Function

We can use Monte Carlo Integration to see how close to this value we can approximate.
We need to:
- Get the function to integrate
- The limits of integration
- Random Number Generator
- Loop though the Monte Carlo equation
- Scale results by (𝑏−𝑎) / 𝑁













