如何在R中获取所有Yahoo Finance共同基金的列表?

6
我想要获取通过Yahoo Finance提供的所有共同基金列表,并将其导入R中。在TTR包中有一个stockSymbols函数,但似乎无法获取共同基金。
谢谢。

stockSymbol 函数从纳斯达克网站检索股票列表(该网站还列出了其他几个交易所):如果您知道类似的网页列出了您想要的资产,您可以简单地检索和解析它。 - Vincent Zoonekynd
1
有一个网站(eoddata.com),它拥有完整的共同基金列表,适合对此感兴趣的人。我的问题是,我需要按行业和部门获取共同基金。最可能使用雅虎财经API实现这一目的。 - Volodymyr Kruglov
1个回答

3
我不认为雅虎提供他们拥有数据的所有共同基金的列表(同样,他们也不提供他们涵盖的股票列表)。您可以从您在评论中提到的网站下载列表,循环遍历所有基金,从雅虎检索相应的“简介”页面,并提取所需的信息--“类别”字段似乎是您想要的“部门和行业”的最接近的东西。
# 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)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接