【问题标题】:Using Yahoo! database without quantmod functions使用雅虎!没有 quantmod 函数的数据库
【发布时间】:2015-06-15 02:02:42
【问题描述】:

我要解决的问题是使用 Yahoo! 循环通过 R 的字符串!金融API。这会生成一堆数据框文件,但如果我可以将其转换为xts,那就太棒了。但是,xts 部分并不那么重要。

library(quantmod)
DB <- quantmod:::DDB_Yahoo()       
for (i in length(DB$db)){
  symbols <- DB$db[i] #symbols are c('AAIT', 'AAL', 'AAME', ...   #Thousands Essentially 
URL <- "http://ichart.finance.yahoo.com/table.csv?s=symbols"
dat[i] <- read.csv(URL[i])
dat$Date <- as.Date(dat$Date, "%Y-%m-%d")

我知道我们不能在 ("") 引号中使用符号,但这是出于逻辑目的。

附言对于这种情况,我不是故意使用quantmod 函数。

【问题讨论】:

    标签: r loops yahoo-finance


    【解决方案1】:
    x<-c('AAIT', 'AAL', 'AAME')
    kk<-lapply(x,function(i) download.file(paste0("http://ichart.finance.yahoo.com/table.csv?s=",i),paste0(i,".csv")))
    

    如果你想直接读取文件:

    jj<- lapply(x,function(i) read.csv(paste0("http://ichart.finance.yahoo.com/table.csv?s=",i)))
    

    【讨论】:

    • 好的,谢谢,但是我如何将它应用到library(quantmod) DB &lt;- quantmod:::DDB_Yahoo() Stocks &lt;- as.matrix(DB$db) yahoodatabase &lt;- function(){} for (i in length(DB$db)){ symbols &lt;- DB$db[i] return(symbols)} URL &lt;- lapply(x,function(i) read.csv(paste0("http://ichart.finance.yahoo.com/table.csv?s=",i))) dat[i] &lt;- read.csv(URL[i]) dat$Date &lt;- as.Date(dat$Date, "%Y-%m-%d") }
    • 我的错:这更好,但我收到错误for (i in length(DB$db)){ symbols &lt;- DB$db[i] URL &lt;- lapply(symbols,function(i) read.csv(paste0("http://ichart.finance.yahoo.com/table.csv?s=",i))) dat[i] &lt;- read.csv(URL[i]) dat$Date &lt;- as.Date(dat$Date, "%Y-%m-%d") } Error in read.table(file = file, header = header, sep = sep, quote = quote, : 'file' must be a character string or connection
    • 为什么要读两次文件?当你已经有 lapply 时,你也不需要 for 循环。
    • 您只需要将 x 替换为 DB 。另外,如果可行,请将答案标记为accepted
    • 完全生病的人。甜的!!! `symbols ichart.finance.yahoo.com/…))'
    猜你喜欢
    • 1970-01-01
    • 2022-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多