You are on page 1of 27

Monte Carlo Simulation

Example 1: Using the RAND( ) function to generate a random number, uniformly distributed between 0 and 1.

The Excel function =RAND( ) is a random number generator. It has no arguments, i.e. there is nothing between the parentheses.
Each time a worksheet is recalculated (automatically when you change any cell, or manually using the F9 function key),
all instances of the RAND( ) function are recalculated and select a different random number, uniformly distributed between 0 and 1.

1. Generate 100 random numbers: hit F9 function key to recalculate the spreadsheet.

2. Cells with red triangles in their upper right contain comments; examine them by moving your cursor over them.

3. Examine the other worksheets in this file, which show more ways to harness =RAND( ) to create random numbers.

Trial # Result
1 0.4402
This column merely Each cell in this column contains exactly the same
identifies the trial
2 0.1524
formula: =RAND()
number, 1-100 in this 3 0.4839
example. 4 0.1963 Each cell has a different value, however, because
5 0.5889 each instance of the =RAND() function generates
an independent random number between 0 and 1.
6 0.4619
7 0.2194 Here we display only 4 significant digits; the
8 0.8873 underlying value contains many more, up to the
limit of Excel's computational precision.
9 0.0204
10 0.2066
11 0.3507
12 0.7903
13 0.8660
14 0.5616
100 Draws from Continuous Uniform U[0,1]
15 0.3873
16 0.0603
17 0.7076
-0.1000

0.1000

0.3000

0.5000

0.7000
0.0000

0.2000

0.4000

0.6000

0.8000
18 0.7847
19 0.8237
20 0.8637 Output of RAND() formula
21 0.1174
22 0.4578
23 0.4597
24 0.9591
25 0.0803
26 0.2123
27 0.9111
28 0.6189
29 0.6595
30 0.2753
31 0.6066
32 0.5400
33 0.5247
34 0.4441
35 0.8658
36 0.2786
37 0.3016
38 0.6518
39 0.9566
40 0.0428
41 0.7565
42 0.0784
43 0.8253
44 0.4085
45 0.6653
46 0.1845
47 0.9339
48 0.8337
49 0.9758
50 0.4487
51 0.8121
52 0.2202
53 0.6608
54 0.0422
55 0.5828
56 0.9035
57 0.8206
58 0.0820
59 0.0053
60 0.4009
61 0.2790
62 0.7068
63 0.7440
64 0.8105
65 0.4987
66 0.1978
67 0.4750
68 0.9917
69 0.3805
70 0.5645
71 0.0105
72 0.2750
73 0.5175
74 0.4640
75 0.4172
76 0.5925
77 0.5963
78 0.0518
79 0.8448
80 0.3723
81 0.2388
82 0.8412
83 0.1986
84 0.7579
85 0.8981
86 0.4240
87 0.1452
88 0.2599
89 0.2037
90 0.5498
91 0.7447
92 0.8969
93 0.1110
94 0.8076
95 0.8999
96 0.3720
97 0.8798
98 0.8464
99 0.0960
100 0.1373
een the parentheses.

buted between 0 and 1.

us Uniform U[0,1]
0.7000

0.9000

1.1000
0.6000

0.8000

1.0000

D() formula
Plot Series
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Monte Carlo Simulation

Example 3: Using the RAND( ) function to flip an arbitrary coin

If we embed the RAND( ) function in an =IF( ) function and compare it to a fixed number between 0 and 1,
we can get it to flip a coin with that number as the probability of Heads. That is, we can randomly select
between two alternatives, with the probabilities determined by our choice of that fixed number.
Cell G9 contains the
1. Specify probability of "Heads" = 0.72 critical value 0.72

2. Flip 100 coins: hit function key F9 to recalculate the spreadsheet =COUNTIF(D16:D115,G13)

COUNTIF is a useful function - here


3. View summary of results; actual # of heads in 100 trials: A B applications. It counts the number
68 32 that satisfy a given condition. Here
of the simulated results are "A."
Trial # Random # Result
1 0.3612 A
2 0.1465 A Each cell in this column contains the same formula (adjusted for relative cell reference
This column that row's random number with the probability of heads specified above. For example
3 0.1719 A
merely have the formula for Trial 1: =IF(C16<$G$9, $G$13, $H$13)
identifies 4 0.5394 A
the trial 5 0.6955 A Recall that an Excel IF formula contain three arguments:
number, 6 0.7704 B the first is a statement that is tested to see if it is true;
1-100. the second is the value the function returns if the test statement is true;
7 0.8390 B the third is the value the function returns if the test statement is false.
8 0.4279 A
9 0.8977 B If the row's random result (say, for Trial 1, cell C16) is less than the fixed number (fou
Each cell in this returns the value of cell $G$13. Otherwise, it returns the value of cell $H$13.
10
column contains the 0.3145 A
same formula: 11 0.3717 A This coin-flipping could be accomplished in a single formula, but here we have broken
=RAND() and D, to make each RAND result explicit.
12 0.9321 B
13 0.2499 A
14 0.1417 A
15 0.9226 B
16 0.1451 A
100 Flips of Uneven "Coin"
17 0.1493 A
18 0.0448 A
19 0.1897 A
32%
20 0.7896 B
21 0.4308 A
22 0.8691 B
23 0.6958 A
24 0.2405 A 68%
25 0.5490 A
26 0.5940 A
27 0.5681 A
28 0.5144 A A B
29 0.1116 A
30 0.6252 A
31 0.9481 B
32 0.7771 B
33 0.2480 A
34 0.7816 B
35 0.0862 A
36 0.3361 A
37 0.1316 A
38 0.7765 B
39 0.6551 A
40 0.4892 A
41 0.1912 A
42 0.0300 A
43 0.3390 A
44 0.5190 A
45 0.9325 B
46 0.0584 A
47 0.6899 A
48 0.8698 B
49 0.6031 A
50 0.0559 A
51 0.7210 B
52 0.1325 A
53 0.1261 A
54 0.1331 A
55 0.4367 A
56 0.2965 A
57 0.7678 B
58 0.0082 A
59 0.2126 A
60 0.5895 A
61 0.5676 A
62 0.8989 B
63 0.4032 A
64 0.0460 A
65 0.6710 A
66 0.6036 A
67 0.6402 A
68 0.8865 B
69 0.8376 B
70 0.8824 B
71 0.0670 A
72 0.5708 A
73 0.2187 A
74 0.8735 B
75 0.9253 B
76 0.3745 A
77 0.1074 A
78 0.7882 B
79 0.8335 B
80 0.3805 A
81 0.8331 B
82 0.6620 A
83 0.4381 A
84 0.0472 A
85 0.0545 A
86 0.9124 B
87 0.3275 A
88 0.7252 B
89 0.7336 B
90 0.2766 A
91 0.0668 A
92 0.2441 A
93 0.9857 B
94 0.7823 B
95 0.5043 A
96 0.9691 B
97 0.1153 A
98 0.9787 B
99 0.8284 B
100 0.0649 A
Cell G9 contains the
critical value 0.72

=COUNTIF(D16:D115,G13)

COUNTIF is a useful function - here and in other


applications. It counts the number of cells in a range
that satisfy a given condition. Here it tells us how many
of the simulated results are "A."

mula (adjusted for relative cell references), which compares


y of heads specified above. For example, here in cell D16 we
G$13, $H$13)

rguments:
e;
t statement is true;
tatement is false.

C16) is less than the fixed number (found in $G$9), the IF


returns the value of cell $H$13.

ingle formula, but here we have broken it into two columns, C

"Coin"

68%
Monte Carlo Simulation

Example 4: Using the RAND( ) function to flip a 3-sided coin

If we embed the RAND( ) function in more complicated (so-called "nested") =IF( ) functions,
we can get it to flip a coin with more than 2 sides, that is, randomly select among several alternatives
of different probabilities. In this example, we have three sides: A, B, and C.

P(A) P(B) P(C )


1. Specify probabilities of A & B (C gets the rest): 0.60 0.30 0.10

2. Flip 100 coins: hit F9 function key to recalculate the spreadsheet

3. View summary of results, actual # of A's, B's and C's in 100 trials:
A B C
trial # random# result 62 30 8
1 0.8463 B
2 0.9750 C Each cell in this column contains the same formula (adjusted for relative cell referen
random number with the 3 probabilities specified above. For example, here in cell D1
3 0.2627 A =IF(C17<$F$10, $F$15, IF(C17<$F$10+$G$10, $G$15, $H$15))
4 0.3025 A
5 0.4932 A If the row's random result (say, for Trial 1, C17) is less than the first critical value P(
Otherwise, it moves on to another IF formula embedded in the third argument, whic
6 0.6743 B be "B" or a "C."
7 0.4325 A
8 0.1193 A
9 0.6199 B
10 0.7818 B
100 Flips of 3-Sided Coin
11 0.0142 A
12 0.8816 B 30%
13 0.7888 B
14 0.0792 A
15 0.5411 A
16 0.0934 A
17 0.3170 A 8%
18 0.7185 B 62%
19 0.5890 A
20 0.4780 A
21 0.9859 C
22 0.7913 B A B C
23 0.6347 B
24 0.1656 A
25 0.4205 A
26 0.2144 A
27 0.3000 A
28 0.5369 A
29 0.5550 A
30 0.1528 A
31 0.9862 C
32 0.0863 A
33 0.1528 A
34 0.2879 A
35 0.2680 A
36 0.2340 A
37 0.4126 A
38 0.3229 A
39 0.7440 B
40 0.3445 A
41 0.4895 A
42 0.0906 A
43 0.3856 A
44 0.4149 A
45 0.4856 A
46 0.3112 A
47 0.3174 A
48 0.4846 A
49 0.0178 A
50 0.9497 C
51 0.4569 A
52 0.3867 A
53 0.8285 B
54 0.1800 A
55 0.9890 C
56 0.1311 A
57 0.0941 A
58 0.9666 C
59 0.2622 A
60 0.3529 A
61 0.7443 B
62 0.9674 C
63 0.6891 B
64 0.3902 A
65 0.7468 B
66 0.4888 A
67 0.2778 A
68 0.4606 A
69 0.4076 A
70 0.7285 B
71 0.4952 A
72 0.4537 A
73 0.8113 B
74 0.8942 B
75 0.3498 A
76 0.7629 B
77 0.3104 A
78 0.5270 A
79 0.3450 A
80 0.0266 A
81 0.5790 A
82 0.9883 C
83 0.6276 B
84 0.7877 B
85 0.8789 B
86 0.8599 B
87 0.5464 A
88 0.6459 B
89 0.4641 A
90 0.6483 B
91 0.2469 A
92 0.7858 B
93 0.8542 B
94 0.8531 B
95 0.8536 B
96 0.8272 B
97 0.3944 A
98 0.8793 B
99 0.3517 A
100 0.0695 A
rmula (adjusted for relative cell references), which compares that row's
ified above. For example, here in cell D17 we have:
10, $G$15, $H$15))

17) is less than the first critical value P(A), the IF formula returns "A."
embedded in the third argument, which determines whether the result should

100 Flips of 3-Sided Coin


100%
8
90%
80% 30
70%
60%
50%
40%
30% 62
20%
10%
0%
Monte Carlo Simulation

Example 2: Using the RAND( ) function to generate a random number, uniformly distributed within in any range

We can rescale our random numbers so that their probability of occurrence is uniform within any interval we care to specify.

1. Specify the upper & lower limits of the interval in which you would like to generate uniform random numbers:
lower limit 40
upper limit 80

2. Generate 100 random numbers: hit F9 function key to recalculate the spreadsheet.

3. View summary of results, actual min, max and mean of 100 trials: min 40.99
max 79.98
trial # random# result mean 59.17
1 0.8189 72.76

Cumulative Count
2 0.9203 76.81
3 0.2237 48.95
4 0.2383 49.53
5 0.0398 41.59
100 Draws from Continuous U
100
6 0.9996 79.98 90
7 0.1607 46.43 80
8 0.6254 65.02 70
9 0.3875 55.50 60
10 0.7839 71.36 50
11 0.4621 58.49 40
12 0.9691 78.76 30
13 0.9681 78.73 20
14 0.5438 61.75 10
15 0.6273 65.09 -
16 0.9744 78.98 35 40 45 50 55 60 65 7
17 0.6442 65.77 Result
18 0.6689 66.76
19 0.0247 40.99
20 0.6273 65.09
21 0.4269 57.08
22 0.3920 55.68
23 0.0696 42.79
24 0.8086 72.35
25 0.4951 59.81
26 0.4545 58.18
27 0.6846 67.38
28 0.0957 43.83
29 0.5815 63.26
30 0.8947 75.79
31 0.5245 60.98
32 0.1110 44.44
33 0.2537 50.15
34 0.7578 70.31
35 0.7150 68.60
36 0.9611 78.45
37 0.1527 46.11
38 0.3363 53.45
39 0.1835 47.34
40 0.7382 69.53
41 0.5467 61.87
42 0.8583 74.33
43 0.8989 75.96
44 0.3293 53.17
45 0.8679 74.72
46 0.5467 61.87
47 0.1946 47.78
48 0.3270 53.08
49 0.9649 78.60
50 0.9278 77.11
51 0.0412 41.65
52 0.4649 58.59
53 0.2426 49.70
54 0.4108 56.43
55 0.5085 60.34
56 0.5291 61.16
57 0.2903 51.61
58 0.5293 61.17
59 0.2114 48.46
60 0.9438 77.75
61 0.4713 58.85
62 0.8792 75.17
63 0.7071 68.29
64 0.5022 60.09
65 0.2788 51.15
66 0.1454 45.82
67 0.1869 47.48
68 0.8913 75.65
69 0.3237 52.95
70 0.2168 48.67
71 0.5188 60.75
72 0.9751 79.00
73 0.5905 63.62
74 0.1149 44.59
75 0.6317 65.27
76 0.0556 42.22
77 0.3524 54.10
78 0.6774 67.10
79 0.3753 55.01
80 0.1810 47.24
81 0.3287 53.15
82 0.2229 48.91
83 0.4376 57.51
84 0.3901 55.60
85 0.4405 57.62
86 0.2066 48.26
87 0.7786 71.15
88 0.5518 62.07
89 0.8292 73.17
90 0.1914 47.66
91 0.2906 51.63
92 0.0380 41.52
93 0.2824 51.30
94 0.0415 41.66
95 0.1725 46.90
96 0.0379 41.52
97 0.5626 62.51
98 0.2078 48.31
99 0.6997 67.99
100 0.1587 46.35
in any range

erval we care to specify.

dom numbers:

Plot Range
82.80
90.90
26.30
27.30
aws from Continuous Uniform 3.03
100.00
14.10
66.70
41.40
80.80
49.50
97.00
96.00
59.60
67.70
50 55 60 65 70 75 80 85 98.00
Result 70.70
71.70
-
67.70
45.50
43.40
7.07
81.80
52.50
48.50
73.70
8.08
64.60
88.90
56.60
9.09
29.30
78.80
76.80
93.90
12.10
38.40
17.20
77.80
60.60
84.80
89.90
37.40
85.90
60.60
20.20
35.40
94.90
91.90
4.04
50.50
28.30
44.40
54.50
57.60
32.30
58.60
23.20
92.90
51.50
86.90
75.80
53.50
30.30
11.10
18.20
87.90
34.30
24.20
55.60
99.00
65.70
10.10
69.70
6.06
39.40
72.70
40.40
16.20
36.40
25.30
46.50
42.40
47.50
21.20
79.80
62.60
83.80
19.20
33.30
2.02
31.30
5.05
15.20
1.01
63.60
22.20
74.70
13.10
Monte Carlo Simulation

Example 5: Using the RAND( ) function to generate Normal random numbers

Finally, we can embed the RAND( ) function in a =NORMINV( ) function.


This generates random numbers that are normally distributed with a specified mean (mu) and
standard deviation (sigma).
mu sigma
1. Specify mu and sigma for desired normal distribution: 100 15

2. Generate 100 normally-distributed random numbers: hit function key F9 to recalculate the spreadsheet

3. View summary of results, actual mean and standard deviation of sample random numbers:
x-bar s
trial # random# result 96.53 15.63
1 0.5450 101.69
2 0.0813 79.05

Cumulative Count
3 0.7321 109.29
4 0.0215 69.66
5 0.8713 116.99 100 Draws from Normal Distr
6 0.6056 104.02 100
7 0.2848 91.47 90
8 0.1586 85.00
80
9 0.2656 90.61
70
10 0.2517 89.96
60
11 0.6619 106.26
50
12 0.1037 81.09
40
13 0.5833 103.16
30
14 0.0843 79.35
20
15 0.6191 104.55
10
16 0.2207 88.45
-
17 0.2277 88.80 50 100
18 0.2826 91.37
19 0.4925 99.72 Result
20 0.5868 103.29
21 0.0132 66.70
22 0.0976 80.57
23 0.1017 80.92
24 0.9892 134.49
25 0.0643 77.21
26 0.5078 100.29
27 0.2851 91.48
28 0.1522 84.59
29 0.7586 110.53
30 0.8923 118.58
31 0.4677 98.79
32 0.1518 84.57
33 0.9913 135.69
34 0.5433 101.63
35 0.1091 81.53
36 0.3407 93.84
37 0.2611 90.40
38 0.3207 93.01
39 0.6040 103.96
40 0.3757 95.25
41 0.6634 106.33
42 0.0226 69.96
43 0.3454 94.03
44 0.0319 72.19
45 0.3406 93.84
46 0.7777 111.47
47 0.5841 103.19
48 0.8523 115.69
49 0.9845 132.34
50 0.0756 78.47
51 0.8628 116.39
52 0.9550 125.43
53 0.2625 90.46
54 0.4632 98.61
55 0.0020 56.85
56 0.5270 101.02
57 0.8992 119.15
58 0.3966 96.07
59 0.8069 113.00
60 0.4935 99.75
61 0.1991 87.33
62 0.4646 98.67
63 0.0800 78.92
64 0.3792 95.39
65 0.3192 92.95
66 0.1770 86.09
67 0.1271 82.89
68 0.6284 104.92
69 0.8824 117.81
70 0.6039 103.95
71 0.6254 104.80
72 0.9833 131.90
73 0.1785 86.18
74 0.3778 95.33
75 0.5453 101.71
76 0.3002 92.14
77 0.8432 115.11
78 0.4389 97.69
79 0.0840 79.32
80 0.0766 78.57
81 0.2661 90.63
82 0.5546 102.06
83 0.3759 95.26
84 0.4586 98.44
85 0.1760 86.04
86 0.0597 76.64
87 0.6833 107.15
88 0.7450 109.88
89 0.6637 106.34
90 0.4245 97.14
91 0.5990 103.76
92 0.9330 122.48
93 0.1005 80.82
94 0.0149 67.40
95 0.0878 79.69
96 0.9614 126.51
97 0.3535 94.36
98 0.1536 84.68
99 0.4970 99.89
100 0.2595 90.33
Plot Range
64.60
11.10
81.80
3.03
raws from Normal Distribution 89.90
73.70
38.40
24.20
35.40
31.30
77.80
18.20
67.70
13.10
74.70
29.30
100 150 30.30
37.40
Result 58.60
69.70
1.01
15.20
17.20
99.00
7.07
61.60
39.40
22.20
83.80
91.90
57.60
21.20
100.00
63.60
19.20
44.40
33.30
42.40
72.70
47.50
78.80
4.04
45.50
5.05
43.40
84.80
68.70
87.90
98.00
8.08
88.90
94.90
34.30
55.60
-
62.60
92.90
51.50
85.90
59.60
28.30
56.60
10.10
50.50
41.40
26.30
20.20
76.80
90.90
71.70
75.80
97.00
27.30
49.50
65.70
40.40
86.90
53.50
12.10
9.09
36.40
66.70
48.50
54.50
25.30
6.06
80.80
82.80
79.80
52.50
70.70
93.90
16.20
2.02
14.10
96.00
46.50
23.20
60.60
32.30

You might also like