Search code examples
rquantmod

How to load P/E ratio for S&P 500 ETFs


Using quantmod I can load P/E ratios of company stocks, but not ETFs even though they can be viewed on Yahoo financial webpage. For example, for SPY it can be veiwed here http://finance.yahoo.com/q?s=SPY&fr=uh3_finance_web&uhb=uhb2. However, the command in R does not produce anything:

getQuote("SPY", what = yahooQF("P/E Ratio"))
             Trade Time P/E Ratio
SPY 2016-05-17 04:00:00       N/A

It works fine for stocks though:

getQuote("MSFT", what = yahooQF("P/E Ratio"))
              Trade Time P/E Ratio
MSFT 2016-05-17 04:00:00     38.94

Any suggestions?


Solution

  • On Yahoo, it looks like the P/E ratio for ETFs is only calculated on a periodic basis. You can see this if you go directly to the page for SPY, which says that the P/E ratio is as of 4/30/16.

    Yahoo likely does this on a periodic basis because the holdings of an ETF may change on a daily basis, and depending on the ETF type may or may not be published daily. If they are published, they are published on the fund's site, so it would be difficult for Yahoo to go to each fund's site, update the ratio of holdings, and then calculate a P/E ratio each day.

    Since you can get other information from Yahoo for ETFs, one can infer that getQuote does not return the P/E ratio because it's outdated for the ETF.