Brownia Motion: http://math.hawaii.edu/~xander/Fa06/Kac--Brownian_Motion.pdf.
bm <- cumsum(rnorm(1000,0,1))
bm <- bm - bm[1]
plot(bm, main = "Brownian Motion", col = "blue", type = "l")
acf(diff(bm), main = "Autocorrelation of Wt")
par(mfrow = c(2,1))
hist(diff(bm), col = "orange", breaks = 100, main = "Wt-s Distribution")
qqnorm(diff(bm))
qqline(diff(bm))
bm <- cumsum(rnorm(1000,0,1))
bm <- bm - bm[1]
plot(bm, main = "Brownian Motion", col = "blue", type = "l")
acf(diff(bm), main = "Autocorrelation of Wt")
par(mfrow = c(2,1))
hist(diff(bm), col = "orange", breaks = 100, main = "Wt-s Distribution")
qqnorm(diff(bm))
qqline(diff(bm))
bm <- cumsum(rnorm(1000,0,1))
bm <- bm - bm[1]
plot(bm, main = "Brownian Motion", col = "blue", type = "l")
acf(diff(bm), main = "Autocorrelation of Wt")
par(mfrow = c(2,1))
hist(diff(bm), col = "orange", breaks = 100, main = "Wt-s Distribution")
qqnorm(diff(bm))
qqline(diff(bm))
bm <- cumsum(rnorm(1000,0,1))
bm <- bm - bm[1]
plot(bm, main = "Brownian Motion", col = "blue", type = "l")
acf(diff(bm), main = "Autocorrelation of Wt")
par(mfrow = c(2,1))
hist(diff(bm), col = "orange", breaks = 100, main = "Wt-s Distribution")
qqnorm(diff(bm))
qqline(diff(bm))
Assume the stock has 50% chance go up, and 50% change go down, we toss a coin 1000 times, head means up, tail means down. How many times should we expect to see 5 heads or 5 tails in a row? What is the change that the chance stock goes up 5 days in a row or goes down 5 days in a row? This is a problem that can easily be solved by repeated sampling from a known distribution.
run5 <- numeric(10000)
for(i in 1:10000) {
run5[i] <- sum(rle(sample(c(-1, 1), 1000, TRUE))$lengths == 5)
}
hist(run5)
mean(run5)
## [1] 15.5998
abline(v = mean(run5),col = "blue",lwd = 4)