Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

r

stocks

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.

like image 353
danioyuan Avatar asked Jun 22 '12 00:06

danioyuan


1 Answers

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.

like image 155
GSee Avatar answered Oct 16 '22 03:10

GSee