Reading Fundamental Data from Yahoo Finance

Recently I read a blogpost and someone was recommending the book "DIY Financial Advisor "by Wesley R. Gray, Jack Vogel and David Foulke. I believe it was the QuantStrat blog but I might be wrong.

The book is a good read and also suggest a couple of simple systems any investor can implement and follow.



One system requires fundamental data like P/E or EBITDA/TEV ratios and I could trace them on Yahoo.

I wrote a small function retrieving the fundamental data for a list of given securities (tickers)

At the end you get a fundis object, with all values per ticker.


library(XML)
library(RCurl)


fundi <-function(tickers)
{
  my=NA
  for(i in 1:NROW(tickers)) {
    url=paste("https://de.finance.yahoo.com/q/ks?s=",tickers[[i]],sep = "")
    s <- getURL(url)  #rcurl package
    t=readHTMLTable(s)
    t=t[[8]] #fundamental price book
    a=cbind(tickers[[i]],t[7,],t[9,],t[1,],t[3,])
    my=rbind(my,a)
      }

  my = my[-1,]
  fundis=my
  rm(t)
  rm(a)
  rm(i)
  rm(my)
  rm(s)
  return(fundis)
}


No comments :

Post a Comment

Further Readings