# Monte Carlo Simulation

## Presentation on theme: "Monte Carlo Simulation"— Presentation transcript:

Monte Carlo Simulation
DECISION MODELING WITH MICROSOFT EXCEL Chapter 9 Monte Carlo Simulation Part 2 Copyright 2001 Prentice Hall

An Inventory Control Example:
Foslins Housewares Simulation can be used for models in which the question is “How much of this should we do?” We will now use an inventory control model to provide an illustration of simulation. THE OMELET PAN PROMOTION: HOW MANY PANS TO ORDER? In Foslins, certain sections of the housewares department have just suffered their second consecutive bad year. Due to competition, the gourmet cooking, glassware, stainless flatware, and contemporary dishes sections of Foslins are not generating enough revenue to justify the amount of floor space.

To fight back, the chief buyer reorganized the sections that are in trouble to create a store within a store. With these changes, plus the store’s reputation for quality and service, she feels that Foslins can effectively compete. An “International Dining Month” promotion will be featured in October to introduce the new facility. Five specially made articles (each from a different country) will be featured on sale. For example, a copper omelet pan from France, a set of 12 long-stem wine glasses from Spain, etc. All items must be ordered 6 months in advance. Any unsold items after October will be sold to a discount chain at a reduced price. If they run out, a more expensive item from the regular line will be substituted.

Consider the special omelet pans:
Buying price: \$22.00 Selling price: \$35.00 Discounted price: \$15.00 (at the end of October) Regular pans: Buying price: \$32.00 Normal selling price: \$65.00 Selling price if substituted: \$35.00 Now, without knowing the demand for this special product, how many pans should be ordered in advance?

For example, suppose you order 1000 pans and the demand turned out to be 1100 pans.
In this situation, you would be 100 pans short and would have to buy 100 regular pans and sell them at the sale price in order to make up the deficit. The net profit would be: \$35(1100) - \$32(100) - \$22(1000) = \$12,300 In general, let y = number of pans ordered and D = demand. Then for D > y, Profit = 35D – 32(D – y) – 22y Profit = 3D + 10y

In another scenario, suppose you order 1000 pans and the demand turned out to be 200 pans.
In this situation, you would have an excess of 800 pans and would have to sell the addition pans at \$15 each and take a loss. The net profit would be: \$35(200) + \$15(800) - \$22(1000) = -\$3000 In general, for D < y, Profit = 35D + 15(y – D) – 22y Profit = 20D - 7y For D = y, the two formulas are identical.

This spreadsheet assumes an order of 11 omelet pans and a random demand of 8 (i.e., y = 11 and D = 8). =MAX(0,B3-B5) =MAX(0,B5-B3) =IF(B3>=B5,E3*B5+E4*B7-E5*B3,E3*B5-E8*B9-E5*B3) Since the order quantity is greater than demand, (y >D) there are 3 extra pans. Thus, the profit is \$83.

PROFIT VERSUS ORDER QUANTITY
Now, assume that demand has the following distribution: Prob {demand = 8} = 0.1 Prob {demand = 9} = 0.2 Prob {demand = 10} = 0.3 Prob {demand = 11} = 0.2 Prob {demand = 12} = 0.1 Prob {demand = 13} = 0.1 Note: These demands have been chosen artificially small in order to simplify the example.

To generate random demand for this probability distribution in Crystal Ball, enter this discrete distribution in a two-column format for Crystal Ball.

Now, click on cell B5. Next, click on the Define Assumptions icon, choose Custom distribution and click OK.

In the resulting dialog, click on the Data button

Now, enter the spreadsheet cell range where the discrete distribution was placed and click OK.

After clicking OK, the distribution will be displayed:
Click OK again to accept these settings.

To determine the expected profit through the use of the simulations, click on cell B11 and then click on the Define Forecast icon. If not already selected, choose Large as the window size and When Stopped (Faster). Click OK.

In order to use simulation to calculate the average profit, first generate a number of trials, setting y = 11. The profit that results on any given trial depends on the value of demand that was generated on that trial. The average profit over all trials is the expected profit. To do this, click on the Run Preferences icon and change the Maximum Number of Trials to 500. Click OK.

Next, click on the Start Simulation icon and after Crystal Ball has run the 500 iterations, the following dialog will appear: Click OK and Crystal Ball will automatically produce a histogram.

To look at the statistics from the simulation, go to the Crystal Ball View menu and choose Statistics. Based on these trials, the best estimate of the expected profit of ordering 11 omelet pans is \$ Note that since both the demand and the average profit are random variables, running the simulation again will most likely result in a different average profit.

Expected Value versus Order Quantity
Expected Value versus Order Quantity. To calculate the true expected profit using the spreadsheet and Crystal Ball, simply enter each demand in cell B5 (one at a time), run the simulation and then record the average profit. These average profits will then be multiplied by their respective probabilities. The sum of these values will give the true expected profit.

Simulated versus Expected Profits
Simulated versus Expected Profits. For any particular order quantity, the average profit generated by the spreadsheet simulator does not equal the true expected profit. The implication of this fact on the process of making a decision is interesting. The computed expected profits and simulated average profits for order sizes of 9, 10,11, and 12 pans are shown below: Based on the max. profit, your decision would be to order 10 pans for the true expected profit or 11 pans for the simulated average profit.

The previous example illustrates that simulation, in general, is not guaranteed to achieve optimality. A simple way to increase the likelihood of achieving optimality is to increase the number of trials. With simulation, your decision may be wrongly identified if care is not taken to simulate a sufficient number of trials. In a real problem you would not both calculate the true expected profit and use simulation to calculate an average profit. Use simulation when it is computationally impractical or not even possible to calculate the expected profit associated with the alternative decisions, or when it is important to assess the variability of the performance measure for various solutions.

RECAPITULATION To summarize: 1. A spreadsheet simulator takes parameters and decisions as inputs and yields a performance measure(s) as output. 2. Each iteration of the spreadsheet simulator will generally yield a different value for the performance measure. 3. The performance measure (for an order size of 11) was profit. The 500 trials taken together combine to produce a measure of goodness of the order size: average profit.

More information can be obtained from the simulation. Suppose you want to know how often a shortage occurred (i.e., demand exceeded quantity ordered), click on cell B9 and add it as a “Forecast” cell. Then, rerun the simulation. The results show that a shortage occurred in 95 of the 500 trials (20.6%). Indicators of variability are also important products of simulation studies. Management usually seeks policies which have low variability.

6. Management must assess four main factors :
4. Increasing the number of simulation iterations will usually improve the accuracy of the estimate of the expected value of the performance measure. 5. In a simulation, we can never be sure that the optimal decision has been found. Although, a % or 99% confidence interval can be calculated. 6. Management must assess four main factors : a. Does the model capture the real problem? b. Are the influence of the starting and ending conditions of the simulation properly accounted for? c. Have enough trials been performed for each decision so that the average value of the measure(s) of performance is a good indication of the true expected value? d. Have enough decisions been evaluated so that you can believe that the best answer found is “close enough” to the optimum?

Simulation of Foslins’ Model with a More Realistic Demand Assumption
Previously with the Foslins model, we had assumed a simplified demand distribution. However, a more realistic model of demand is the normal distribution with a mean of 1000 and a standard deviation of 100. The Foslins’ Spreadsheet: Simulating Demand More Realistically. To simulate 1000 trials, modify the Run Preferences dialog to indicate the larger number of iterations. In addition, use the same 1000 random values for demand in each of the upcoming simulations (for different order quantities for comparison). This is known as setting the seed value.

The Foslins’ Spreadsheet: Simulating Demand More Realistically
The Foslins’ Spreadsheet: Simulating Demand More Realistically. In the spreadsheet, change the quantity ordered to 1020. Also, change the random distribution of demand from a customized one to the normal distribution with a mean of 1000 and a standard deviation of 100.

To simulate 1000 trials, click on the Run Preferences icon and change the number of iterations.

Now, specify the seed value:
First, click on Sampling in the Run Preferences dialog. Check the use Same Sequence … option and enter an Initial Seed Value of 422 (or any other number). Click OK. Note that the demands do not change. We want to compare the average profit for different order quantities but the same set of random demands. Profit will differ only because of different order quantities.

Variance Reduction is the process of decreasing variability in simulation results.
It is an important technique in reducing the amount of computation necessary to obtain valid simulation results. With simulation, using the same sequence of random variables provides us with complete control of the random elements. THE EFFECT OF ORDER QUANTITY Click on the Start Simulation icon to begin the simulation. After 1000 iterations, the following dialog will open. Click OK to bring up a histogram of the profit values.

Here is the resulting histogram.
You can view the statistics by clicking on the View – Statistics menu option. The average profit for an order quantity of 1020 pans is \$12,

You can determine how the average profit varies for a range of order quantities and a given set of demands by entering different order quantities in cell B3. First, place a new order quantity in cell B3. Click on the Reset Simulation icon and in the resulting dialog, click OK. Now, you can begin the simulation again by clicking on the Start Simulation icon. Finding the optimal order quantity is an iterative procedure -- change the order quantity and re-run the simulation. Then, compare the profits to find the maximum profit.

For example, suppose you ran 1000 iterations at each of the following order quantities:
Expected Profit Order Quantity 1010 1013 1015 1016 1017 1018 1020 1025 1030 \$12,268.95 \$12,264.60 \$12,270.29 \$12,270.77 \$12,270.70 \$12,268.34 \$12,270.76 \$12,270.71 \$12,270.44 So, this iterative process has shown that an order quantity of 1017 gives a maximum profit of \$12,

However, this quantity that maximizes profit may not maximize the true expected profit. Indeed, it may be impossible to guarantee that the optimal solution will be found using simulation. Remember, the optimal solution is theoretical as opposed to a real-world concept. At best, an optimal solution represents a “good decision” for the real-world problem. Since the average profit for order quantities between 1015 and 1018 only varied by a couple of pennies, even if we didn’t get the exact optimal order quantity, we are confident that we are “close enough.”

The Probability Distribution of Profit
The Probability Distribution of Profit. To find out more about the solution suggested by simulation (ordering 1017 pans), we can look at the probability distribution. This histogram visually describes the range of risk that Foslins will be taking in ordering 1017 pans. The peaked distribution means that there is a definite probability that the profit will exceed the mean profit. The area to the left means that there is some chance of obtaining a profit below the expected profit. However, there is little chance of loosing money.

Airline Overbooking Model
Midwest Express: Airline Overbooking Model Here is a revenue management example from the service industry. The airlines were the first to pioneer the use of these tools. American Airlines (AA) started the practice of auctioning off the value of a seat on a given flight when more customers showed up than it had seats available. AA estimates that overbooking alone adds over \$200 million per year to its bottom line. Other areas besides overbooking that are practiced in the revenue management area include forecasting, seat allocation among the various fare classes, and control of the entire network of flight legs.

Midwest Express is headquartered in Milwaukee, Wisconsin and was started by the large consumer products company Kimberly Clark, which has large operations in nearby Appleton, Wisconsin. After reviewing the historical data on the percentage of no-shows, it was found that the average no-show rate for Flight 227 from Milwaukee to San Francisco is 15%. The aircraft (MD88) has a capacity of 112 seats in a single cabin. As all service is considered premium, there is no First Class/Coach cabin distinction. Demand for this primarily business route is strong and the average fare is \$400.

If only 112 reservations are accepted, then the flight will almost certainly go out with empty seats because of the no-shows. These no-shows represent an opportunity cost for Midwest Express. On the other hand, if more reservations than seats are accepted, then even after accounting for the no-shows, there will still be a risk of overbooking seats. The normal procedure in the event that a customer is denied boarding, is to put the “extra” customers on the next available flight and provide them with some compensation (a free flight in the future, a voucher for a free meal and a hotel, etc.). On the average, the compensation usually costs Midwest Express around \$600.

The more reservations that are accepted, the less likely there will be empty seats, but the likelihood that a customer will be denied boarding is increased. The goal is to find the optimal overbooking level that maximizes profit. =RiskSimtable({112,114,116,118,120,…,144,146}) =RiskBinomial(B10,1-B7) This model assumes that the fares are fully refundable (if they don’t show, they don’t pay). =MAX(0,B12-B3) =MAX(0,B3-B12) =B12*B5-B14*B6

You can perform multiple trials since the value returned will change every time the spreadsheet is recalculated by pressing F9. In order to see the random values returned for each iteration, to Monte Carlo by clicking on the Settings icon and then on the Sampling tab. In the Standard Recalc section, click on Monte Carlo.

Now, use simulation to determine the optimal overbooking level
Now, use simulation to determine the optimal overbooking level. To see which value maximizes Midwest Express’ profit, consider the range of reservations from 112 to 146 in increments of 2. To do this, enter the following formula into cell B10: =RiskSimtable({112,114,116,118,120,…,144,146}) Now, click on the @Risk icon. In the resulting Simulations Settings dialog, click on the Iterations tab. Change the number of iterations to 1000 and the number of simulations to 18.

Now, click on cell B19 and then click on the Add Output Cell icon to add this cell to the simulation. Click on the Run Simulation icon to start the simulation. The Simulating dialog will appear in which you can observe the status of the simulation.

@Risk automatically displays the results of these 18 simulations:
Click on the Merge Sim#’s button.

The following information will be displayed.
As shown in Sim#1, if only 112 reservations are accepted, the avg. profit would be \$38,080. As the no. of reservations are increased, the avg. profit increases then starts to decline. The max. profit of \$43,901 occurs at 134 reservations.

Capacity Balancing Now, let’s explore the assertion that capacity should be “balanced” throughout a manufacturing plant. MODELING A WORK CELL Consider the following work cell: WIP holds it in a temporary storage area if the 2nd work station is busy, Raw Material This cell takes a raw material, and then processes it at WS2. WS2 processes it at the first work station (WS1), WS1

The completed part is used in assembly at the rate of 3 per hour.
The goals are to Meet the demand for this part on the assembly line, Keep work in process (WIP) between the two work stations down Minimize the capacity of the work stations subject to achieving the first two goals.

SIMULATING BALANCED CAPACITY
Since the assembly area needs the part at a rate of 3 per hour, set the capacity of both work stations at 3 per hour. The Capacities of WS1 and WS2 are balanced. However, because of processing time variability, a work station might be able to process anywhere from 1 to 5 units per hour. Suppose that during any given hour, a work station will have the capability of processing 1, 2, 3, 4, or 5 units with equal probability (discrete uniform distribution). Then the average output of that work station will be 3 units per hour provided it always has something on which to work.

Assume that sufficient raw material will always be available to WS1 so that it will never be starved. However, because the processing times are variable at WS1, there may be times when WS2 is idle for lack of material.

The Initial Conditions
The Initial Conditions. The following spreadsheet displays the first 16 simulated hours of operation of the work cell. =B10 + C10 – E10 =MIN(B10,D10) =F10 =AVERAGE(\$F\$10:F10) The initial conditions at the beginning of the first hour of the simulation are no work in process (WIP), and WS1 and WS2 are idle.

Now, enter a discrete uniform random number generator in cell C10 (WS1 Output) and cell D10 (Potential WS2 Output) to produce one of 5 possible values with equal probability. First, type in the data in a tabular format for Crystal Ball.

Now, to enter the discrete uniform random number generators for WS1 Output and Potential WS2 Output in Crystal Ball, click on cell C10 and enter = CD.Custom(\$C\$2:\$D\$6) With the cursor still on cell C10, click on Excel’s Copy icon and then highlight the range C10:D25. Next, click on Excel’s Paste icon to copy the uniform discrete distribution to all 32 of these cells. Highlight cells G10, G13, G16, G19, G22, and G25. Click on the Define Forecast icon and change the Window size to Large and the Display to When Stopped (faster) and click OK. Repeat this step for each of the 6 forecast cells, or use the Copy/Paste feature with the forecast cells.

Click on the Run Preferences icon and change the Maximum Number of Trials to 1000 and click OK.
Now click on the Start Simulation icon and after Crystal Ball has run the 1000 iterations, it automatically produces an individual histogram for each of the 6 forecast cells.

To better view these, click on Run – Open Trend Chart.
Crystal Ball plots the distribution of Average WIP over the first 16 hours by using the six selected hours that we indicated. The center band indicates the mean + 25% and the next darker band is a 95% confidence interval. This shows that the Average WIP seems to be growing slightly over the first 16 hours.

Beyond the Initial Conditions
Beyond the Initial Conditions. Now, expand the simulation beyond the 16 hours by copying the formulas down for another 184 hours. Re-run Crystal Ball using the same basic steps as in the previous example. The resulting graph of avg. WIP for the first 200 hours of operation shows a continual growth. The longer the cell is in operation, the greater the amount of WIP that accumulates. Here, the average arrival rate and the average service rate are equal when the capacities of the two work stations are balanced. Hence, the unexpected growth.

SIMULATING UNBALANCED CAPACITY
Now, let’s add capacity to WS2 so that its average production rate is 3.5 units per hour (using a discrete uniform distribution between 2 and 5 units). Using the data from the previous spreadsheet, add the following distribution for Workstation 2: Now, change the formulas in cells D10:D209 to be: = CD.Custom(\$G\$2:\$H\$5) Select six forecast cells, spread evenly across the 200 hours and run 1000 iterations.

The resulting graph of average WIP over time shows a much lower average WIP.
These results suggest that there is no long-term growth in the Average WIP with the steady-state value lying somewhere between 5 and 7 units.

In conclusion, the capacity of the two work stations should not be balanced (equal output rates).
If WIP is to be kept to reasonable levels, then the downstream work station (WS2) should have a somewhat greater capacity. By running the simulation for longer periods of time, the effect of the initial conditions can be overcome, and the true long-term behavior can be discerned. In general, simulation results are useful only when care is taken in the experimental design to eliminate extraneous effects such as starting or ending conditions. Simulations that are too short may give misleading results.

Optimization Under Uncertainty
We can now combine the optimization tools that we’ve discussed with the ability to do Monte Carlo simulation. Let’s demonstrate the use of optimization under uncertainty with OptQuest (available with Crystal Ball Pro) on two very common examples – portfolio allocation and project selection. Suppose that we can choose to invest in one of three stocks – Intel, Microsoft, and Proctor & Gamble, or in a money market account. Let W represent the fraction invested in Money Market X represent the fraction invested in Intel stock Y represent the fraction invested in Microsoft stock Z represent the fraction invested in P&G stock

Historically, based on the last 9 years, the average annualized return has been:
46.6% Intel 62.1% Microsoft 20.8% Procter & Gamble 5.2% Money Market The constraints are: No more than 50% of the portfolio is to be in any one asset. The sum of the decision variables must be 100%. In order to optimize the portfolio, we can either maximize return subject to a constraint to keep the risk at some satisfactory level or minimize risk subject to a constraint to keep the return at some satisfactory level.

In this example, we will be minimizing risk
In this example, we will be minimizing risk. Set up a spreadsheet as shown below. =AVERAGE(C2:C10) =COVAR(\$C\$2:\$C\$10,C2:C10) =COVAR(\$D\$2:\$D\$10,D2:D10) =COVAR(\$E\$2:\$E\$10,E2:E10) =COVAR(\$F\$2:\$F\$10,F2:F10) =SUM(C17:F17) =C17*C11 SUMPRODUCT(MMULT(C17:F17,C13:F16),C17:F17)

Here are the Solver results.
These show that you should invest in 0.51% of Intel, 20.7% of Microsoft, 50% of P&G, and 28.8% of money market accounts. The minimum variance is

Now let’s use Crystal Ball with OptQuest. Perform the following steps:
1. Change cells C11:F11 to numbers rather than formulas. Highlight cells C11:F11 and click on Edit – Copy and then click Edit – Paste Special – Values and click OK. 2. Click on the Define Assumption icon to specify the distribution for cells C11:F11. Specify each as a normal distribution with the following parameters, respectively: Standard Mean Deviation 46.6% .5646 62.1% .3999 20.8% .1334 5.2% .0141

3. Click on the Define Forecast icon and select cell H17 (Portfolio Variance).
4. Click on the Run Preferences icon and change the maximum number of trials to Also, select Latin Hypercube as the sampling method and Use Same Sequence as the random 5. Click on the Define Decision icon and define the decision variables as cells C17:F17 (each as a continuous variable with lower bound of 0% and upper bound of 50%. Select the variable type as continuous.

6. Click on the OptQuest icon to start the program.
7. In OptQuest, select File – New – Yes to optimize all decision variables. Check that the Type Column indicates that these are continuous values and click OK.

8. Define the constraints as follows:
a. Intel% + Microsoft% + P&G% + MM% = 1 b. Intel% <= 0.5 c. Microsoft% <= 0.5 d. P&G% <= 0.5 e. MM% <= 0.5 f *Intel% *Microsoft% *P&G% *MM% >=0.25

9. From the Select menu, choose Minimize Objective and click OK.
10. In the Options window, click OK to accept the default process. To start the optimization under uncertainty, click Yes.

After 10 minutes, you should get results similar to the following:

11. To interpret the results, select Edit – Copy to Excel which will copy the resulting values for the decision variables back into your spreadsheet and automatically give a frequency diagram for the chosen statistic. In the Forecast window, you can also select View – Statistics to view the summary statistics. The OptQuest engine basically gave the same answer as Solver (in a much longer period of time). The result from OptQuest confirmed that after running 1,000 random iterations, the average portfolio variance was indeed closely represented by the mean values used in our original spreadsheet, which Solver used to optimize.

PROJECT SELECTION Consider the R&D group at a major public utility that has identified eight possible projects for the coming year. Each project has an initial investment required and the resulting NPV from a proforma cash flow analysis has also been tabulated. The CFO of the company has only authorized \$2 million to be spent on R&D projects for the coming year. If implemented, these 8 projects would require an investment of \$2.8 million, so we much choose those projects which will return the largest NPV and still remain within the budget.

Set up the model for optimization using binary decision variables (yes/no) for each of the eight potential projects. =SUMPRODUCT(E5:E12,C5:C12) =SUMPRODUCT(D5:D12,E5:E12) =C14 - C15

The resulting solution from Solver shows that projects 1, 2, 3, 4, and 7 should be chosen with the maximum NPV obtained of \$3.55 million and using all \$2 million of the budget. This is an application of integer programming where the NPVs are assumed to be certain. Now add some uncertainty to the success of each project.

Now, due to the uncertainty of each project succeeding, re-optimize with Solver (maximize cell G15, changing cells are E5:E12, constraint: C15 <= C14). This gives a new solution that recommends projects 1, 2, 4, 6, 7, with an expected NPV of \$2.184 million and spending only \$1.85 million of the budgeted \$2 million. How do we know if this is the best decision, given all the uncertainty? With OptQuest we can specify that it maximize the 25th percentile of the NPV distribution that results from a simulation of 1000 trials. Then, for each possible combination of decision variables (28 = 256 combinations), the software will make “intelligent” choices as it searches for the best combination.

To set this up in OptQuest, follow the steps outlined below:
1. Click on the Define Assumption icon and define the assumption cells as F5:F12 (each as a binomial with success rate as given in the original spreadsheet, and 1 trial). 2. Define the decision variables as cells E5:E12 (each as a discrete variable with lower bound of 0, upper bound of 1). 3. Click on the Define Forecast icon and specify cell G15 with “NPV” as Forecast name and “Dollars” as the forecast units. 4. Click on the Run Preferences icon and specify a maximum number of trials equal to 1,000. Also, specify Latin Hypercube and Use same sequence with an initial seed value of 999.

5. Now, start OptQuest by clicking on its icon or by going to the Tools – OptQuest pull-down menu.
6. In OptQuest, click on File – New and select Yes to optimize all decision variables. Check that the Type column indicates that these are discrete values. 7. Define the single constraint as: 250*Project *Project *Project *Project *Project5 + 30*Project *Project7 + 70*Project 8 <= 2000

8. From the Select drop-down menu, select Maximize Objective and change the Forecast Statistic from the Mean to the Percentile and enter the number 25. 9. In the Options window, click OK to accept the default process. To begin the optimization under uncertainty, click Yes.

10. To interpret the results, select Edit – Copy to Excel to copy the resulting values for the decision variables to the spreadsheet and automatically provide frequency diagrams of the chosen statistic (NPV). Under View switch to Cumulative Chart and enter the right-hand side value as \$1.6 million.

In the Forecast window, you can also select View – Statistics to view the summary statistics.

The results from OptQuest showed that the best projects to choose are 1, 2, 5, 6, 7 which spend \$1.98 million of the budget and generate a maximum 25th percentile value of \$1.6 million.