Upload
anthonyconnor
View
15
Download
2
Embed Size (px)
DESCRIPTION
sample
Citation preview
MonteCarlito 1.10Martin Auer, 2004-2010Distributed under terms of GNU General Public License
This tutorial explains how MonteCarlito can be used to run Monte Carlosimulations in Excel.
Monte Carlo simulations are often used to compute mathematical functionswhere no fast, analytical solution exists (e.g., some financial functions,or integrals), or to look at the statistical behaviour of complex systems.
Example 1: Basics
Basically, in a Monte Carlo simulation you analyze a random function, often toget its average result (its so-called "expected value"). Say you are offeredto play the following game: you throw a dice, and get 1$ it you throw 1, 4$ if 2, 9$ if 3, 16$ if 4, 25$ if 5, and 36$ if 6. But you also have to pay 14$ upfront to participate. Would you play that game?
To answer that question, you determine the expected profit/loss; an easy wayto do this is to simulate the game many times and average the individual outcomes.
To simulate this in Excel, first you need to create a random number from 0-1 with RAND():
Random number: 0.111997499 (press F9 several times to see how this number changes.)
From this, derive a dice using a mathematical function:
Dice: 1 (again, press F9 several times to see how this number changes.)
To play the game once, determine the profit of the dice throw, and subtract the costs:
Game profit: 1Costs: 14
One game's profit/loss: -13
Pressing F9 repeatedly reveals that sometimes you win, sometimes you lose money. If you repeat this many times and analyze the outcomes, you can determine if you should play.
MonteCarlito is a tool to help you with that.Just put the result of one (random) outcome in any cell, and write "1000" next to it:
1000 -13 (check with F9 it the outcome still changes)
www.montecarlito.com
Now, select the whole light blue area (2x2 cells) and press Ctrl+W.MonteCarlito runs the simulation 1000 times, and gives you the average result. If it's positive, you should play!
To simulate this in Excel, first you need to create a random number from 0-1 with RAND():
(press F9 several times to see how this number changes.)
(again, press F9 several times to see how this number changes.)
If you repeat this many times and analyze the outcomes, you can determine if you should play.
(check with F9 it the outcome still changes)
MonteCarlito runs the simulation 1000 times, and gives you the average result. If it's positive, you should play!
Example 2: Area of the circle
Say you forgot the number PI.Monte Carlo simulation is one way to approximate it (and more often, more difficult integrals).
You could throw a dart at a 4cm x 4cm sized rectangle with a circle painted on it,repeat this 1000 times, and count the number of throws landing in the circle area (call it C) andthe number of throws landing on the rectangle, in- or outside the circle (call this number R).
The ratio of C/R should be fairly similar to the ratio of the circle area and the rectangle area (which is 4 x 4 = 16):
C/R = circle area/16
The circle area is thus 16xC/R.But it is also r^2 x PI = 2 x 2 x PI
Thus PI = 4 x C/R
To simulate one dart throw, first create two random numbers (the x and y coordinate) between -2 and 2:
x yThrow to coordinates: -0.93262955 1.932368641 (press F9 a few times to make sure that the throw is between -2 and 2 in both axes)
Check if it is inside the circle: 0 (1=inside circle, 0 outside)
Now, use MonteCarlito with 1000 throws (ie, R=1000):
1000 0 (select blue area and press Ctrl+W)Mean 0.805
805 is the number of circle hits C1000 is the number of throws R
Estimated PI = 4 x C/R: 3.220
Monte Carlo simulation is one way to approximate it (and more often, more difficult integrals).
repeat this 1000 times, and count the number of throws landing in the circle area (call it C) andthe number of throws landing on the rectangle, in- or outside the circle (call this number R).
The ratio of C/R should be fairly similar to the ratio of the circle area and the rectangle area (which is 4 x 4 = 16):
To simulate one dart throw, first create two random numbers (the x and y coordinate) between -2 and 2:
(press F9 a few times to make sure that the throw is between -2 and 2 in both axes)
(1=inside circle, 0 outside)
(select blue area and press Ctrl+W)
Example 2: Project management
Project planning tools assign effort estimates to subtasks.Total project effort is the sum of the individual efforts.
It's more realistic to treat the subtasks as having random efforts,the total effort is the sum of those random variables.
MonteCarlito can not only answer the expected total effort, butalso its distribution, and thus answer questions like "what are the 10% of outcomes that are worst?"
A very similar issue arises when computing financial measure like the value-at-risk (VAR).
Subtask 1, between 20 and 30 days: 23.81357663Subtask 2, usually 15 days, but sometimes much longer: 32.17683737
Total effort: 1000 55.990414Mean 47.95866648Standard error 0.321932681Median 45.5857Standard deviation 10.18040526Variance 103.6406513
Select the blue area and press Ctrl+W.
The expected total effort is: 47.95866648
The standard deviation*1.96 is: 19.95359431
This means roughly that in 95% of all outcomes, the effort is between 47.95866648and 47.95866648
also its distribution, and thus answer questions like "what are the 10% of outcomes that are worst?"
plus 19.95359431minus 19.95359431
MonteCarlito
Instructions:
1. Put all N formulas you want to simulate next to each other, preceded by the number of trials you want to run.
2. Select the N+1 cells and the 7x(N+1) cells beneath (indicated by frame).
3. Run macro "simulate" or press Ctrl+W to run simulation. Result:
1000 0.6762 2971.9361 0.8963Mean 0.5036 2198.8597 -0.0131Standard error 0.0094 135.6636 0.0309Median 0.4878 186.1393 -0.0174Standard deviati 0.2986 4290.0602 0.9761Variance 0.0891 18404616.8190 0.9529Skewness 0.0039 2.4879 0.0473Kurtosis 1.7135 8.7563 2.9563
Note:- If the number of trials is negative, simulation is run in high-speed mode with minimized windows.- If the cell with the number of trials has bold font type, histograms are created at end of simulation run.- If you select less than 7 rows of cells beneath formulas, you get less output.
Examples:
1. Put all N formulas you want to simulate next to each other, preceded by the number of trials you want to run. a) Select range I11:K13; press Ctrl+W.
100 0.8991 -0.4822
b) Select range I18:J21; press Ctrl+W (a new workbook will be created with histogram).
1000 -0.23689273278
b) Select range I18:J21; press Ctrl+W (a new workbook will be created with histogram).