CAT Lesson5
-
Upload
bryan-seow -
Category
Documents
-
view
235 -
download
1
description
Transcript of CAT Lesson5
IS102Computer as an Analysis ToolWeek 5: Monte Carlo Simulation
Reading:Chapter 6: Risks and Uncertainties
Instructor:Associate Professor Guo ZhilingSchool of Information [email protected]
Review: • Solver for optimization
– Decisions– Objectives – Constraints
• Lookup functions– Vlookup– Lookup– Index and Match
Echo Office Supplies – Solution Steps1. Compute projected sales revenue before price discount
1) Use Vlookup() to check unit price based on projected demand, and compute projected sales for each project
2) Use Sum() to sum up projected sales for different customer types in the summary section
3) Use Match() and Index() to display information such as projected sales of selected customer
2. Compute projected sales revenue using new price table1) Perform the same steps as in 1.1) and 1.2) using new price table
2) Construct constraints LHS and RHS
3) Construct objective function cell
3. Prepare solver inputs1) Define objective function
2) Define constraints
3) 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
1
2
3
>=
>=4
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:
To generate a random number between 2 non-contiguous numbers MIN and MAX (e.g.1 & 3), use:
RAND()*(MAX-MIN)+MIN
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 HallLet’s 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.
You pick a door, and the host, who knows what's behind the other doors, opens another door which is empty.
Monte Hall
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
1
2
3
1 2 3
Selected Door
PrizeDoor
RB(2,3) 3 2
3 1If(RAND()>0.5,1,3)
2 1 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
1
2
3
1 2 3
Selected Door
RevealedDoor
3 2
3 1
2 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
1 2 3 1 2 3 1 2 3
Open
If change door from1 to 2 = Win
Either door 1 or 3can be opened
Open
If change door from2 to 1 = Lose
Open
If change door from3 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.
– This ensures that higher frequency results occur more likely than the lower frequency results.
X’=SMALL(array,k)X’=SMALL(raw data, RNADBETWEEN(1,N))
An Example: Resampling Discrete Data
Number Frequency
1 2
2 4
3 3
4 1
1
1
2
2
2
2
3
3
3
4
Sorted Data Randbetween (1,10)
1
2
3
4
5
6
7
8
9
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.
– 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.
X’=PERCENTILE(array,k)X’=PERCENTILE(raw data, RNAD())
Reminders• Review today’s 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