[R] Monte Carlo Random Walk

jerome evan.e.scott at gmail.com
Wed Oct 19 00:33:02 CEST 2011


Hello all,

I am quite new to R, with the goal of using it for a project in my business
course. I am attempt to run a Monte Carlo simulation of futures prices based
on a random  walk whereby the given volatility (I will use historical
volatility in this case, say 12%) is Levy-distributed , equally likely to go
up or down, and there are 25 discrete steps (to be repeated 1000x).

I have a poor statistics background, but I believe this is how I would need
to begin to model the run within R:

1. xn = future price on day n
2. x1 = Random number between 40-140 (arbitrary range)
3. For all xn where n > 1, xn = x(n-1) * (1 + RandomLevyNumber(c=Daily
Volatility, Alpha))
4. Daily Volatility = 12%
5. Alpha 1.7

My output would be a 25x1000 matrix (that I could manipulate/sample/etc
within R or export into Excel or Matlab). With the results of that matrix, I
would utilize various statistical tests and explore various models to
analyse the results.

Coding wise, I have this so far:


library(fBasics)
sims <- 1000 # 1000 simulations
runs <- matrix(sims) # Matrix to store the 1000 runs
prices <- matrix(sims) # Matrix to store the 25 values simulated in each run

for(i in 25:sims){ # Start the loop
v <- rstable(35,.5,1,gamma,delta). # Generate random Levy #. Unsure of the
parameters to use.
p1 <- runif(40:140, 1)
p2-25 <- p(n-1) * 1+v(???) #I am attempting to recreate the function I
described in step 3 above.

} # End loop




Any guidance on where to go from here, what I am doing wrong, or any general
direction I should go in would be greatly appreciated. I am in a rut and do
not have a lot of resources to lean on here.

--
View this message in context: http://r.789695.n4.nabble.com/Monte-Carlo-Random-Walk-tp3917010p3917010.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list