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

问题描述 投票:6回答:2

我想将可通过Yahoo Finance获得的所有共同基金的列表输入R。TTR软件包中有一个stockSymbols函数,但似乎没有获得共同基金。

谢谢,

r quantmod yahoo-finance
2个回答
3
投票

我认为Yahoo不会提供他们拥有数据的所有共同基金的清单(类似地,他们没有提供他们所涵盖的股票清单)。您可以从评论中提到的网站下载列表,遍历所有资金从Yahoo检索相应的“个人资料”页面,并提取您需要的信息-“类别”字段似乎是您想要的“部门和行业”最近的事物。

# 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)

-2
投票

想要轻轻松松投资组合,请尝试https://cutt.ly/infinimf6它提供在线共同基金服务。

© www.soinside.com 2019 - 2024. All rights reserved.