I've been wondering how can I get a series fundamentals such as P/E ratio of a company using yfinance. historical ratios for multiple company .
I have tried
import yfinance as yf
rio=yf.Ticker("RIO.AX")
rio.financials
but my result give me the empty data frame anyone can help? or any documentation I can be able to read thanks a lot
There are two lines of code that have to be inserted to retrieve financials, balance sheet and cashflow statements again.
The solution was found by afju where he/she has posted it in the comments section with a short explanation:
https://aroussi.com/post/python-yahoo-finance
so credits to him/her
Here is what you need to change in
.../site-packages/yfinance/base.py
which has worked for me for following version of yfinance:
import yfinance as yf
yf.__version__
>>>'0.1.54'
insert comment in # get fundamentals (around line 375):
#data = utils.get_json(url+'/financials', proxy)
and write these two lines:
url = "{}/{}/financials".format(self._scrape_url, self.ticker)
data = utils.get_json(url, proxy)
so in the end, it looks like this:
# get fundamentals
#data = utils.get_json(url+'/financials', proxy)
url = "{}/{}/financials".format(self._scrape_url, self.ticker)
data = utils.get_json(url, proxy)