Brownian Motion in R
Brownian Motion in R
0. This is an optional project for extra credit only. Your grade will not be affected if you decline to
do it. Steps 1-4 are preparatory. Step 5 describes the finished product. This part of the project
should be submitted as a Canvas assignment by 11:59 pm on Wednesday, November 25.
1. Introduction: Brownian motion with drift parameter µ and variance parameter σ 2 is the process
Xt = µt + σBt ,
Gt = G0 eXt ,
where G0 > 0. For this super-double-bonus-extra-credit part of the project, you will create a
geometric Brownian motion simulator by adapting your random walk generator form the first part
of the project.
2. You may use my random walk generator if you wish. Go to Canvas/Files/R/randomwalk.R and
download. It generates a random walk on [0, T ] with n time steps, spatial increment dx and
probability p of a step to the right. Once you’ve downloaded it and used the R source command
to activate it in your workspace, try typing randomwalk(1,20,.1,.5). You should get a random
walk on [0, 1] with 20 time steps, spatial increment dx = .1, with p = .5 .
3. To approximate standard Brownian motion, we used a symmetric random walk, i.e. a random
walk with p√= .5. So you should fix p at this value. We also set the diffusion coefficient to 1/2, so
that ∆x = ∆t. Hence √ you can get rid dx as a variable. Once you’ve defined dt in the body of
your code, just set dx = dt. With these changes, your random walk generator can be considered
a standard Brownian motion simulator as long as you choose dt = T /n small enough. Try it out
with T = 1 and n = 100. You should get something resembling a Brownian path.
4. It is very easy to modify your code to simulate Brownian motion with drift. It already plots an
approximation to Bt . You have to figure out how to multiply that by σ and add µt. Here is a
sample path on [0, 1], with n = 200 time steps, µ = .1 and σ 2 = .04.
0.00
−0.05
−0.10
t
5. Last step: This one should be very easy. Modify your code so that it takes the additonal argument
G0 > 0, and then plots Gt = G0 eXt on an interval [0, T ]. In particular,
a. Give the finished product an appropriate name such as GeoBromo.R.
b. The first line of your code should be something like
GeoBromo ← function(T, n, µ, σ, G0 ){
Once again, you don’t have to call the function “GeoBromo” but it’s certainly a reasonable choice.
Feel free to use m, s and G0 (or any other approriate variable names) instead of µ, σ and G0 .
c. Your code should be (lightly) commented.
d. The command GeoBromo(T,n, µ, σ, G0 ) should produce a plot of G0 eXt on [0, T ] with n time
steps of size dt = T /n, and whatever values of µ, σ and G0 you choose. It should look something
like this:
Geometric Brownian Motion with drift parameter 0.6 ,
variance parameter 0.04 and initial value 2
3.5
3.0
x
2.5
2.0