getSymbols("NFLX",from="2020-01-01",to="2020-12-30")
## 'getSymbols' currently uses auto.assign=TRUE by default, but will
## use auto.assign=FALSE in 0.5-0. You will still be able to use
## 'loadSymbols' to automatically load data. getOption("getSymbols.env")
## and getOption("getSymbols.auto.assign") will still be checked for
## alternate defaults.
##
## This message is shown once per session and may be disabled by setting
## options("getSymbols.warning4.0"=FALSE). See ?getSymbols for details.
## [1] "NFLX"
NFLX_log_returns<-NFLX%>%Ad()%>%dailyReturn(type='log')
tail(NFLX_log_returns, 10)
## daily.returns
## 2020-12-15 -0.0050661286
## 2020-12-16 0.0096687321
## 2020-12-17 0.0152594013
## 2020-12-18 0.0029043688
## 2020-12-21 -0.0104199692
## 2020-12-22 -0.0029916632
## 2020-12-23 -0.0246699278
## 2020-12-24 -0.0009918014
## 2020-12-28 0.0099702191
## 2020-12-29 0.0223821001
# The first chart series graph is straightforward as it shows Amazon’s price chart.
NFLX%>%Ad()%>%chartSeries()
# The second chart series show the Bollinger Band chart, % Bollinger change, Volume Traded and Moving Average Convergence Diverence in 2020 alone.
NFLX%>%chartSeries(TA='addBBands();addVo();addMACD()',subset='2020')
set.seed(2021)
# random walk: Rooted in past performance is not an indicator of future results. Price fluctuations can not be predicted with accuracy
NFLX_mean_log <- mean(NFLX_log_returns$daily.returns)
NFLX_sd_log <- sd(NFLX_log_returns$daily.returns)
mu<-NFLX_mean_log
sig<-NFLX_sd_log
testsim<-rep(NA,252)
#generate random daily exponent increase rate using AMZN's mean and sd log returns
#one year 252 trading days, simulate for 1 years
price<-rep(NA,252)
#most recent price
price[1]<-as.numeric(NFLX$NFLX.Adjusted[length(NFLX$NFLX.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))
colnames(random_data)<-c("Price","Day")
random_data<-as.data.frame(random_data)
random_data%>%ggplot(aes(Day,Price))+geom_line()+labs(title="Netflix (NFLX) price simulation for year 2021")+theme_bw()
set.seed(2021)
N<-500
mc_matrix<-matrix(nrow=252,ncol=N)
mc_matrix[1,1]<-as.numeric(NFLX$NFLX.Adjusted[length(NFLX$NFLX.Adjusted),])
for(j in 1:ncol(mc_matrix)){
mc_matrix[1,j]<-as.numeric(NFLX$NFLX.Adjusted[length(NFLX$NFLX.Adjusted),])
for(i in 2:nrow(mc_matrix)){
mc_matrix[i,j]<-mc_matrix[i-1,j]*exp(rnorm(1,mu,sig))
}
}
name<-str_c("Sim ",seq(1,500))
name<-c("Day",name)
final_mat<-cbind(1:(252),mc_matrix)
final_mat<-as_tibble(final_mat)
## Warning: The `x` argument of `as_tibble.matrix()` must have unique column names if `.name_repair` is omitted as of tibble 2.0.0.
## Using compatibility `.name_repair`.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
colnames(final_mat)<-name
dim(final_mat)
## [1] 252 501
final_mat%>%gather("Simulation","Price",2:501)%>%ggplot(aes(x=Day,y=Price,Group=Simulation))+geom_line(alpha=0.2)+labs(title="Netflix Stock (NFLX): 500 Monte Carlo Simulations for year 2021")+theme_bw()
probs<-c(0.005,0.025,0.25,0.5,0.75,0.975,0.995)
final_mat[31,-1]%>%as.numeric()%>%quantile(probs=probs)
## 0.5% 2.5% 25% 50% 75% 97.5% 99.5%
## 385.1107 410.5165 514.2704 568.1590 629.4925 758.0070 815.4182
The actual price for netflix on Feb 12 2021 is $556.52. Whearas the inter-quantile price range is 514 to 629 The model is not ridiculous
probs<-c(0.005,0.025,0.25,0.5,0.75,0.975,0.995)
final_mat[252,-1]%>%as.numeric()%>%quantile(probs=probs)
## 0.5% 2.5% 25% 50% 75% 97.5% 99.5%
## 248.0157 344.5871 629.4021 872.1327 1226.8996 2201.0924 2706.0421
# Chance that the price drops below that on Feb 12
sum(final_mat[252,-1] < 556.52)/500
## [1] 0.168
There is a 16.8% chance that by the end of this year, netflix stock drops its price below that of today at 556.52. However, the inter-quantile price range is still incentive, which is 629 to 1226