- These slides will show how to use R package quantmod to download stock prices.
- Then I will try to show how these can be plotted using Plotly
- First load the required package
library(quantmod) library(plotly)
October 30, 2017
library(quantmod) library(plotly)
plot_sym<-function(sym){
fin_data<-getSymbols(sym,src="google",env=NULL)
fin_data1<-as.data.frame(fin_data)
fin_data1[,6]<-time(fin_data)
x = list(title = 'Year',
zeroline = TRUE)
y = list(title = 'Opening Stock Price (in $)',
zeroline = TRUE)
plot_ly(x=fin_data1[,6],y=fin_data1[,1],type="scatter",mode="lines") %>%
layout(title="Stock Price",xaxis=x,yaxis=y)
}
plot_sym("GOOG")
plot_sym("AMZN")
plot_sym("AAPL")