You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The first sample app in https://www.opencpu.org/apps.html is very nice, but not operational due to cancellation of Google Finance API. Here is a suggested fix using data from the good guys at IEX.
The function is still called googledata for easy integration, but deserves the name changed to iexdata.
#' IEX data
#'
#' Download historical prices for a given stock from IEX
#'
#' @param ticker stock ticker symbol. E.g. "IBM".
#' @param from start date. Either string or date object.
#' @param to end date. Either string or date object.
#' @return dataframe with historical prices
#' @export
googledata <- function(ticker, from = NULL, to = NULL) {
library(jsonlite)
myurl <- paste0('https://api.iextrading.com/1.0/stock/',ticker,'/chart/5y')
mydata <- fromJSON(myurl) # data.frame
if (length(mydata)==0)
return(NULL) # ticker not found
if (!all( c("date","open","high","low","close","volume") %in% names(mydata))) {
return(NULL) # ticker has incomplete column list
}
mydata <- subset(mydata, select=c(date,open,high,low,close,volume))
mydata$date <- as.Date(mydata$date, tz='')
mydata <- mydata[mydata$date>=as.Date(from) & mydata$date<=as.Date(to),]
names(mydata) <- c('Date','Open','High','Low','Close','Volume')
return(mydata);
}
# test
test.data <- googledata(ticker='IBM', from='2017-07-07', to='2018-05-07');
library(ggplot2)
qplot(Date, Close, data = test.data, geom = c("line", "smooth"));
The text was updated successfully, but these errors were encountered:
The first sample app in https://www.opencpu.org/apps.html is very nice, but not operational due to cancellation of Google Finance API. Here is a suggested fix using data from the good guys at IEX.
The function is still called googledata for easy integration, but deserves the name changed to iexdata.
The text was updated successfully, but these errors were encountered: