Professional Documents
Culture Documents
getSymbols("AMZN",from="2001-01-01",to="2019-05-01")
amzn_price=AMZN$AMZN.Adjusted
amzn_ret=diff(log(amzn_price))[-1]
mean=mean(amzn_ret)
sd=sd(amzn_ret)
N <- 1000
mu <- mean
sigma <- sd
price_init=AMZN$AMZN.Adjusted[[nrow(AMZN$AMZN.Adjusted)]]
# Simulate prices
set.seed(111)
for(i in 2:N) {
}
price_sim <- cbind(day, price) %>% as_tibble()
#It looks like we are going to lose money with this investment.
#Here we repeatedly perform the random walk simulation process hundreds or thousands of times.
# Simulate prices
set.seed(1145)
for (j in 1:M) {
for(i in 2:N) {
}
}
names(price_sim) <- nm
# Visualize simulation
price_sim %>%
geom_line(alpha = 0.1) +
ggtitle(str_c("Microsoft: ", M,