![](/img/trans.png)
[英]How to get company description, statistics using R from eg. Yahoo Finance?
[英]How to get the list of all Yahoo Finance mutual funds in R?
我想将通过Yahoo Finance可用的所有共同基金的列表添加到R中。TTR程序包中有一个stockSymbols函数,但似乎没有获得共同基金。
谢谢,
我认为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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.