gpt4 book ai didi

r - 错误 "Index vectors are of different classes: numeric date"

转载 作者:行者123 更新时间:2023-12-05 00:37:04 24 4
gpt4 key购买 nike

我正在尝试从以下站点实现以下代码:

library(quantmod)
library(tseries)
library(timeDate)

symbols <- read.csv("sp500.csv", header = F, stringsAsFactors = F)
nrStocks <- length(symbols[,1])

z <- zoo()
for (i in 1:nrStocks) {
cat("Downloading ", i, " out of ", nrStocks , "\n")
x <- get.hist.quote(instrument = symbols[i,], start = dateStart,
quote = "AdjClose", retclass = "zoo", quiet = T)
z <- merge(z, x)
}

但我收到错误消息:
Error in download.file(url, destfile, method = method, quiet = quiet) : 
cannot open URL 'http://chart.yahoo.com/table.csv?s=MFE&a=0&b=01&c=2008&d=8&e=12&f=2011&g=d&q=q&y=0&z=MFE&x=.csv'
In addition: There were 50 or more warnings (use warnings() to see the first 50)

In merge.zoo(z, x) : Index vectors are of different classes: numeric Date

有任何想法吗?

最佳答案

以下是可能的问题列表:

  • "sp500.csv" :您需要从某个地方获取此文件。如果您从 here 获取此代码那么一种可能性是 this但该列表已过时
  • z <- zoo() :这不会有日期格式的索引,因此会导致合并警告,因此可能明智地后面跟着一行 index(z) <- as.Date(format(time(z)),tz="")
  • start = dateStart, : 您没有指定 dateStart .如果你想要最后一个月左右,那么像 start = Sys.Date() - 30,可能有用
  • 错误的股票代码:错误消息显示您的列表包含 MFE作为标志之一。 MFE 是 McAfee Inc,它已被英特尔公司接管,因此不再有报价的股价。
  • 关于r - 错误 "Index vectors are of different classes: numeric date",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7411216/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com