r - 如何获取 R 中所有雅虎财经共同基金的列表?

标签 r quantmod yahoo-finance

我想把所有通过雅虎财经可用的共同基金的列表放到R里。TTR包里有一个stockSymbols函数,但是好像没有拿到共同基金。

谢谢,

最佳答案

我认为雅虎没有提供他们拥有数据的所有共同基金的 list
(同样,他们不提供他们所涵盖的股票 list )。
您可以从评论中提到的网站下载列表,
循环所有资金,
从雅虎检索相应的“个人资料”页面,
并提取您需要的信息——“类别”字段
似乎是最接近你想要的“部门和行业”的东西。

# Read the list of funds
# I assume the file was downloaded manually from 
#   http://www.eoddata.com/Data/symbollist.aspx?e=USMF
# This requires registration (free).
d <- read.delim( "USMF.txt", stringsAsFactors = FALSE )

# Retrieve the profile page, for each of the funds.
# It takes 1 second for each, and there are 24,000 of them:
# this may take more than 6 hours.
library(RCurl)
library(stringr)
d$Category <- ""
for( i in seq_len(nrow(d)) ) {
  try({
    url <- paste0("http://uk.finance.yahoo.com/q/pr?s=", d$Symbol[i])
    cat( url, " " )
    profile <- getURL(url)
    row  <- str_extract(profile, "Category.*?</tr>")
    cell <- str_extract(row,     "<td.*</td>"      )
    d$Category[i] <- str_replace_all( cell, "<.*?>", "" )
    cat( d$Category[i], "\n" )
  })
}
head(d)

关于r - 如何获取 R 中所有雅虎财经共同基金的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17759621/

相关文章:

linux - 除了使用 Ctrl + C 之外,如何在 linux 中停止正在运行的 R 命令?

r - 在数据帧中保留具有定义数量的 NA 的行

用于替换 1 之前出现的每个零的 R 逻辑

java - 如何解决雅虎财经API的临时移动错误

替换出现在字符串末尾的文本

r - Quantstrat 多种货币。 Blotter::UpdateAcct 中可能有错误吗?

r - 将 getSymbols 结果合并到一个 xts 对象中

r - 在 R 中使用 quantmod 绘制 SPX 与 VIX

yahoo-finance - 如何从雅虎财经获取商品数据?

cookies - 雅虎财经历史数据下载器网址不起作用