Sei sulla pagina 1di 115

Intro

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., 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.
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.
There are other hidden sheet in this workbook.

Page 1

Intro

ate a free throw.

Page 2

OneFreeThrow
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
Random
#MACRO?
draw
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.
Random
draw

#MACRO?

###

###

###

###

Combining the RAND and IF statements into a single formula, we get a virtual 90% free throw shooter:
Larry Bird
#MACRO?
Simulated
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:
Excel is drawing different random numbers in cells B18 and B23. Every time it sees
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 whenever
the user enters new information anywhere in the workbook OR it can be in Manual Calculate
mode, 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 not
automatically recalculated the cells in the workbook. If you hit F9, the "Calculate" message

Page 3

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

Page 4

OneFreeThrow

0,1 interval.
ndom number generation, see sections 9.2 and 9.3.

Page 5

OneFreeThrow

calculation mode.

Page 6

Sample

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 Exc

#MACRO?

#MACRO?

Hit F9 to simulate another 100 free throws.

#MACRO?

How did Larry do this time?

#MACRO?

#MACRO?

Hit F9 again and again. Watch cell B1.

#MACRO?

How much spread or bounce is there?

#MACRO?

#MACRO?

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

#MACRO?

Click on the button below to do so.

10

#MACRO?

11

#MACRO?

12

#MACRO?

13

#MACRO?

14

#MACRO?

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 th

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?

The exact same formula is used in the 100 cells from B4 to B

Curious about streaks? Click on the button below.


Click this button several times.

Page 7

Sample
38

#MACRO?

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?

Page 8

Sample
78

#MACRO?

79

#MACRO?

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 9

Sample

aws (free throw attempts).

mula in Cell B4 informs Excel of this chance process.


the 100 cells from B4 to B103. Click on a few of these cells to see for yourself.

sample percentage?

simulation that answers this question.

Page 10

Sample

Page 11

Sample

Page 12

Q&A for MonteCarlo.xls


1) 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.

n Monte Carlo.

rlo in this example?

Monte Carlo Simulation of Sample Percentage with 1000 Repetitions


Sample
Number
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

Sample
Percentage
89%
94%
87%
88%
92%
86%
85%
84%
84%
90%
94%
94%
84%
90%
90%
88%
88%
88%
80%
90%
85%
90%
85%
90%
95%
93%
90%
90%
86%
92%
93%
91%
89%
89%
83%

Excel Tip: Pause the cursor over one of


Time Elapsed

1 secs
Empirical Histogram for 1000 Repetitions

160
Summary Statistics

140

Average = 89.97%
SD = 3.052%
Max = 97%
Min = 79%

120
100
80
60
40
20
0
78%

80%

82%

84%

86%

88%

90%

92%

94%

96%

98% 100%

Empirical Histogram for 1000 Repetitions


160
140

Summary Statistics

120

Average = 89.97%
SD = 3.052%
Max = 97%
Min = 79%

100
80
60
40
20
0
78%

80%

82%

84%

86%

88%

90%

92%

94%

96%

98% 100%

60
40
20

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

85%
90%
93%
91%
96%
91%
93%
91%
90%
86%
89%
88%
91%
92%
92%
83%
91%
93%
92%
88%
91%
95%
88%
91%
93%
95%
83%
87%
89%
93%
94%
89%
88%
88%
94%
85%
90%
95%
88%
90%
87%

0
78%

80%

82%

84%

86%

88%

90%

92%

94%

96%

98% 100%

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

91%
91%
93%
86%
91%
89%
88%
87%
88%
88%
93%
90%
90%
95%
83%
93%
91%
89%
88%
89%
89%
89%
90%
92%
93%
89%
94%
92%
90%
92%
94%
90%
88%
89%
87%
92%
90%
91%
90%
95%
90%

118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

87%
92%
95%
96%
94%
92%
86%
83%
93%
90%
95%
91%
90%
94%
91%
91%
91%
92%
90%
90%
93%
85%
94%
95%
91%
90%
89%
91%
93%
93%
86%
91%
86%
87%
84%
95%
91%
91%
91%
89%
86%

159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199

89%
96%
82%
90%
91%
91%
94%
88%
86%
91%
89%
93%
94%
92%
90%
92%
92%
90%
90%
92%
90%
93%
88%
93%
87%
89%
88%
93%
89%
88%
85%
90%
89%
93%
89%
92%
82%
91%
89%
93%
95%

200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240

87%
90%
88%
91%
91%
88%
86%
91%
85%
90%
95%
92%
88%
91%
93%
92%
87%
94%
91%
94%
94%
88%
92%
90%
90%
92%
92%
92%
88%
91%
94%
89%
89%
89%
87%
94%
91%
88%
89%
85%
94%

241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281

90%
92%
95%
89%
94%
87%
93%
92%
96%
87%
88%
91%
91%
94%
85%
91%
88%
95%
94%
95%
88%
86%
87%
95%
93%
86%
90%
91%
97%
85%
89%
91%
88%
83%
92%
91%
93%
88%
87%
87%
88%

282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322

92%
89%
87%
90%
91%
81%
79%
89%
84%
95%
93%
97%
92%
94%
91%
86%
95%
89%
92%
92%
90%
87%
91%
91%
91%
88%
87%
96%
93%
89%
93%
92%
89%
90%
87%
91%
92%
89%
89%
88%
85%

323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363

94%
89%
92%
94%
88%
86%
93%
93%
88%
88%
90%
87%
92%
89%
83%
93%
90%
91%
91%
87%
89%
88%
92%
93%
94%
89%
93%
94%
94%
93%
88%
88%
87%
90%
93%
94%
89%
81%
87%
87%
90%

364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404

86%
90%
87%
92%
90%
92%
91%
90%
89%
94%
81%
90%
91%
92%
93%
84%
86%
88%
91%
89%
89%
91%
91%
89%
90%
90%
89%
92%
92%
88%
89%
90%
87%
91%
91%
90%
89%
91%
87%
92%
90%

405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445

87%
90%
88%
89%
90%
90%
92%
90%
86%
94%
84%
91%
93%
93%
89%
94%
92%
90%
89%
87%
93%
87%
89%
89%
92%
92%
88%
90%
90%
90%
86%
88%
91%
89%
87%
88%
89%
92%
85%
90%
94%

446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486

91%
91%
87%
90%
89%
85%
90%
88%
92%
87%
88%
88%
91%
94%
95%
92%
88%
91%
89%
88%
94%
92%
90%
89%
91%
91%
88%
90%
91%
93%
88%
93%
88%
86%
93%
94%
87%
87%
93%
93%
84%

487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527

87%
88%
95%
94%
95%
94%
89%
87%
95%
91%
88%
92%
90%
87%
91%
85%
88%
83%
93%
86%
93%
88%
91%
92%
86%
90%
87%
90%
87%
89%
97%
82%
89%
93%
91%
95%
88%
90%
84%
91%
86%

528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568

91%
93%
93%
92%
84%
94%
92%
92%
91%
86%
89%
88%
88%
90%
81%
87%
91%
91%
89%
85%
95%
90%
92%
91%
85%
90%
86%
87%
91%
94%
92%
94%
93%
93%
92%
89%
90%
91%
91%
87%
90%

569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609

87%
91%
94%
91%
89%
91%
82%
89%
86%
90%
93%
88%
94%
91%
89%
91%
92%
90%
91%
90%
88%
87%
85%
90%
89%
92%
89%
90%
90%
84%
87%
88%
90%
93%
89%
89%
93%
90%
89%
89%
83%

610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650

89%
88%
90%
88%
91%
87%
85%
87%
92%
93%
91%
89%
93%
95%
94%
91%
91%
86%
89%
91%
90%
90%
94%
89%
91%
88%
87%
86%
89%
91%
94%
93%
91%
91%
92%
94%
92%
92%
89%
89%
92%

651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691

91%
91%
85%
93%
86%
90%
87%
92%
93%
94%
91%
85%
95%
91%
91%
95%
91%
88%
95%
89%
88%
85%
90%
90%
86%
90%
94%
91%
88%
89%
88%
94%
89%
85%
94%
87%
90%
91%
88%
89%
89%

692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732

87%
93%
90%
91%
94%
96%
89%
91%
91%
89%
91%
86%
97%
89%
94%
88%
95%
93%
92%
86%
89%
86%
95%
87%
90%
90%
94%
89%
92%
89%
92%
86%
88%
94%
89%
91%
94%
92%
95%
93%
89%

733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773

88%
79%
87%
85%
91%
93%
88%
90%
95%
94%
95%
87%
87%
92%
89%
85%
93%
89%
87%
90%
88%
94%
88%
88%
84%
90%
87%
85%
91%
91%
91%
88%
92%
85%
92%
85%
90%
84%
86%
87%
89%

774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814

83%
90%
94%
91%
83%
94%
92%
89%
89%
87%
86%
91%
95%
89%
90%
96%
89%
93%
92%
90%
90%
93%
94%
93%
86%
87%
93%
94%
89%
90%
95%
91%
91%
89%
93%
96%
94%
89%
93%
93%
91%

815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855

92%
93%
87%
88%
90%
91%
90%
86%
92%
91%
88%
92%
89%
91%
90%
89%
92%
88%
91%
91%
93%
92%
92%
86%
91%
92%
91%
88%
93%
92%
92%
85%
89%
91%
90%
90%
91%
86%
91%
89%
89%

856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896

88%
86%
93%
93%
91%
84%
81%
95%
89%
90%
93%
89%
88%
89%
92%
91%
85%
93%
90%
88%
88%
95%
91%
91%
88%
89%
90%
89%
90%
87%
85%
87%
85%
86%
91%
84%
90%
85%
94%
92%
89%

897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937

89%
95%
89%
92%
95%
89%
83%
86%
89%
89%
91%
92%
96%
92%
88%
89%
96%
92%
93%
87%
92%
92%
82%
92%
90%
86%
96%
91%
89%
91%
92%
91%
83%
85%
93%
90%
88%
88%
91%
87%
91%

938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978

91%
94%
94%
93%
94%
94%
94%
92%
93%
91%
93%
90%
92%
91%
93%
92%
90%
85%
94%
90%
83%
94%
93%
87%
91%
90%
93%
89%
86%
92%
92%
87%
87%
91%
84%
93%
94%
90%
86%
87%
95%

979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000

86%
83%
86%
91%
87%
90%
90%
83%
92%
91%
89%
95%
92%
89%
90%
90%
89%
88%
92%
89%
86%
93%

Repetitions

Min = 79%

Max = 97%
: Pause the cursor over one of the bars, the number of samples (or height of the bar) is displayed. Average = 89.97%
SD = 3.052%

ions

96%

98% 100%

ons

96%

98% 100%

96%

98% 100%

Min = 79%

Max = 97%
Average = 89.97%
SD = 3.052%

Bin Value
78%
79%
80%
81%
82%
83%
84%
85%
86%
87%
88%
89%
90%
91%
92%
93%
94%
95%
96%
97%
98%
99%
100%

Number
of
Samples
0
2
1
5
5
16
16
35
48
72
92
125
124
143
101
88
71
41
11
4
0
0
0

Monte Carlo Simulation of Sample Percentage with 10000 Repetitions


Sample
Number
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

Max
Sample
Streak
15
22
32
16
21
43
17
16
22
27
38
28
36
36
29
21
25
14
16

Time Elapsed

2.00 secs
Empirical Histogram for 10000 Repetitions

3000

Summary Statistics
2500

Average = 27.0
SD = 9.7

2000

Max = 89
Min = 8

1500
1000
500
0

0 to 6 to 11
5
10 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 96
to to
95 100

Potrebbero piacerti anche