【问题标题】:AlphaVantager Time series set YYYY MM DD HH MM SSAlphaVantager 时间序列集 YYYY MM DD HH MM SS
【发布时间】:2017-11-11 19:44:43
【问题描述】:

我已经使用 R 中的 alphavantager 包下载了数据。我正在尝试将分钟数据设置为时间序列 xts 对象。

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)

当我运行is.xts(df) 时,我得到一个输出FALSE。我正在尝试将GOOG$timestamp 设置为具有以下格式的xts 对象:YYYY MM DD HH MM SS,以便我可以从quantmod 包中运行chartSeries

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"

我怎样才能在 R 中做到这一点?

编辑:我从chartSeries 函数得到的错误:

chartSeries(df, TA=NULL)

> Error in try.xts(x, error = "chartSeries requires an xtsible object") : 
  chartSeries requires an xtsible object

【问题讨论】:

    标签: r time-series quantmod


    【解决方案1】:

    quantmod 不同,alphavantager 不会将数据转换为xts 对象。因此,您必须自己做。这应该有效:

    df <- xts(GOOG[,-1], order.by = as.POSIXct(GOOG$timestamp))
    

    【讨论】:

      猜你喜欢
      • 2019-02-17
      • 2020-05-10
      • 2018-06-16
      • 2018-11-08
      • 2013-07-22
      • 1970-01-01
      • 1970-01-01
      • 2012-11-29
      • 2021-10-13
      相关资源
      最近更新 更多