Brownian Motion Simulation
Purpose
Illustrations for Brownian Motion properties
> library(sde) > par(mfrow = c(3, 1)) > plot(BM()) > plot(GBM(1, 1, sqrt(0.5))) > plot(BBridge(0, 1)) |
Scaled Random Walk
> gc() used (Mb) gc trigger (Mb) max used (Mb) Ncells 1320897 35.3 2105982 56.3 2105982 56.3 Vcells 13806996 105.4 94822634 723.5 145805771 1112.5 > par(mfrow = c(1, 1)) > set.seed(1977) > test <- function(n) { + T <- 1 + t <- seq(0, T, length = 100) + S <- cumsum(2 * (runif(n) > 0.5) - 1) + W <- sapply(t, function(x) ifelse(n * x > 0, S[n * x], 0)) + W <- as.numeric(W)/sqrt(n) + return(W) + } > cols <- rainbow(4) > set.seed(1977) > plot(t, test(10), type = "l", ylim = c(-2, 2), col = cols[1], + ylab = "") > par(new = T) > plot(t, test(100), type = "l", ylim = c(-2, 2), col = cols[2], + ylab = "") > par(new = T) > plot(t, test(1000), type = "l", ylim = c(-2, 2), col = cols[3], + ylab = "") > par(new = T) > plot(t, test(10000), type = "l", ylim = c(-2, 2), col = cols[4], + ylab = "") > legend("topleft", legend = c("10", "100", "1000", "100000"), + fill = cols) |
BM nowhere differentiable
Simulate a path and let delta approach 0. Using the limit formula for the BM at t = 0.5, we see the limit does not exist and hence it is not differentiable.
> gc() used (Mb) gc trigger (Mb) max used (Mb) Ncells 1320719 35.3 2105982 56.3 2105982 56.3 Vcells 13806887 105.4 48549187 370.5 145805771 1112.5 > set.seed(1977) > Nz <- 10^(1:7) > for (i in seq_along(Nz)) { + N <- Nz[i] + delta <- 1/N + y <- BM(N = N) + x1 <- N/2 + 1 + x2 <- N/2 + 2 + print(abs(y[x1] - y[x2])/delta) + } [1] 6.145777 [1] 8.183401 [1] 53.6134 [1] 49.72411 [1] 68.17444 [1] 936.5277 [1] 3970.497 |
Quadratic Variation converges to t
> gc() used (Mb) gc trigger (Mb) max used (Mb) Ncells 1320689 35.3 2105982 56.3 2105982 56.3 Vcells 13806901 105.4 37834396 288.7 145805771 1112.5 > set.seed(1977) > Nz <- 10^(1:7) > for (i in seq_along(Nz)) { + N <- Nz[i] + delta <- 1/N + y <- BM(N = N) + print(sum(diff(y)^2)) + } [1] 0.9183258 [1] 0.9842033 [1] 1.062219 [1] 0.9905187 [1] 1.004441 [1] 0.9995988 [1] 0.9999596 |