Closed henriquesss closed 1 year ago
Hi! Can you provide a code sample to reproduce the error ?
from future import print_function import yfinance as yf import json import pandas as pd from datetime import datetime
net_revenue_lines = {"Tickers": [], "Lucro líquido": []}
def test_yfinance(): bovespa_tickers = [ "PETR4.SA", "VALE3.SA", "BOVA11.SA", "ITUB4.SA", "MGLU3.SA", "PETR3.SA" ]
for symbol in bovespa_tickers:
ticker = yf.Ticker(symbol)
# Checa se tem informação e histórico para tickers válidos
assert(ticker.info is not None and ticker.info != {})
assert(ticker.history(period="max").empty is False)
# Categorias de dados dentro de cada ticker
ticker.cashflow
ticker.balance_sheet
ticker.financials
ticker.sustainability
ticker.major_holders
ticker.institutional_holders
# Formatação do período
date = "2019-12-31"
date_format = "%Y-%m-%d"
date = datetime.strptime(date, date_format)
# Dados da categoria "financials"
# receita-liquida
net_revenue = ticker.financials[date].loc["Net Income"]
# gross_profit = ticker.financials.loc["Gross Profit"] #receita-bruta
# ebit = ticker.financials.loc["Ebit"] #ebit
# total_operation_expenses = ticker.financials.loc["Total Operating Expenses"] #Custo de operação total
# cost_of_revenue = ticker.financials.loc["Cost Of Revenue"] #Custo de receita
net_revenue_lines["Lucro líquido"].append(int(float(net_revenue)))
net_revenue_lines["Tickers"].append(symbol)
print('-------------------')
print(symbol)
print('-------------------')
print(ticker.financials)
# Criação do dataframe
result_table = pd.DataFrame(net_revenue_lines)
better_filter = result_table.sort_values(by=["Lucro líquido"], ascending=False)
worst_filter = result_table.sort_values(by=["Lucro líquido"], ascending=True)
print("Resultado:")
print(better_filter)
exit()
if name == "main": test_yfinance()
I'm not sure if you are having the same issue as https://github.com/ranaroussi/yfinance/issues/191, but you might check it out just to be sure.
Interesting, I'm passing though both asserts (but I do have switched branch to https://github.com/ranaroussi/yfinance/pull/179 to correct major_holders issue)! Maybe worth giving it a try
I'm not sure if you are having the same issue as #191, but you might check it out just to be sure.
I already had applied the modifications of that issue when i had mine :disappointed:
Thanks
Hello @henriquesss, I think I finally found how to solve your issue. It seems that there were two specific problems in the base.py code. You can just install directly my fork via pip: pip install git+https://github.com/rodrigobercini/yfinance.git or follow the steps below.
1) First, apply this url fix.
This will fix the returning blank data frames issue, but another problem will arise: "Index out of range"
2) To fix that second issue, try this method
With those two steps, everything should be working fine. BUT one of your tickers is called "BOVA11.SA" and that's an ETF, so there are no financials for this ticker. Trying to fetch this data will result in an error. Simply remove this ticker from your tickers pool and the code must work.
I've just tried myself and it's working fine.
Cheers!
i clone your repository and tried with this list(only stocks this time hehe) and still not working with some tickers(RUMO3.SA, TBLE3.SA, SMLE3.SA, ESTC3.SA, KROT3.SA, CTIP3.SA, KLBN11.SA)
bovespa_tickers = [ 'BBAS3.SA', 'MRVE3.SA', 'BBSE3.SA', 'JBSS3.SA', 'WEGE3.SA', 'BBDC3.SA', 'CPFE3.SA', 'HGTX3.SA', 'CYRE3.SA', 'ENBR3.SA', 'BBDC4.SA', 'RADL3.SA', 'CIEL3.SA', 'CMIG4.SA', 'EQTL3.SA', 'HYPE3.SA', 'PETR4.SA', 'SBSP3.SA', 'BRML3.SA', 'LREN3.SA', 'CSAN3.SA', 'LAME4.SA', 'BRFS3.SA', 'UGPA3.SA', 'MRFG3.SA', 'ECOR3.SA', 'ABEV3.SA', 'SANB11.SA', 'GGBR4.SA', 'GOAU4.SA', 'RENT3.SA', 'USIM5.SA', 'QUAL3.SA', 'CPLE6.SA', 'PETR3.SA', 'BRKM5.SA', 'BRAP4.SA', 'BRPR3.SA', 'DTEX3.SA', 'ELET3.SA', 'ELET6.SA', 'GFSA3.SA', 'GOLL4.SA', 'POMO4.SA', 'MGLU3.SA', 'BIDI4.SA', 'VALE3.SA', 'RUMO3.SA', 'ITSA4.SA', 'TBLE3.SA', 'SMLE3.SA', 'CESP6.SA', 'CCRO3.SA', 'ITUB4.SA', 'ESTC3.SA', 'OIBR4.SA', 'MULT3.SA', 'NATU3.SA', 'VIVT4.SA', 'PCAR4.SA', 'KROT3.SA', 'EMBR3.SA' 'CTIP3.SA', 'TIMP3.SA', 'KLBN11.SA', 'SUZB5.SA', 'FIBR3.SA', 'VALE5.SA' ]
For the following tickers, it seems that their yahoo finance page has no data, perhaps the tickers are no longer available in Bovespa, it could be for many other reasons. https://finance.yahoo.com/quote/TBLE3.SA https://finance.yahoo.com/quote/SMLE3.SA https://finance.yahoo.com/quote/RUMO3.SA https://finance.yahoo.com/quote/ESTC3.SA https://finance.yahoo.com/quote/KROT3.SA https://finance.yahoo.com/quote/CTIP3.SA
For Klabin, their holders' page is broken, so I added a "try" error handler when fetching the holders data to my fork https://finance.yahoo.com/quote/KLBN11.SA/holders
you have to use Yahoo tickers, usually they are pretty similar, but sometimes not quite like it. when this happen look for the ticker in yahoo web page:
RUMO3.SA > RAIL3.SA TBLE3.SA > EGIE3.SA (changed name to Engie Brasil) SMLE3.SA > SMLS3.SA ESTC3.SA > EZTEC3.SA KROT3.SA > COGN3.SA (changed name to Cognus Educação) CTIP3.SA > B3SA3.SA (Cetip merged with BVMF, and recently became are B3
KLBN11.SA tiker is right but the code doesn't run (dont know why). I fixed adding a try in base.py, like in this link https://stackoverflow.com/questions/60469752/yfinance-tickerdata-info-not-working-for-some-stocks
Hi,
It seems the financial statements (income statement, bal sheet, cashflow) are not coming as intended with specific tickers of bovespa.
When i run 'runtest.py', the script stop on this validations:
assert(ticker.info is not None and ticker.info != {})
assert(ticker.history(period="max").empty is False)
Does anyone already have a similar problem?