[R] simple loop problemo (Geo brownian motion)

newbster gpm8342 at yahoo.com
Fri Nov 19 19:09:56 CET 2010


I would like to plot multiple random walks onto the same graph.  My p
variable dictates how may random walks there will be.


par(mfrow=c(1,1))
p <- 100
N <- 1000
S0 <- 10
mu <- 0.03
sigma <- 0.2
nu <- mu-sigma^2/2
x <- matrix(rep(0,(N+1)*p),nrow=(N+1)) 
y <- matrix(rep(0,(N+1)*p),nrow=(N+1)) 
t<- (c(0:N))/N
for (j in 1:p)
{
z <- rnorm(N,0,1)
x[1,j] <- 0
y[1,j] <- S0
for (i in 1:N)
{
x[i+1,j] <- (1/sqrt(N))*sum(z[1:i])
y[i+1,j] <- y[1,j]*exp(nu*t[i+1]+sigma*x[i+1,j])
}

plot(t,y,type="l",xlab="time", ylab="Geometric Brownian motion")

}


Any help would be appreciated, thanks.


-- 
View this message in context: http://r.789695.n4.nabble.com/simple-loop-problemo-Geo-brownian-motion-tp3050762p3050762.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list