hierbei handelt es sich um eine Hausaufgabe für die Uni. Der Code läuft soweit, die Grafik muss nur noch "nach oben" verschoben werden. Es musste eine Geometrische Brownsche Bewegung simuliert werden. Mit Startwert 100, 250 Tage, Return 5% und Sigma 30%. Diese Simulation soll 1000 mal stattfinden. Führe ich die Simulation 1 mal durch passt alles soweit
Code: Alles auswählen
t <- 0:250 # time
sig2 <- 0.30/250
## first, simulate a set of random deviates
x <- rnorm(n = length(t) - 1, mean = 0.05/250, sd = sqrt(sig2))
## now compute their cumulative sum
x <- c(0, cumsum(x))
y <- 100 + x
plot(t, y, type = "l", ylim = c(98, 102))
Code: Alles auswählen
nsim <- 1000
x <- matrix(rnorm(n = nsim * (length(t) - 1), sd = sqrt(sig2)), nsim, length(t) -
1)
x <- cbind(rep(0, nsim), t(apply(x, 1, cumsum)))
plot(t, x[1, ], xlab = "time", ylab = "GBM", ylim = c(-2, 2), type = "l")
apply(x[2:nsim, ], 1, function(x, t) lines(t, x), t = t)
Liebe Grüße
Paulina