Monte Carlo Simulation

    Real life is full of uncertainty. That does not mean you have to leave everything to chance. There is a way to put numbers on uncertainty, and that is exactly what Monte Carlo Simulation does. Before we get into it, let's start with the idea of a Random Variable.

    What is a Random Variable?

    You already know this:

    Profit = Revenue - Expense

    Looking back at last year is easy. You know your revenue and you know your expense. You plug both numbers into the formula and you get a profit figure. One known number out, two known numbers in.

    Predicting next year is a different story. You do not know what your revenue or your expense will be, so you cannot just calculate a single profit figure.

    You might try to list out the possibilities by hand, like this:

    If Revenue is $100 and Expense is $20, Profit is $80.
    If Revenue is $200 and Expense is $30, Profit is $170.
    .........
    The trouble is there is no end to it. Revenue and expense can each take on endless values, so the number of combinations is endless too. You cannot do that by hand.

    Here is the better way. Based on your experience and your past records, you can usually describe revenue and expense as probability distributions instead of single guesses. Once you do that, you can work out profit as a probability distribution too.

    So the formula turns into this:

    Probability Distribution of Profit = Probability Distribution of Revenue - Probability Distribution of Expense

    That raises a fair question. How do you subtract one probability distribution from another? A distribution is not a single number you can type into a calculator and hit the minus button.

    The answer is Monte Carlo Simulation. It lets you treat Profit as a random variable when Revenue and Expense are random variables.

    Monte Carlo Simulation works by taking many random samples. So let's be clear about what random sampling really means.

    Random Sampling

    Picture this probability wheel, like a roulette wheel.

    Roulette-style probability wheel used to introduce Monte Carlo simulation, with the wheel divided into Red (75 percent) and Blue (25 percent) sectors.
    Roulette-style probability wheel used to introduce Monte Carlo simulation, with the wheel divided into Red (75 percent) and Blue (25 percent) sectors.

    If you spin this wheel and let it stop, what would you expect on average, red or blue? Out of every 4 spins, you would expect about 3 reds and 1 blue. That is because red covers 75% of the wheel and blue covers 25%. In other words, the result follows a probability distribution: red is 0.75 and blue is 0.25. Random sampling is just that idea put to work. You build a wheel that matches a probability distribution, then spin it to draw a sample.

    For example, say you have a probability distribution like this:

    Triangular probability distribution example used to illustrate how a random sample can be drawn from a continuous distribution during Monte Carlo simulation.
    Triangular probability distribution example used to illustrate how a random sample can be drawn from a continuous distribution during Monte Carlo simulation.

    To draw a random sample from this distribution, you build a wheel where every possible outcome gets its own slice. The size of each slice matches that outcome's probability. Look at the triangular distribution above. The value 30 has a probability of 0.02. So on the wheel there is a slice for the value 30, and it takes up 2% of the wheel. Spin that wheel and stop it 100 times, and you would expect the slice for 30 to come up about twice. Every probability distribution has a math formula for this kind of wheel. Most of those formulas are messy to work out by hand. The good news is that when you use the SpiceLogic Rational Will or Decision Tree Software, the software does all of that math for you, so you can stay focused on the decision itself.

    How Monte Carlo Simulation evaluates a function of random variables

    So far you know what a random variable is and what random sampling is. Now suppose you are the project manager on a new project, and you need to predict the profit. From your past data, you have worked out a probability distribution for both Revenue and Cost.

    Say your Revenue follows a Normal Distribution, shown below.

    Normal probability distribution used to model the uncertain Revenue input in the Monte Carlo simulation walkthrough.
    Normal probability distribution used to model the uncertain Revenue input in the Monte Carlo simulation walkthrough.

    And your Expense follows a Triangular Distribution, shown below.

    Triangular probability distribution used to model the uncertain Expense input in the Monte Carlo simulation walkthrough.
    Triangular probability distribution used to model the uncertain Expense input in the Monte Carlo simulation walkthrough.

    As we said earlier, you could try to write out endless combinations like:

    Combination 1: Revenue $500, Expense $300
    Combination 2: Revenue $501, Expense $301
    ….
    .....
    You would be buried in no time. There is no practical way to list them all by hand.

    This is where Monte Carlo Simulation steps in. The idea is simple. Draw one random sample from the Revenue distribution. Say you get $500. Then draw one random sample from the Expense distribution. Say you get $200. So for this first round, profit is $500 - $200 = $300.

    Now draw again. Say this time Revenue is $400 and Expense is $300. So for the second round, profit is $100.

    Keep repeating, usually 10,000 times or more.

    After thousands of samples, you can sort the results into a histogram. The X-axis shows ranges of profit, and the Y-axis shows how many of your random samples landed in each range.

    Histogram of 10,000 Monte Carlo samples of the Total Combined Cost of Item A and Item B, with the number of occurrences in each thousand-dollar bucket from 1k to 20k.
    Histogram of 10,000 Monte Carlo samples of the Total Combined Cost of Item A and Item B, with the number of occurrences in each thousand-dollar bucket from 1k to 20k.

    From the chart above, you can read off that out of 10,000 samples, 200 landed in the profit range of $1,000 to $2,000, 300 landed in the $2,000 to $4,000 range, and so on.

    Since you have a count for each range, you can turn each count into a probability. Just divide the sample count in a range by the total number of samples (10,000).

    So the probability of the $1,000 to $2,000 range is 200 / 10,000 = 0.02. Do that for every range and you end up with the probability distribution of profit, like this:

    Risk profile derived from the Monte Carlo histogram by converting each bucket's sample count into a probability, showing the Total Combined Cost of Item A and Item B distribution.
    Risk profile derived from the Monte Carlo histogram by converting each bucket's sample count into a probability, showing the Total Combined Cost of Item A and Item B distribution.

    This method of finding the probability distribution of a dependent random variable is what we call Monte Carlo Simulation.

    Step by Step Modeling Example

    Let's model the function we have been talking about, Profit = Revenue - Expense, where both Revenue and Expense are random variables.

    Start the Decision Tree Analyzer and build a simple tree like the one below, with just one Decision Node and one action.

    Starting state of the Monte Carlo walkthrough, with the Payoff button on the node flyover menu highlighted as the first step.
    Starting state of the Monte Carlo walkthrough, with the Payoff button on the node flyover menu highlighted as the first step.

    The first time you click the "Pay off" button in a project, the software asks whether you want a regular single or multiple criteria analysis, or a Cost-Effectiveness analysis. Choose the first option.

    Payoff type selection dialog offering regular single or multi-criteria analysis versus Cost-Effectiveness analysis on the first Payoff click in a project.
    Payoff type selection dialog offering regular single or multi-criteria analysis versus Cost-Effectiveness analysis on the first Payoff click in a project.

    You will then see the screen below. Select "Maximize" and type in "Revenue", as shown here.

    Objective creation wizard with Maximize selected and Revenue entered as the criterion name.
    Objective creation wizard with Maximize selected and Revenue entered as the criterion name.

    Click the "Proceed" button. The software asks what type of criterion this is. Select "Numerical Type".

    Objective wizard step asking the criterion type for the Revenue criterion, offering Subjective Type or Numerical Type cards as choices.
    Objective wizard step asking the criterion type for the Revenue criterion, offering Subjective Type or Numerical Type cards as choices.

    Next you are asked for a minimum value, a maximum value, and a unit. Use $ as the unit, 0 as the minimum, and $1000 as the maximum.

    Objective wizard step for Revenue, with minimum 0, maximum 1000 and unit set to dollar sign.
    Objective wizard step for Revenue, with minimum 0, maximum 1000 and unit set to dollar sign.

    Click "Proceed". The software asks whether you have another criterion to add. Click Yes. Then, in the same way, create a numerical objective called "Minimize Expenses".

    When that second criterion is done and you are asked whether to add another, answer "No".

    Wizard prompt asking whether another criterion needs to be added, answered No after Revenue and Expenses are defined.
    Wizard prompt asking whether another criterion needs to be added, answered No after Revenue and Expenses are defined.

    Now you are asked to set up a trade-off between the two criteria. This forms a multi-criteria utility function. You have several choices here, such as pairwise comparison, a custom expression, and more. For this example, choose the Custom Multi-Criteria Utility Function from the screen below.

    Multi-criteria trade-off setup screen offering Pairwise comparison, Custom Multi-Criteria Utility Function and other options for combining the two criteria.
    Multi-criteria trade-off setup screen offering Pairwise comparison, Custom Multi-Criteria Utility Function and other options for combining the two criteria.

    When you click the Custom Multi-Criteria Utility Function box, a math equation editor opens up. In this editor you can write full math expressions, for example sqrt([Revenue]) - ln([Expenses]). Our expression is much simpler. It is just [Revenue] - [Expenses], so keep it exactly as shown here.

    Custom Multi-Criteria Utility Function editor with the rich math expression [Revenue] - [Expenses] entered to define Profit.
    Custom Multi-Criteria Utility Function editor with the rich math expression [Revenue] - [Expenses] entered to define Profit.

    Click the "Proceed" button. You are taken back to the decision tree, and the payoff editor appears. Enter simple values for now: Revenue $500 and Expenses $200. The node shows a value of $300, which is correct, since our custom expression gives Revenue - Expenses = 500 - 200 = 300.

    Payoffs at Investment A panel with Revenue 500 dollars and Expenses 200 dollars entered as numbers, producing Profit 300 dollars on the node label. Callout points to the probability distribution button.
    Payoffs at Investment A panel with Revenue 500 dollars and Expenses 200 dollars entered as numbers, producing Profit 300 dollars on the node label. Callout points to the probability distribution button.

    Now let's give Revenue a probability distribution. Click the probability distribution icon in the Revenue row, shown in the screenshot above. The probability distribution window opens. Click the "Continuous Uniform" distribution, shown below.

    Probability distribution gallery with the Continuous Uniform distribution selected for the Revenue input.
    Probability distribution gallery with the Continuous Uniform distribution selected for the Revenue input.

    We left the default settings as they were and clicked OK.

    Continuous Uniform distribution dialog accepted with its default parameters for the Revenue input in the Monte Carlo walkthrough.
    Continuous Uniform distribution dialog accepted with its default parameters for the Revenue input in the Monte Carlo walkthrough.

    Do the same thing for the Expense criterion. This time, pick the "Exponential" distribution from the gallery. Leave the defaults and click through. The payoff editor in the decision tree will now look like this.

    Payoff editor in the decision tree diagram after assigning a Uniform distribution to Revenue and an Exponential distribution to Expenses.
    Payoff editor in the decision tree diagram after assigning a Uniform distribution to Revenue and an Exponential distribution to Expenses.

    Now for the interesting part. Open the Options Analyzer and look at the Risk Profile chart carousel.

    Keep the action node "Investment A" selected in the diagram and expand the "Node Analyzer" tab. In the Ribbon, under "Monte Carlo Simulation", you will find a number box labeled "Number of Iteration". Set it to 10,000. More iterations give a more accurate result.

    Options Analyzer Risk Profile chart for Investment A after a Monte Carlo run with 10,000 iterations and 12 bins, with a callout pointing to the iteration count input.
    Options Analyzer Risk Profile chart for Investment A after a Monte Carlo run with 10,000 iterations and 12 bins, with a callout pointing to the iteration count input.

    And there it is. You can now see a probability distribution for our random variable "Profit", which equals Revenue minus Expenses. The Decision Tree Analyzer ran a Monte Carlo simulation behind the scenes and produced this distribution. The chart is the result of subtracting one probability distribution from another, exactly as we defined in the custom expression editor.

    If you add a second action node to the Decision Node, the software compares them. The action with the higher expected value is the one it recommends as the better choice.

    In the ribbon there is another number box called Max bin count. A bin is a segment that the simulation results get sorted into. Use a lot of bins and the results spread out evenly across all of them, which often does not tell you much. Use very few bins and the differences between bins stand out more, which can be more useful for many analyses. By default the software uses 12 bins. Let's change it to 5 and see what happens.

    Monte Carlo risk profile chart drawn with 5 bins, showing a coarser segmentation of the simulated Profit distribution.
    Monte Carlo risk profile chart drawn with 5 bins, showing a coarser segmentation of the simulated Profit distribution.

    Now the results are grouped into just a few segments. The screenshot below shows the same risk profile with 9 bins and then with 50 bins, so you can compare.

    Side-by-side comparison of the same Monte Carlo risk profile rendered with 9 bins and with 50 bins, showing how bin count affects the chart's resolution.
    Side-by-side comparison of the same Monte Carlo risk profile rendered with 9 bins and with 50 bins, showing how bin count affects the chart's resolution.

    A real random function as a decision tree

    Let's model something real. Say you are planning a vacation and you can travel by car or by plane. If you drive, your car might break down on the road, and the repair could cost anywhere within a range. And as you know, plane ticket prices never stay still, they change all the time. Assuming you already know how to create a decision tree in the software, let's build one like this:

    Vacation decision tree comparing Go by car (with a 0.3 chance of breakdown) against Go by plane, used for the longer Monte Carlo modeling example.
    Vacation decision tree comparing Go by car (with a 0.3 chance of breakdown) against Go by plane, used for the longer Monte Carlo modeling example.

    Let's say the chance of the car breaking down is 0.3. Set that probability as shown in the screenshot above.

    Now create an objective called "Minimize Cost". From the flyover menu on the "Go by car" node, click the "Payoff" button. The objective wizard opens. Create the "Minimize Cost" objective the same way as before: choose Money type or Number type with the unit "$", a minimum of 0, and a maximum of $1000, as shown below.

    Objective creation wizard configuring the Minimize Cost objective with its allowed payoff range for the vacation example.
    Objective creation wizard configuring the Minimize Cost objective with its allowed payoff range for the vacation example.

    Click Proceed. When you are asked whether there are any more objectives to add, answer "No". You are then taken to the decision tree, like this.

    Vacation decision tree with the Payoffs at Go by car panel open and a callout pointing to the probability distribution button next to the Cost objective.
    Vacation decision tree with the Payoffs at Go by car panel open and a callout pointing to the probability distribution button next to the Cost objective.

    Now think about the cost of driving. It could land anywhere from $100 to $500, because you cannot be sure about gas prices along the way, how much food you will buy, and so on. Still, your best guess is that it will probably come in around $300, with $100 or $500 being less likely. A normal distribution with a mean of $300 fits that picture well. Click the probability button in the payoff editor and choose "Normal Distribution" this time.

    Probability Distributions gallery dialog with a 'Select Normal' callout pointing at the Normal thumbnail, the chosen distribution for the Car cost.
    Probability Distributions gallery dialog with a 'Select Normal' callout pointing at the Normal thumbnail, the chosen distribution for the Car cost.

    Once you pick the normal distribution, you can set the mean and the standard deviation.

    Detail view of the Normal Distribution editor where the mean and standard deviation for the Car cost are specified.
    Detail view of the Normal Distribution editor where the mean and standard deviation for the Car cost are specified.

    Click OK to accept the distribution you set up. The decision tree will now look like this.

    Vacation decision tree updated to show the Car cost node carrying a Normal probability distribution as its payoff.
    Vacation decision tree updated to show the Car cost node carrying a Normal probability distribution as its payoff.

    Now set a probability distribution for the car breakdown cost. You figure it could be somewhere between $400 and $800, but you have no idea which value is most likely. So a uniform distribution is a good fit. This follows the principle of indifference: if you have no reason to believe one outcome is more likely than another, you treat them all as equally likely. Since you cannot guess what kind of breakdown might happen, give every value in the range the same chance with a continuous uniform distribution. Just like the driving cost, attach a uniform distribution that runs from 400 to 800, like this:

    Uniform distribution chosen for the Car break down cost, modeling a 400 to 800 dollar range without committing to a most likely value.
    Uniform distribution chosen for the Car break down cost, modeling a 400 to 800 dollar range without committing to a most likely value.

    Now set a distribution for the plane cost. Your best guess for the most likely price is $400, but it could be higher or lower, perhaps anywhere from $300 to $700. You could use a triangular distribution or a normal distribution, whichever you feel more confident about. A triangular distribution makes good sense here, like this:

    Triangular distribution chosen for the Plane ticket cost, with most likely 400 dollars and a range from 300 to 700 dollars.
    Triangular distribution chosen for the Plane ticket cost, with most likely 400 dollars and a range from 300 to 700 dollars.

    With all of that in place, the decision tree will look like this.

    Final vacation decision tree with normal, uniform and triangular probability distributions assigned to every uncertain cost, ready for Monte Carlo simulation.
    Final vacation decision tree with normal, uniform and triangular probability distributions assigned to every uncertain cost, ready for Monte Carlo simulation.

    The modeling is done. Now expand the Options Analyzer panel to see all the calculated results. And here is the nice part: the Monte Carlo simulation has already run for you. Look at the probability distribution in the Risk Profile panel. That distribution is the output of the Monte Carlo simulation.

    Options Analyzer panel showing the Monte Carlo simulation result for the vacation decision tree, with the risk profile automatically generated.
    Options Analyzer panel showing the Monte Carlo simulation result for the vacation decision tree, with the risk profile automatically generated.

    You can resize the panels for a clearer view, as shown below. Notice that Stochastic Dominance is also worked out from the risk profile. Expand the Stochastic Dominance panel to see the dominance diagram.

    In the Risk Profile chart, switch to the CDF view to see the Cumulative Distribution Function, which is a clearer way to read stochastic dominance. Also tick the Continuous View checkbox, shown in the screenshot below, for a smoother graph.

    Stochastic Dominance panel and dominance diagram computed from the Monte Carlo risk profile for the vacation example.
    Stochastic Dominance panel and dominance diagram computed from the Monte Carlo risk profile for the vacation example.

    How the result was calculated

    So the SpiceLogic Rational Will or Decision Tree Software produced the probability distribution in the Risk Profile panel. But how? It built thousands of random samples, like this:

    1. It drew a random sample from the cost distribution on the "Go by car" node. Call that value "p". Then, using the probability wheel, it picked an outcome at the chance node based on the event probabilities (0.3 for the car breaking down). If the "Car breaks down" branch came up on the wheel, the software drew a random sample from the breakdown cost distribution. Call that value "q".

    So in the first round, the total cost is "p + q".

    2. It repeated this process thousands of times, producing a large set of outcomes. The software then chose to show the results in up to 100 groups. It works out a group width so the outcomes fall into at most 100 groups. In the screenshot above, the tooltip shows the group "-932.36 to -920.36", and the probability of landing in that group is 0.01.

    Options for Monte Carlo Simulation

    By default, Monte Carlo Simulation is turned on automatically whenever a probability distribution is used.

    Monte Carlo Simulation options on the Methods ribbon, with the execution mode dropdown open and showing Always Instantly, Not instantly, and When Probability Distribution Used choices.
    Monte Carlo Simulation options on the Methods ribbon, with the execution mode dropdown open and showing Always Instantly, Not instantly, and When Probability Distribution Used choices.

    You can turn that automatic behavior off by changing the drop-down to "Not Instantly", as shown in the screenshot above. With "Not Instantly" selected, you get a button to run the Monte Carlo simulation by hand, so you can run it whenever you want.

    Methods ribbon in Not Instantly Monte Carlo mode with the Run Monte Carlo Simulation Now button highlighted by a callout for running the simulation on demand.
    Methods ribbon in Not Instantly Monte Carlo mode with the Run Monte Carlo Simulation Now button highlighted by a callout for running the simulation on demand.

    If you set the option to "Always Instantly", then Monte Carlo simulation runs whenever there is at least one chance node in the tree, whether or not any probability distribution is used, and it generates the Risk Profile.

    Last updated on Feb 13, 2022