Skip to Main Content

This article explains what Monte Carlo simulation is, how it works, and common applications. It provides examples of advantages, disadvantages, and tools used in the process.

What is Monte Carlo Simulation?

Monte Carlo simulation is a set of algorithms used to predict the probabilistic outcomes of a process when its inputs vary randomly. Also referred to as the Monte Carlo method, Monte Carlo analysis, or Monte Carlo experiments, the algorithms are a type of stochastic simulation.

To understand the distribution of possible outcomes, Monte Carlo simulations run a large number of trials, each with a different set of random inputs. The simulation results from each trial are then analyzed to determine the probability distribution of uncertain variables.

The concept of Monte Carlo simulation emerged from the Manhattan Project and subsequent nuclear weapons development programs. In 1946, Stanislaw Ulam and John Von Neumann sought to determine the probability distribution of energy released when a neutron collided with an atomic nucleus. A colleague suggested the name "Monte Carlo" because his uncle gambled at the Monte Carlo Casino in Monaco, and the random selection of input variables reminded them of roulette's randomness.

Most processes are deterministic because the outputs are known for any given set of inputs. As an example, if you add a known amount of heat to a known amount of water at a known temperature, you can calculate how much the temperature rises. But it is difficult to predict outcomes in a more complex system where inputs are random, and the process itself is complex. Engineers, scientists, mathematicians, and economists use Monte Carlo simulations to incorporate randomness into forecasts of outcomes in such systems. 

Microsoft Excel Example of Monte Carlo Simulation

A good way to understand this powerful simulation tool is to look at a simple example. A classic problem is predicting how many times flipping four coins will result in zero, one, two, three, or four heads showing.

The input variable is the number of coins, and the output variable we want to predict is the probability of each combination of heads. A simple Excel Monte Carlo simulation uses the random number function, rand(), to predict heads or tails by setting a cell to one (heads) if the random number is less than 0.5 and zero (tails) if it is more than 0.5. The model consists of a table with one column per coin, one row per trial, and a sum column to compute the number of coins that showed heads. To calculate probabilities, the model uses countif() to count the number of times each possibility occurred, then divides that by the number of trials. 

monte carlo example excel four coin
monte carlo excel formula

A simple four-coin Monte Carlo simulation in Microsoft Excel. The results are shown at the top of the image and the formulas used at the bottom. A new result is calculated every time the spreadsheet is refreshed.

How To Conduct a Monte Carlo Simulation

Monte Carlo simulations use algorithms to solve problems by sampling from a large set of random inputs. Anyone using this tool must define the process he or she is simulating, identify the inputs and outputs, run the simulation, and review the results.

Here are the specific steps:

1. Understand the Process

Start the simulation by defining the process to model. This can be a physics problem, a stock market, the weather in a specific region, or a biological process.

2. Define the Independent Variables and Their Distribution

The next step is to capture all the independent variables. These are characteristics of the process that variables can represent. They should also be characteristics that change the process's behavior when they change. Independent variables are also called input variables, input values, or simply inputs.

In this step, investigators must also define the minimum and maximum values for each independent variable and the distribution, or variability, within that range of values. There are many types of distributions. Here are the most common:

  • Uniform Distribution: Any value within the specified range is just as likely as any other value, forming an even or uniform distribution.
  • Normal Distribution: In nature and finance, values tend to cluster around a central mean, with values being less likely to occur the further you look away from that mean, called a normal distribution. Many people refer to such a distribution as a bell curve because it looks like a bell when plotted on a graph.
  • Triangular Distribution: When there is limited real-world data, as in project management, engineers will use the minimum, most likely, and maximum values to form a triangular distribution rather than a bell curve. The most probable value may not be the mean.
  • Binomial Distribution: When an input value for a process can only have two possible values (zero or one, yes or no, true or false, heads or tails, etc.), investigators use a binomial distribution.
  • Poisson Distribution: A Poisson distribution captures input parameters that have two possible values. However, it accounts for the frequency of a given value over time. Visits to a store would be a good example of this.
  • Empirical Distribution: In complex systems, the distribution of a given input variable may not follow any of the common characteristics. However, when there is enough historical data to plot the distribution, an empirical or custom distribution can be used.

3. Define the Dependent Variables

The third step is to define the process's dependent variables. These are measurable characteristics that change when the input variables change. Dependent variables should also be metrics that matter to people. Minimizing or maximizing a dependent variable is the typical goal of an optimization study. Or teams use the possible results to inform decision-making. Dependent variables are also called output variables, output values, or result values.

4. Create a Simulation of the Process

The critical step is to create an accurate representation of the process as a computer algorithm. This can be a simple equation, a lookup table, or a more complex representation as a numerical model. The simulation should run as quickly and efficiently as possible.

5. Run Simulations Repeatedly With a Random Set of Input Variables

The Monte Carlo simulation itself consists of running a large number of trials using the simulation model. The algorithm uses the range of values and distribution for each input to create random values for each input variable. The tool then captures the different outcomes from each trial.

The process under study determines the number of simulations required to obtain an accurate distribution of output values. Some problems require 1,000 to 10,000 runs. But certain processes may need 100,000 or more trials.

6. Analyze the Output Variables

Once all output values are collected, the next step is to apply statistical methods to estimate the probability of each outcome. If the output variable has a normal distribution, the mean and standard deviation values represent the probability distribution. In simple cases, the probability of a given value is the count for a given outcome divided by the number of trials.

For more complex systems and applications, especially the training of machine learning models, investigators use a Bayesian analysis.

Typical Applications for Monte Carlo Simulation Across Industries

People use Monte Carlo simulations for probabilistic modeling across a wide range of industries. Here is a look at some of the most common applications:

Engineering

Engineers use Monte Carlo methods across applications because they often need to design complex systems with no historical data or simple, deterministic models. Outside of design, they also use it for project management to conduct sensitivity analyses and risk management for their project planning. The most common usage is in numerical simulations for complicated systems to understand the statistical behavior of a product and the relationship between input and output variables. One of the best examples is neutron transport, in which engineers calculate how neutrons pass through and interact with the structural components in a nuclear reactor.

Oil, Gas, and Mining

Extracting natural resources from the earth involves predicting a project's economic viability amid numerous unknowns. The industry uses Monte Carlo simulations to help predict reservoir sizes, porosity, the quality of the resources they are extracting, and even the price of that commodity in the future. One of the more common uses is to model the geology in a potential oil field using probabilistic distributions for the composition, porosity, and thickness of different layers of rock, in addition to what the oil distribution is for each combination. People then run a Monte Carlo simulation to get a distribution of potential oil concentrations. Instead of predicting the exact amount of oil in a given location, they calculate the probabilistic distribution of the oil.

Financial Markets

Few things in the world have more complexity and randomness than financial markets. Economists and financial analysts use Monte Carlo methods to predict stock prices, volatility, interest rates, consumer prices, and other key economic variables. Commodity traders use the Monte Carlo method to stress-test the price of a commodity they own over time. They model the sensitivity of price to dozens of different market-impacting changes and then use a random selection of events over time to get a distribution of possible prices for each day. The result is a value at risk (VAR) for their portfolio.

Physics, Chemistry, and Biotechnology

The Monte Carlo method was initially developed for nuclear physics and remains a key part of modeling radiation in systems such as reactors, radiation therapy, and detectors. Chemists use it as a foundation for computational chemistry and statistical mechanics when modeling chemical reactions or developing new molecules because the mechanisms they study are impossible to calculate analytically. The same is true for biotechnology, where researchers use the method to interpret drug trial results, assess patient response rates, and design new drugs.

A common use of Monte Carlo for drug discovery is for molecular docking simulation. Chemists want to find a small molecule (a key) that fits into a protein (a lock). If the molecule fits into the protein, it can suppress unwanted chemical reactions. Instead of modeling every shape and rotation for the small molecule, a random distribution of both finds the lowest energy combinations that researchers can then focus on. 

Advantages and Disadvantages of the Monte Carlo Method

People use Monte Carlo simulations across many applications because of their advantages. But the approach also has some disadvantages worth consideration before applying it to a real-world problem.

Here is a list of the most common advantages and disadvantages:

Advantages

  • Models complex problems.
  • Generates probabilistic results.
  • Provides sensitivity information for input variables, indicating how strongly a change to those variables impacts an output variable’s value.
  • Captures input distribution.

Disadvantages:

  • Requires significant computational resources for complex systems with many input and output variables and a computationally complex numerical model.
  • Reacts strongly to input data quality (garbage in, garbage out).
  • Produces a false sense of precision because it can produce a lot of statistical information. However, the calculated distributions are only as good as the input parameters and the accuracy of the model.
  • Presents a labor-intensive process due to the time needed to create and verify an accurate model.

Tools Used for Monte Carlo Simulation

There are generally three types of tools used to conduct Monte Carlo simulations: math software, custom programs, and simulation software.

Each has its own advantages and challenges, as outlined below.

Math Software

Software tools such as Microsoft Excel, Google Sheets, Mathematica, and MATLAB are powerful for performing calculations and handling statistical distributions of input and output variables. The spreadsheet tools lack dedicated Monte Carlo capabilities, so users must build their simulations from the ground up. Math-specific tools, especially those with strong statistics modules, make creating random variables easier, automate the trial runs, and perform probabilistic analysis on the results. The biggest challenge for this class of tools is creating an accurate model of the process.

Custom Programs

Custom programs are good when subroutines in a programming language can represent the process. Libraries exist in most languages to support tasks such as creating the input distributions for the random variables and for processing the dependent variables that result. The downside of this approach is that the user must create a custom program for each application, including the model for the process being studied. Programming platforms like Python make this easier, but it can still take some time to set up and debut the simulation.

Simulation Software

The most powerful tool set — and the most common for real-world applications — is simulation software. These programs model the process under study and often include built-in tools that simplify Monte Carlo setup and automate trial-case execution.

A great example of this is the Ansys Optics suite: Ansys Zemax OpticStudio optical system design and analysis software for Monte Carlo simulations of optical systems and Ansys Lumerical software for the highly stochastic behavior found in photonics. Both tools help users build parametric models that support Monte Carlo simulation. 

optimization interface lumerical

The optimization interface for Ansys Lumerical software

The same is true for the flagship Ansys simulation software tools: Ansys Mechanical structural finite element analysis software, Ansys LS-DYNA/LS-Opt nonlinear dynamics structural simulation software, Ansys Fluent fluid simulation software, the Ansys Maxwell advanced electromagnetic field solver, and Ansys HFSS high-frequency electromagnetic simulation software. Each of these tools focuses on simulating a specific subset of physics. Still, they all support parameterization of input and output variables, provide Monte Carlo simulation tools, and support statistical post-processing.

If the built-in tools for a given simulation platform are insufficient, users can integrate them with optimization tools such as Ansys optiSLang process integration and design optimization software. This general-purpose optimization and process integration tool has inherent strengths for Monte Carlo simulation runs and integrates with both Ansys, part of Synopsys, and non-Ansys simulation tools, providing a single, automated platform. It also leverages a robust Python interface that connects the program to other software or Python routines. 

monte carlo tolerance zemax

The Monte Carlo tolerance interface for Ansys Zemax OpticStudio optical system design and analysis software

Artificial Intelligence (AI)

Researchers and mathematicians have used Monte Carlo simulations for many different AI applications for some time. Here are a few examples:

  • Machine learning using training and optimization, Bayesian analysis, and confidence assessment
  • Monte Carlo Tree Search for large-scale decision-making
  • Reinforcement learning
  • Training neural networks
  • Refining large language models (LLMs)

The Ansys SimAI cloud-enabled AI platform for simulation is a strong example of a modern AI tool that leverages Monte Carlo simulation to generate training data for models.

Related Resources

Optical and Radiometric Simulation for Biomedical Applications

This webinar explores concepts for calculating the light propagation in biological tissues and for determining scattering and absorption spectra of biological tissues.

Ansys HFSS + SynMatrix AI: Low-Loss Planar Filters

Discover how planar filters are now essential in RF and microwave systems, offering compact, cost-effective, and high-frequency solutions compatible with PCB technology in this presentation.

Using Machine Learning Algorithms as part of Reliability Analysis Workflows for Digital Validation of Advanced Driver Assistance Systems

This presentation addresses challenges of digital validation using reliability analysis approaches and introduces workflows of reliability algorithms and machine learning.