forked from joyharjanto/mcmc-stock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandomwalk
29 lines (18 loc) · 798 Bytes
/
randomwalk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
random walk: Rooted in past performance is not an indicator of future results. Price fluctuations can not be predicted with accuracy
mu<-AMZN_mean_log
sig<-AMZN_sd_log
testsim<-rep(NA,1000)
#generate random daily exponent increase rate using AMZN's mean and sd log returns
#one year 252 trading days, simulate for 4 years
# 4*252 trading days
price<-rep(NA,252*4)
#most recent price
price[1]<-as.numeric(AMZN$AMZN.Adjusted[length(AMZN$AMZN.Adjusted),])
#start simulating prices
for(i in 2:length(testsim)){
price[i]<-price[i-1]*exp(rnorm(1,mu,sig))
}
random_data<-cbind(price,1:(252*4))
colnames(random_data)<-c("Price","Day")
random_data<-as.data.frame(random_data)
random_data%>%ggplot(aes(Day,Price))+geom_line()+labs(title="Amazon (AMZN) price simulation for 4 years")+theme_bw()