[R-SIG-Finance] Plot GBM density in a 3 d plot

Maximilian Lklweryc maxlklweryc at gmail.com
Wed Nov 28 14:29:03 CET 2012


Hi,
I have the following problem:
I simulated a lot of final values of stock prices. So for example when
I use Geometric Brownian Motion the final values should be lognormal
distributet, this plot can be seen here:

http://de.wikipedia.org/wiki/Datei:GBM_density_develop.png


I want to recreate the plot. I have adjusted color and so, but I do
not know how to do this? My example with a wrong formula is:

sigma<- 0.1
mu<-0.1

farbe<-rgb(85, 141, 85, maxColorValue=255)

x <- seq(-40, 40, length= 10)
y <- c(1:22)
f <- function(x,y) { r <-
1/(sqrt(2*pi)*sigma*y*x)*exp(-(log(x)-mu*y)^2/2*(sigma*y)^2); r }
z <- outer(x, y, f)

z[is.na(z)] <- 1
op <- par(bg = "gray80")
persp(z, theta = -60, phi = 30, expand = 0.5, col = farbe,
     ticktype = "detailed",
      xlab = "X", ylab = "Y", zlab = "Z"
)

First of all I want to have the theoretical 3d density. Later on I
want to create a second plot with the empirical 3d density. I have the
simulated values but I do not know how to plot this?

Thanks a lot for your help!



More information about the R-SIG-Finance mailing list