0% found this document useful (0 votes)
10 views28 pages

Lecture 5

This document discusses using Monte Carlo simulation in Excel to solve problems involving random variables. It provides examples of generating random numbers in Excel and using functions like LOOKUP and VLOOKUP to simulate values from probability distributions. One example presented is simulating weekly heater sales over 100 weeks to estimate average sales and out-of-stock customers.

Uploaded by

Arnika Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views28 pages

Lecture 5

This document discusses using Monte Carlo simulation in Excel to solve problems involving random variables. It provides examples of generating random numbers in Excel and using functions like LOOKUP and VLOOKUP to simulate values from probability distributions. One example presented is simulating weekly heater sales over 100 weeks to estimate average sales and out-of-stock customers.

Uploaded by

Arnika Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

LECTURE 5

MONTE CARLO SIMULATION BY EXCEL


(PART 1)

1
AGENDA

 Random number generation by Excel: uniform distribution


 Examples in Excel

2
RANDOM NUMBER TABLE

3
RANDOM NUMBERS IN EXCEL

 Generation of random numbers has the following properties:


 Uniformly distributed, greater than or equal to 0 and less than 1.
 Probabilistically independent.
 Easy to generate another set of random numbers for a new simulation.
 Useful as the “building block” of a simulation.

4
RANDOM NUMBERS IN EXCEL:
RAND FUNCTION

 Formula for generating a single random number:


 =RAND( )
 Parentheses (with nothing between them) are to indicate function without
arguments.
 When this is copied to another set of cells, a different set of random numbers is
generated.
 See Excel “Random Numbers” worksheet

5
EXPERIMENTING WITH RAND FUNCTION

 Enter “= RAND( )” in one cell.


 Copy it to 499 other cells.
 The numbers change whenever you change the spreadsheet.
 You can obtain a new set of random numbers by pressing “F9”.

6
EXPERIMENTING WITH RAND FUNCTION

 Develop a frequency table to see how the 500 random number are
distributed.
 Enter a column of “bin values” (the upper ends of the categories): 0.1, 0.2,
up to 0.9
 Highlight an adjacent range one cell longer than the bin range.
 Enter formula =FREQUENCY(data,bin) and press Ctrl-Shift-Enter.

7
EXPERIMENTING WITH RAND FUNCTION

 This table shows the frequencies (number of values) in each of several


categories.
 The first frequency is the number of values less than or equal to 0.1.
 These were found with the FREQUENCY function (an array function).

8
FREEZING THE RANDOM NUMBERS

 Copy the random numbers on the original sheet to a new sheet with the Paste
Special/Values option.
 The pasted copy is now frozen (does not change when F9 key is pressed).
 Freezing random numbers is sometimes useful in simulation models, but not
always.
 See “Freezing Numbers” worksheet.

9
SIMULATING VALUES FROM PROBABILITY
DISTRIBUTIONS

 RAND() generates random number in [0,1), such that the probability of


generating a number within [𝑎, 𝑏] is equal to 𝑏 𝑎 (0 𝑎 𝑏 1).
 This is somewhat like drawing 00-99 out of a black box, except that we can also
draw numbers like 0.5155, 0.56564, etc.
 Goals:
 Divide [0,1) into intervals that reflect our probability distribution (i.e.
random number assignment).
 Use Excel functions to identify the random observation based on the
generated random number.

10
EXAMPLE 1: MONTE CARLO SIMULATION
REVISIT WITH EXCEL

 Last class: Higgins Plumbing and Heating


 Use simulation to estimate the average weekly sales.

Heater Sales Probability


4 0.12
5 0.10
6 0.18
7 0.24
8 0.16
9 0.14
11
10 0.06
Total 1.00
STEP 1: ASSIGN RANDOM NUMBER INTERVALS

 When we specify the random number intervals, it will seem as if the


upper limit of one row overlaps with the lower limit of the next row.
 However, the probability that we get any specific number like 0.1, 0.5,
etc with the RAND() function is essentially 0.
 Don’t need to worry about RAND() being equal to the lower/upper
limits.

12
STEP 2: DETERMINE RANDOM OBSERVATION
(LOOKUP)

 LOOKUP(lookup_value, lookup_vector, result_vector)


 Look for lookup_value in lookup_vector and return a value from the same position
in result_vector.
 lookup_value = Our random number
 lookup_vector = Random number assignment
 result_vector = Observations
 Remark:
1. The values in lookup_vector must be placed in ascending order
2. If the LOOKUP function can't find lookup_value, Excel rounds DOWN to
match the closest value in lookup_vector .
13
 Implication of Remark 2  Use Lower Limit for lookup_vector .
HIGGINS - LOOKUP

 See “Higgins - Lookup” tab.

14
STEP 2: VLOOKUP (ALTERNATIVE)

 Alternatively, we can use the VLOOKUP function.


 VLOOKUP(lookup_value, table_array, col_index_num, range_lookup)
 Searches for a value in the leftmost column of a table, and then returns a value in the
same row from a column you specify in the table.
 Remark:
1. Lookup_value: Excel lookups for this in the FIRST column of the table.
2. Table_array is the table of information.
3. Col_index_num of x means that we return values from the x-th column of the table.
4. Range_lookup is either TRUE (approximate match) or FALSE (exact match).
• If “TRUE” or omitted, then VLOOKUP works like LOOKUP and rounds down lookup_value.
• If “FALSE”, VLOOKUP will find an exact match, or return the error value #N/A if not found. 15
STEP 2: VLOOKUP (ALTERNATIVE)

 Alternatively, we can use the VLOOKUP function.


 VLOOKUP(lookup_value, table_array, col_index_num, range_lookup)
 Searches for a value in the leftmost column of a table, and then returns a value in the
same row from a column you specify in the table.
 Remark:
1. Lookup_value: Our random number.
2. Table_array: First column of table should be the lower limit.
3. Col_index_num: Column with heater sales.
4. Range_lookup: TRUE

16
VLOOKUP FUNCTION: EXAMPLE
 See “Higgins - Vlookup” worksheet
 Observe that “Upper limit” = “Cumulative probability” in the last
example  Don’t need two different columns.

17
HIGGINS – SALES AND OUT-OF-STOCK

 Suppose Jerry restocks and starts each week with 8 heaters.


 Run a simulation over 100 weeks to compute the average weekly
demand.
 On average, how many customers are unable to buy a heater
because Jerry is out-of-stock?
 IF(logical_test, value_if_true, value_if_false)
 Logical_test: demand <= 8
 Value_if_true: 0 (everyone buys a heater)
 Value_if_false: demand – 8 (# of unhappy customers)
 How can we modify the IF function if we only want to count the
number of weeks that Jerry is out-of-stock?
18
EXAMPLE 2: ART’S NEWSSTAND

 Art sells newspaper. He cannot foretell the daily demand 𝐷 (i.e. the number of
newspapers that he can sell in any day).
 Each morning, Art orders 𝑞 newspapers from his wholesaler at $3 each.
 Art sells the newspaper at $5 each. If he has unsold units at the end of the day,
he receives $0.50 per scrap (i.e. an unsold piece).
 Art wants to maximize his average daily profit. How many newspapers, 𝑞, should
he order each morning?

19
EXAMPLE 2: ART’S NEWSSTAND

 Decision Variable: 𝑞 = daily order quantity.


 Art’s random daily profit:
 If 𝐷 𝑞, then Art earns $5 𝑞 3 𝑞.
 If 𝐷 𝑞, then Art earns $5 𝐷 0.50 𝑞 𝐷 3 𝑞.
 Combining the two scenarios yields Art’s random daily profit:
5 min 𝑞, 𝐷 0.5 max 𝑞 𝐷, 0 3 𝑞.

Revenue Scrap value, if any Purchase cost


20
EXAMPLE 2: ART’S NEWSSTAND

 Art wants to determine the optimal order quantity to maximize his average
daily profit.
 Why focus on average profit?
 Taking expectation on Art’s random daily profit yields Art’s average daily profit,
namely:
E5 min 𝑞, 𝐷 0.5 max 𝑞 𝐷, 0 3 𝑞
 Maximizing Art’s average daily profit is expressed by
max E 5 min 𝑞, 𝐷 0.5 max 𝑞 𝐷, 0 3 𝑞

 How can we determine the optimal order quantity?

21
EXAMPLE 2: ART’S NEWSSTAND

 Art cannot control the daily demand.


 Hence, the daily demand 𝐷 can be described by a random variable.
 An idea without computer:
 Order 80 newspaper over the next month.
 Compute the average daily profit when Art orders 𝑞 80 newspapers.
 Repeat for different values of 𝑞.

22
EXAMPLE 2: ART’S NEWSSTAND

 Alternatively, determine the probability distribution of past demand and


run simulations.
 Q1: Suppose he orders 80 newspaper each morning. Can we compute his
average profit?
 Be careful! Our goal is to compute Art’s average profit, NOT average
demand.

23
EXAMPLE 2: ART’S NEWSSTAND

 Art tells us that the daily demand follows a uniform distribution between 30
pieces and 150 pieces, inclusive.
 That is, 𝐷 ~ 𝑈 30,150 and every integer between 30 and 150 occurs with
EQUAL probability.
 When we have a uniform distribution between a and b, we can use the
RANDBETWEEN(a,b) function as a shortcut!

24
EX 2, Q1: COMPUTING AVERAGE PROFIT
Average over profits
in Col C

Profit
=5*MIN($B$1,B7)
+0.5*MAX(0,$B$1-B7)
-3*$B$1

25

Simulated Demand
=RANDBETWEEN(30,150)
EXAMPLE 2: ART’S NEWSSTAND

 Average Profit as a Function of the Number of Observations, given that the daily
order quantity is 𝑞 80.

26
EX Q2: OPTIMAL ORDER QUANTITY

 Q2: How many newspaper should Art order daily to maximize his
average profit?
 Method 1: Data table
 Method 2: Scenario Manager

27
SUMMARY

 Monte Carlo simulation via Excel


 Computing an optimal decision using simulation

28

You might also like