Monte Carlo Simulation: Brett Foster
Monte Carlo Simulation: Brett Foster
Monte Carlo Simulation: Brett Foster
Brett Foster
Monte Carlo In A Nutshell
• Using a large number of simulated trials in
order to approximate a solution to a problem
• Generating random numbers
– Computer not required, though extremely helpful
A Brief History
• Earliest well documented use of Monte Carlo:
– Late 18th Century France
• Comte de Buffon performed an experiment involving
the repeated tossing of a needle onto a plane
• Wanted to determine probability of needle intersecting
a string
Modern Monte Carlo Method
• Named after Monte Carlo Casino in 1940’s by
a group of men working on the nuclear bomb
– John von Neumann, Stanislaw Ulam and Nicholas
Metropolis
• Ulam’s Uncle supposedly often frequented this
Casino
Onset of Computers
• Invention and popularization of computer
– Much more practical to implement Monte Carlo
– Popularity has taken off since 1950’s
Random Numbers
• Key aspect of computers: allow us to quickly
generate thousands of “random” numbers.
– Food for thought:
• Computers are ultimately deterministic devices
– How then can the numbers be “random?”
– We will leave this thought for the philosophers and assume
that we do actually have random numbers
A Simple Example
• Using Monte Carlo to approximate pi
– Will give us a better understanding of how to
implement and analyze a Monte Carlo Simulation
• Obviously, there are more efficient ways to figure out
digits of pi
• This example will help build a conceptual
understanding before looking at another example
• Consider a unit circle inscribed within a square
– The ratio of the area of the circle to the area of
the square is π/4
• We will use this key fact in order to estimate π by
randomly selecting points with the square, and
checking whether they are within the circle
• We will generate n points uniformly
distributed within the square
• Let X denote a binomial random variable
which takes the value 1 if a randomly
generated point falls within the circle and 0 if
the point falls outside of the circle
• X is a Bernoulli R.V. with p = π/4
• Notice: E(X) = π/4 E(4X) = π
• For convenience, let Y = 4X. Now, we estimate
π with
The Simulation:
• This simulation can easily be programmed into
a computer:
– I used VBA in Excel to write a short function to run
our simulation
• We input n, number of trials, and function will
repeatedly select points uniformly distributed within
the square and determine how many fall within the
circle
• Function computes sample mean and returns our
estimate for π :
VBA Code:
Function EstimatePi(n As Integer)
c=0
'loop through proceedure n times
For i = 1 To n
'generate point uniformly within square
x = -1 + 2 * Rnd()
y = -1 + 2 * Rnd()
'Check if within circle
If (x ^ 2 + y ^ 2 < 1) Then
c=c+1
End If
Next
'compute our estimate for pi
EstimatePi = 4 * c / n
End Function
How accurate is this method?
• Consider the variance of our estimate:
• As n changes, we have
Function ValueBasketCall(s1 As Double, s2 As Double, s3 As Double, C12 As Double, C13 As Double, C23 As Double, v1 As Double,
v2 As Double, v3 As Double, a1 As Double, a2 As Double, a3 As Double, r As Double, t As Double, n As Integer)
p=0
m1 = s1 * Exp((a1 - 0.5 * (v1) ^ 2) * t)
m2 = s2 * Exp((a2 - 0.5 * (v2) ^ 2) * t)
m3 = s3 * Exp((a3 - 0.5 * (v3) ^ 2) * t)
For i = 1 To n
u1 = Rnd()
Z1 = WorksheetFunction.NormSInv(u1)
u2 = Rnd()
X2 = WorksheetFunction.NormSInv(u2)
Z2 = C12 * Z1 + X2 * (1 - C12 ^ 2) ^ 0.5
u3 = Rnd()
X3 = WorksheetFunction.NormSInv(u3)
Z3 = C13 * Z1 + X1 * (C23 - C13 * C12) / ((1 - (C12) ^ 2) ^ 0.5) + X3 * ((1 - (C13) ^ 2 - ((C23 - C13 * C12) ^ 2 / (1 - C12 ^ 2))) ^ 0.5)
q1 = m1 * Exp(Z1 * v1 * (t) ^ 0.5)
q2 = m2 * Exp(Z2 * v2 * (t) ^ 0.5)
q3 = m3 * Exp(Z3 * v3 * (t) ^ 0.5)
payoff = WorksheetFunction.Max(0, q1 - 0.5 * (q2 + q3))
p = p + payoff
Next
ValueBasketCall = p * Exp(-r * t) / n
End Function
Analyzing the results:
• As in our pi example, the results are much
more meaningful if we have some idea of their
accuracy
• Define V as the value of the option for a single
trial. Then, our estimate is given by
• CLT is approximately normal
• Also,