16
Intro Page 1 Intro to MonteCarlo.xls This workbook introduces Monte Carlo Simulation with a simple example. In this book, we use Microsoft Excel to simulate chance processes. Typically, we use Excel to draw a sample, then compute a sample statistic, e.g. We can repeat this process, again and again, keeping track of the result each t at the empirical histogram and summary statistics of the results in order to di statistical properties of the chance process. This method of studying a chance Monte Carlo simulation. There are other hidden sheet in this workbook. The OneFreeThrow sheet shows how Excel can be used draw a random number and simul The Sample sheet has the outcome of 100 free throw attempts.

Introduction to Monte Carlo Simulation - Wabash College · XLS file · Web view2018-05-15 · Monte Carlo simulation to prevent constant redrawing of random numbers. ... function

  • Upload
    doanque

  • View
    221

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Introduction to Monte Carlo Simulation - Wabash College · XLS file · Web view2018-05-15 · Monte Carlo simulation to prevent constant redrawing of random numbers. ... function

Intro

Page 1

Intro to MonteCarlo.xlsThis workbook introduces Monte Carlo Simulation with a simple example.

In this book, we use Microsoft Excel to simulate chance processes.

Typically, we use Excel to draw a sample, then compute a sample statistic, e.g., the sample average. We can repeat this process, again and again, keeping track of the result each time. We then look at the empirical histogram and summary statistics of the results in order to discover or illustrate the statistical properties of the chance process. This method of studying a chance process is called Monte Carlo simulation.

There are other hidden sheet in this workbook.

The OneFreeThrow sheet shows how Excel can be used draw a random number and simulate a free throw.

The Sample sheet has the outcome of 100 free throw attempts.

Page 2: Introduction to Monte Carlo Simulation - Wabash College · XLS file · Web view2018-05-15 · Monte Carlo simulation to prevent constant redrawing of random numbers. ... function

Intro

Page 2

sheet shows how Excel can be used draw a random number and simulate a free throw.

Page 3: Introduction to Monte Carlo Simulation - Wabash College · XLS file · Web view2018-05-15 · Monte Carlo simulation to prevent constant redrawing of random numbers. ... function

OneFreeThrow

Page 3

To simulate a free throw, we use a random draw in an IF statement. Scroll down to see how.

The random draw uses the formula, "=RANDOM()", to get a uniformly distributed number in the 0,1 interval.Click in cell B5 to see the formula. Hit F9 (or CTRL - =) to draw a new number. For more on random number generation, see sections 9.2 and 9.3.

#MACRO?

The RANDOM() function is the foundation of the Monte Carlo Simulation because it's our roulette wheel, but we need one more concept to complete the simulation. We need a way to tell Excel that Larry has a 90% chance of making the free throw.Fortunately, this is easily done with an IF statement.

Take a look at the formulas in cells B18, D18, and D18. Cell D18 says, "if the value in cell B18 is less than 0.9, then the value of this cell is 1, else the value is 0." The structure is "expression to be evaluated," "value if true," "value if false." Notice the difference between cells D18 and D19--yet they end up doing the same thing. While you are at it, try to figure out what's going on in cells C18 and C19.

#MACRO? ### ###

### ###

Combining the RAND and IF statements into a single formula, we get a virtual 90% free throw shooter:

#MACRO?Notice that this outcome will occasionally differ from the one above. The reason is that it's based on a different draw from the uniform distribution.

Hit F9 (or CTRL - =) repeatedly (say 30 times in a row) to see how Larry's doing.As long as the value stays at 1, Larry hit the free throw. When it changes to 0, he missed.Question:"I noticed that sometimes he misses in cell B23, but makes it in cells C18 through D19. What's going on?"

Answer:

RANDOM() in a cell, Excel draws a new random number.

Question:"Sometimes I see the word "Calculate" at the bottom of the screen. What does that mean?"

Answer:Excel can be set up to automatically calculate the values of every formula wheneverthe user enters new information anywhere in the workbook OR it can be in Manual Calculatemode, which means that it will not automatically recalculate. Manual Calculation is needed for Monte Carlo simulation to prevent constant redrawing of random numbers. The "Calculate" message in the Status Bar at the bottom of the screen alerts the reader that Excel has notautomatically recalculated the cells in the workbook. If you hit F9, the "Calculate" message

Random draw

Random draw

Larry Bird Simulated

Excel is drawing different random numbers in cells B18 and B23. Every time it sees

Page 4: Introduction to Monte Carlo Simulation - Wabash College · XLS file · Web view2018-05-15 · Monte Carlo simulation to prevent constant redrawing of random numbers. ... function

OneFreeThrow

Page 4

will disappear. Section 9.3 explains about Calculation in more detail and shows how to set the calculation mode.

Page 5: Introduction to Monte Carlo Simulation - Wabash College · XLS file · Web view2018-05-15 · Monte Carlo simulation to prevent constant redrawing of random numbers. ... function

OneFreeThrow

Page 5

The random draw uses the formula, "=RANDOM()", to get a uniformly distributed number in the 0,1 interval.Click in cell B5 to see the formula. Hit F9 (or CTRL - =) to draw a new number. For more on random number generation, see sections 9.2 and 9.3.

Page 6: Introduction to Monte Carlo Simulation - Wabash College · XLS file · Web view2018-05-15 · Monte Carlo simulation to prevent constant redrawing of random numbers. ... function

OneFreeThrow

Page 6

will disappear. Section 9.3 explains about Calculation in more detail and shows how to set the calculation mode.

Page 7: Introduction to Monte Carlo Simulation - Wabash College · XLS file · Web view2018-05-15 · Monte Carlo simulation to prevent constant redrawing of random numbers. ... function

Sample

Page 7

Percentage Made #MACRO? This sheet contains a single repetition of 100 draws (free throw attempts).

Attempt Result Larry Bird hits 90% of his free throws. The formula in Cell B4 informs Excel of this chance process.1 #MACRO? The exact same formula is used in the 100 cells from B4 to B103. Click on a few of these cells to see for yourself.2 #MACRO? Hit F9 to simulate another 100 free throws.3 #MACRO? How did Larry do this time?4 #MACRO?5 #MACRO? Hit F9 again and again. Watch cell B1. 6 #MACRO? How much spread or bounce is there?7 #MACRO?8 #MACRO? Wouldn't it make sense to keep track of Larry's sample percentage?9 #MACRO? Click on the button below to do so.

10 #MACRO?11 #MACRO?12 #MACRO?13 #MACRO? Curious about streaks? Click on the button below.14 #MACRO? Click this button several times.15 #MACRO?16 #MACRO?17 #MACRO? Do you think Max Streaks follow a normal distribution?18 #MACRO? Click on the button below to see a Monte Carlo simulation that answers this question.19 #MACRO?20 #MACRO?21 #MACRO?22 #MACRO?23 #MACRO?24 #MACRO?25 #MACRO?26 #MACRO?27 #MACRO?28 #MACRO?29 #MACRO?30 #MACRO?31 #MACRO?32 #MACRO?33 #MACRO?34 #MACRO?35 #MACRO?36 #MACRO?37 #MACRO?38 #MACRO?

Page 8: Introduction to Monte Carlo Simulation - Wabash College · XLS file · Web view2018-05-15 · Monte Carlo simulation to prevent constant redrawing of random numbers. ... function

Sample

Page 8

39 #MACRO?40 #MACRO?41 #MACRO?42 #MACRO?43 #MACRO?44 #MACRO?45 #MACRO?46 #MACRO?47 #MACRO?48 #MACRO?49 #MACRO?50 #MACRO?51 #MACRO?52 #MACRO?53 #MACRO?54 #MACRO?55 #MACRO?56 #MACRO?57 #MACRO?58 #MACRO?59 #MACRO?60 #MACRO?61 #MACRO?62 #MACRO?63 #MACRO?64 #MACRO?65 #MACRO?66 #MACRO?67 #MACRO?68 #MACRO?69 #MACRO?70 #MACRO?71 #MACRO?72 #MACRO?73 #MACRO?74 #MACRO?75 #MACRO?76 #MACRO?77 #MACRO?78 #MACRO?79 #MACRO?

Page 9: Introduction to Monte Carlo Simulation - Wabash College · XLS file · Web view2018-05-15 · Monte Carlo simulation to prevent constant redrawing of random numbers. ... function

Sample

Page 9

80 #MACRO?81 #MACRO?82 #MACRO?83 #MACRO?84 #MACRO?85 #MACRO?86 #MACRO?87 #MACRO?88 #MACRO?89 #MACRO?90 #MACRO?91 #MACRO?92 #MACRO?93 #MACRO?94 #MACRO?95 #MACRO?96 #MACRO?97 #MACRO?98 #MACRO?99 #MACRO?

100 #MACRO?

Page 10: Introduction to Monte Carlo Simulation - Wabash College · XLS file · Web view2018-05-15 · Monte Carlo simulation to prevent constant redrawing of random numbers. ... function

Sample

Page 10

This sheet contains a single repetition of 100 draws (free throw attempts).

Larry Bird hits 90% of his free throws. The formula in Cell B4 informs Excel of this chance process.The exact same formula is used in the 100 cells from B4 to B103. Click on a few of these cells to see for yourself.

Wouldn't it make sense to keep track of Larry's sample percentage?

Click on the button below to see a Monte Carlo simulation that answers this question.

Page 11: Introduction to Monte Carlo Simulation - Wabash College · XLS file · Web view2018-05-15 · Monte Carlo simulation to prevent constant redrawing of random numbers. ... function

Q&A for MonteCarlo.xls1) Run a Monte Carlo with 1,000 repetitions of the percentage made of 100 free throws.

Use the Take a Picture button to take a picture of your results.Copy and paste the picture in a Word document.

2) Run a Monte Carlo with 10,000 repetitions of the percentage made of 100 free throws.Take a picture, copy it, and paste it in the Word document below the 1,000 repetition Monte Carlo.

3) In what sense is the 10,000 repetition Monte Carlo better than the 1,000 repetition Monte Carlo in this example?

4) Run a Max Streak Monte Carlo.Take a picture, copy it, and paste it in the Word document.

5) What are the chances that the virtual Larry Bird gets a max streak of 51 in a row or more?Explain how you arrived at your answer.

Page 12: Introduction to Monte Carlo Simulation - Wabash College · XLS file · Web view2018-05-15 · Monte Carlo simulation to prevent constant redrawing of random numbers. ... function

Take a picture, copy it, and paste it in the Word document below the 1,000 repetition Monte Carlo.

3) In what sense is the 10,000 repetition Monte Carlo better than the 1,000 repetition Monte Carlo in this example?

Page 13: Introduction to Monte Carlo Simulation - Wabash College · XLS file · Web view2018-05-15 · Monte Carlo simulation to prevent constant redrawing of random numbers. ... function

Monte Carlo Simulation of Sample Percentage with 10000 Repetitions

1 152 22 Time Elapsed 2.00 secs3 324 165 216 437 178 169 2210 2711 3812 2813 3614 3615 2916 2117 2518 1419 16

Sample Number

Max Sample Streak

0 to 5

6 to 10

11 to 15

16 to 20

21 to 25

26 to 30

31 to 35

36 to 40

41 to 45

46 to 50

51 to 55

56 to 60

61 to 65

66 to 70

71 to 75

76 to 80

81 to 85

86 to 90

91 to 95

96 to

100

0

500

1000

1500

2000

2500

3000 Empirical Histogram for 10000 Repetitions

Min = 8

Average = 27.0

SD = 9.7

Summary Statistics

Max = 89