Is there a way to automatically get general info of many stocks like P/E ratio, Yield, and so on?

StackOverflow https://stackoverflow.com/questions/11148641

  •  16-06-2021
  •  | 
  •  

문제

I know some ways to get daily stock prices and volumes in R or python, but just wondering whether these is a way (using either R or python) to get more info about stocks such as P/E ratio, company website, Yield and so on, preferably not just current value, but also historical values.

Thanks.

도움이 되었습니까?

해결책

Historical is going to be difficult. The quantmod package for R has getQuote which together with yahooQF will be all you need to get current values.

require("quantmod")
getQuote("GS", what = yahooQF(c("Market Capitalization", "Earnings/Share", 
         "P/E Ratio", "Book Value", "EBITDA", "52-week Range")))

            Trade Time Market Capitalization Earnings/Share P/E Ratio Book Value EBITDA  52-week Range
GS 2012-06-21 04:00:00               47.870B          6.764     14.27    134.476      0 84.27 - 139.25

Also, try

getQuote("GS", what=yahooQF())

which will give you a menu of choices for what fields to request.

You can get recent financial statements from Google Finance with getFinancials

There is also the FinancialInstrument package which has several update_instruments.* functions to download metadata about instruments (stocks in this case). For example, here's what the yahoo one does

require("FinancialInstrument")
stock("GS", currency("USD")) # define the stock
#[1] "GS"
update_instruments.yahoo("GS") #update with yahoo
#[1] "GS"
getInstrument("GS")
#primary_id          :"GS"
#currency            :"USD"
#multiplier          :1
#tick_size           :0.01
#identifiers         : list()
#type                :"stock"
#name                :"Goldman Sachs Gro"
#exchange            :"NYSE"
#market.cap          :"47.870B"
#avg.volume          :5480530
#EPS                 :6.76
#EPS.current.year.est:11.4
#EPS.next.year.est   :12.9
#book.value          :134
#EBITDA              :0
#range.52wk          :"84.27 - 139.25"
#defined.by          :"yahoo"
#updated             : POSIXct, format: "2012-06-21 19:31:11"

If you have an InteractiveBrokers account, you can use the outstanding IBrokers package to get lots of info about lots of instruments. Also, if you have an IB account you'll want to look at my twsInstrument package which has a lot of convenience functions.

다른 팁

Just to answer the website part of my question:

  str <- paste("http://investing.money.msn.com/investments/company-report?symbol=", ticker, sep = "")
  page <- paste(readLines(url(str, open = "rt")), collapse = "\n")
  match <- regexpr("<a href=\"http://www\\.(\\S+)\">Website</a>", page, perl = TRUE)

  if (attr(match, "match.length") > 0) {
    site <- substring(page, attr(match, "capture.start"), attr(match, "capture.start") + attr(match, "capture.length") - 1)    
    site <- strsplit(site, "/")[[1]][1]
  }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top