I have downloaded data using the alphavantager
package in R. I am trying to set minute data as a time series xts
object.
rm(list = ls())
library(alphavantager)
AlphaKey <- av_api_key("YOUR API Key (Free) - (obtainable here: https://www.alphavantage.co/support/#api-key) ")
print(AlphaKey)
args(av_get)
GOOG <- av_get(symbol = "GOOG", av_fun = "TIME_SERIES_INTRADAY", interval = "1min", outputsize = "full")
plot(GOOG$close)
close_price <- GOOG$close
times <- as.POSIXct(GOOG$timestamp, format="%d/%m/%Y %H:%M")
times
times <-format(GOOG$timestamp, format="%H:%M:%S")
df <- cbind(times, close_price)
When I run is.xts(df)
, I get an output FALSE
. I am trying to set the GOOG$timestamp
as an xts object with the following format: YYYY MM DD HH MM SS
so that I can run chartSeries
from the quantmod
package.
head(GOOG$timestamp)
[1] "2017-10-30 09:30:00 UTC"
[2] "2017-10-30 09:31:00 UTC"
[3] "2017-10-30 09:32:00 UTC"
[4] "2017-10-30 09:33:00 UTC"
[5] "2017-10-30 09:34:00 UTC"
[6] "2017-10-30 09:35:00 UTC"
How can I go about doing this in R?
EDIT: The error I get from the chartSeries
function:
chartSeries(df, TA=NULL)
> Error in try.xts(x, error = "chartSeries requires an xtsible object") :
chartSeries requires an xtsible object
Unlike quantmod
, alphavantager
does not convert data into an xts
object. Therefore, you must do it yourself. This should work:
df <- xts(GOOG[,-1], order.by = as.POSIXct(GOOG$timestamp))