I have a list of tickers (~11,500) in a .txt/.csv file and accompanying fund data from yahoo finance. I'm wondering if there is a reasonably easy/accessible way to use this list to obtain expense ratios from yahoo finance or elsewhere? Is it a case of writing a C#/Javascript to queery the YQL 11500 times to http://finance.yahoo.com/q/pr?s=TICKER and then store data from the section: Annual Report Expense Ratio (net): X.YZ% ?

Any help greatly appreciated.

Best wishes


3 Answers 3


Python version of Brian's R code:

Brian's code automatically grabs the first expense ratio it finds, which is the one you wanted. This version is a little more explicit.

import urllib2, re
stockSymbols = [ "VDIGX", "VFIAX" ]
expenses = [ [ "Fund", "Most Recent Expense Ratio" ] ]
for stockSymbol in stockSymbols:
    page = urllib2.urlopen("http://finance.yahoo.com/q/pr?s=" + stockSymbol + "+profile" )
    data = page.read()
    row = re.findall("Annual Report Expense Ratio.*?</tr>", data)
    if len(row) > 0:
        ER = re.findall("<td.*?>(\d+\.\d+).*?</td>", row[0] )[0]
        expenses.append( [ stockSymbol, ER ] )
        print stockSymbol, "does not appear to be a fund with an expense ratio"
print "\n".join( i[0] + "," + i[1] for i in expenses )

If you're building a technical system that you want to be easily updatable, then yes. a C# query is probably your best bet. A cursory search around Yahoo reveals no-such functionality, and the fact that no one else has jumped on this question with an answer only serves to bolster that case. If you need help with implementation (which isn't in your question) just let me know, and I'll put together a toy example. Good Luck!


I once used some code from SO to do a similar task. Here's a bit of a modification. It's slow but you don't need it often.

syms <- c('VDIGX','VFIAX')
for(sym in syms){
    url <- paste0("http://finance.yahoo.com/q/pr?s=", sym,"+profile")
    profile <- getURL(url)
    row  <- str_extract(profile, "Expense Ratio.*?</tr>")
    cell <- str_extract(row, "<td.*</td>")
    mer <- str_replace_all( cell, "<.*?>", "" )
    cat(sym,cell," ")
  • $\begingroup$ For those that aren't programmers, this is the R language. Great for doing statistical work, not so great for most other tasks. $\endgroup$
    – chollida
    Jun 9, 2014 at 17:04
  • $\begingroup$ @chollida, thanks, I spent too much time trying to figure out how to pretty print it, I forgot to mention that. The language won't make any difference to the speed of downloading 11k pages. $\endgroup$
    – brian
    Jun 9, 2014 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.