You are on page 1of 24

IS102

Computer as an Analysis Tool


Week 5: Monte Carlo Simulation
Reading:
Chapter 6: Risks and Uncertainties

Instructor:
Associate Professor Guo Zhiling
School of Information Systems
zhilingguo@smu.edu.sg

Review:
Solver for optimization
Decisions
Objectives
Constraints

Lookup functions
Vlookup
Lookup
Index and Match

Echo Office Supplies Solution Steps


1.

Compute projected sales revenue before price discount


1)
2)
3)

2.

Compute projected sales revenue using new price table


1)
2)
3)

3.

Use Vlookup() to check unit price based on projected demand,


and compute projected sales for each project
Use Sum() to sum up projected sales for different customer types
in the summary section
Use Match() and Index() to display information such as projected
sales of selected customer
Perform the same steps as in 1.1) and 1.2) using new price table
Construct constraints LHS and RHS
Construct objective function cell

Prepare solver inputs


1)
2)
3)

Define objective function


Define constraints
Solve!

Solver Definition
Decision variables = new price table
Constraints
Drop projected revenue for big customers as a group as
much as 9%
(Revenue before Revenue after)/ Revenue before >= 9%

Drop projected revenue for other customers as a group


as much as 5%
(Revenue before Revenue after)/ Revenue before >= 5%

Drop projected revenue for each of the five big


customers at least 8%
(Revenue before Revenue after)/ Revenue before >= 8%

Objective function = maximize total profit

Solver Constraints

>=
3

>=
1

Agenda Today
Excel Functions for Simulation
RAND(), RANDBETWEEN(bottom, top)

Simulating Data
From frequency bins
By re-sampling discrete/continuous data
SMALL(), PERCENTILE()

Exercises
MonteHall.xls
DataSim.xls

Monte Carlo Simulation


Monte Carlo Simulation refers to simulating
scenarios repeatedly using random generation of
input variables to the model
Random generation of input variables can be obtained
from known distribution (uniform, normal, etc.)
We can analyze the results obtained from multiple
scenarios to determine desired outputs

Excel Functions for Simulation


RAND()
RANDBETWEEN(bottom, top)

Useful Excel Functions for Simulation


RAND()
Returns a random number between 0 and 1 (excluding
1); that is, [0,1)
Represents a continuous uniform distribution where
each number is equally likely to occur
A new random number is returned every time the
worksheet is calculated
Number generated is usually used as the cumulative
probability number
To generate a random number between continuous numbers MIN
and MAX (e.g.1-9), use: RAND()*(MAX-MIN)+MIN
To generate a random number between 2 non-contiguous numbers
MIN and MAX (e.g.1 & 3), use: IF(RAND()<0.5,MIN,MAX)

Useful Excel Functions for Simulation


RANDBETWEEN(bottom, top)
Returns a random integer number defined between
bottom and top (inclusive)
Represents a discrete uniform distribution where each
number is equally likely to occur
A new random integer number is returned every time the
worksheet is calculated
Number generated is usually used as a position number
E.g., =RANDBETWEEN(1,6)

Exercise 1: Monte Hall


Lets Make A Deal
Suppose you're on a game show, and you're given the
choice of three doors:
Behind one door is a grand prize;
behind the others, nothing.
Monte Hall

You pick a door, and the host, who knows what's behind
the other doors, opens another door which is empty.

He then asks you whether you would stay with your initial selection or
you would switch to the other remaining door?'
Question: Should you switch?

Monte Hall Worksheet


Step 1 (modelling the game)
Randomly generate prize door
Randomly generate selected door
Determine which door to reveal (using reveal door options matrix)

Step 2 (modelling strategies)


Stay: Determine the door number if contestant decides to stay to original
choice
Switch: Determine the door number if contestant decides to change door
(using change door options matrix)

Random: Half of the time Stay and half of the time Switch

Step 3 (evaluating outcome)


Determine if the contestant wins for the 3 strategies in Step 2, using 1 to
represent Win and 0 to represent Not Win
Calculate the winning probability for each strategy
Determine the best strategy

Exercise 1: Monte Hall


Reveal Door Options
This table allows us to determine which door to open and reveal
given prior knowledge of the prize door and selected door
Selected Door

Prize
Door

RB(2,3)

If(RAND()>0.5,1,3)

RB(1,2)
RB = randbetween()

Revealed door = INDEX(array, prize door, selected door)

Exercise 1: Monte Hall


Change Door Options
This table allows us to determine which door to change given prior
knowledge of revealed door and selected door
Selected Door
1
1
Revealed
Door

2
1

1
RB = randbetween()

Changed door = INDEX(array, revealed door, selected door)

Exercise 1: Monte Hall


Evaluate if Win/Not Win
Evaluate if the final selected choice in Step 2 is the
same door as the prize door
We want to return the result of the evaluation to be 1 or
0
Compute the probability of winning using AVERAGE()
We can use formulas such as:
=If(Door choice = prize door, 1, 0)
=(Door choice = prize door) * 1

Probability of Winning
If prize is at door 2, we can have 3 possible scenarios
where the contestant can choose one of the 3 possible
doors.
We try to determine the probability of winning if the
contestant change door
Either door 1 or 3
can be opened

3
Open

If change door from


1 to 2 = Win

Open

Open

If change door from


2 to 1 = Lose

If change door from


3 to 2 = Win

Probability of winning if changing the door = 2/3

Simulating Data
1. Cumulative Relative Frequency (CRF) Table
2. Re-sampling
3. Inverse Distribution

Simulating More Data Points


Method 1: Using Frequency Bins
Build CRF table and use RAND() function to match CRF to
get new X
Different ways to build CRF table (i) frequency count, (ii)
percentage of occurrence, and (iii) distribution functions

Method 2: Using Re-sampling


Discrete Data
SMALL(array, RANDBETWEEN(1,N))

Continuous Data
PERCENTILE(array, RAND())

Method 3: Using Inverse Distribution


Discrete distribution (Uniform, Poisson, Binomial)
Continuous distribution (Normal)

Method 1: Frequency Bins


We first compute the cumulative relative frequency (CRF) of
data X and build the CRF data
We then use RAND() to generate a random number
between 0 and 1
This number is compared with the CRF table using
Lookup() and return the simulated data X

Since a bigger range of values from


RAND() will fall within this interval, 0 has
the highest probability of turning up

LOOKUP() and VLOOKUP()

Down-shifted Lookup Table

Construct the Vlookup Table


by switching columns

Method 2: Resampling
Resampling discrete data
Use Randbetween(1,N) to generate a position number k.
This number is used to return the kth value in the raw
data collection as if the raw data is already sorted in
ascending order.
X=SMALL(array,k)
X=SMALL(raw data, RNADBETWEEN(1,N))
This ensures that higher frequency results occur more
likely than the lower frequency results.

An Example: Resampling Discrete Data


Sorted Data

Randbetween
(1,10)

Number

Frequency

10

Because the position


number is generated
randomly, higher
frequency result (2)
will occur more often
than lower frequency
result (4).
Result 2 has the
highest probability of
turning up.

Method 2: Resampling
Resampling continuous data
Use Rand() to generate a random number between 0
and 1, to represent the percentile value k.
This percentile value k is used to return the
corresponding percentile number in the raw data
collection.
X=PERCENTILE(array,k)
X=PERCENTILE(raw data, RNAD())
PERCENTILE() sorts and interpolates among the raw
data using the number returned by RAND().
The newly generated data X may be DIFFERENT from
the raw data due to interpolation.

Reminders
Review todays class exercises
Project team to arrange to meet instructor to get
in-principle approval for their project before the
end of week 7
Preparation for Next Week
Chapter 7: Processes and Time
EX57: TimerCliker.xls
Ex58: XDBbank.xls

You might also like