def get_price_ext(stock: str, start=None, end=None) -> dfType: """ 日本株の株価を取得する :param stock:証券コード :param start:取得開始日時 :param end:取得終了日時 default:実行日時 :return:価格情報のデータフレーム """ if end is None: end = datetime.datetime.now().strftime("%d/%m/%Y") if start is None: start = (datetime.datetime.now() - datetime.timedelta(days=100)).strftime("%d/%m/%Y") res = investpy.get_stock_information(stock, "united states", as_json=True) print(res)
def ver_compromissos_backEnd(self): # Aqui é onde tratamos os dados para plotar eles dados = pd.read_csv('statusinvest-busca-avancada.csv', decimal=',', thousands='.', sep=';') self.tree_eventos.delete(*self.tree_eventos.get_children()) #acoes = ['ITUB4'] acoes = list(self.pegando_dados_acoes) colunas = [ 'TICKER', 'PRECO', 'P/L', 'DY', 'P/VP', 'EV/EBIT', 'ROE', 'ROA', 'ROIC' ] dados = dados[colunas] cont = 0 lista_dados_cont = list() teste = list() for a in dados.values: if a[0] in acoes: lista_dados_cont.append(list(a)) else: continue teste.append(lista_dados_cont) lista_dados_cont = list() for a in range(len(teste)): (teste[a][0].append( list( inv.get_stock_information(acoes[a], 'BRAZIL')['Beta'].values)[0])) for linha in teste: self.tree_eventos.insert('', END, values=linha[0])
def adicionarInformacoesEmpresas(self, actual): ''' Esta função adiciona os dados de P/L, P/Pa e indice Graham, pode ser um dataframe geral: precisa somente do "name"''' actual['distribuição (%)'] = (actual['total'] / actual['total'].sum()) * 100 actual['P/L'] = 0.0 #actual['P/VP'] = 0.0 #actual['Graham'] = 0.0 os.system('cls') for index, row in actual.iterrows(): try: print('Carregando informações de ' + row['name']) info = inv.get_stock_information(row['name'], 'brazil', as_json=True) #P_Vp = info['Shares Outstanding']*info['Prev. Close']/(float(info['Market Cap'])) #Graham = P_Pa * info['P/E Ratio'] actual.at[index, 'P/L'] = info['P/E Ratio'] #actual.at[index, 'P/VP'] = P_Vp #actual.at[index, 'Graham'] = Graham except: pass return actual
def get_MainStockInformation( stockkey, currencycode ): # stockcode, stockname, currprice, dividend_year # price in USD/KRW currency stock_info = [] result = [] if stockkey in stocks_code: stockcode = stockkey stockname = stocks_dict_code_name.get(stockcode) elif stockkey in stocks_name: stockname = stockkey stockcode = stocks_dict_name_code.get(stockname) else: return stockcountry = stocks_dict_code_country.get(stockcode) stockinfo = investpy.get_stock_information(stockcode, stockcountry, as_json=False) currprice = list(stockinfo['Prev. Close'])[0] dividend_year = get_dividend_year(stockcode, stockcountry) print(currprice) currprice_new = cm.get_LocalCurrencyValue_NewStock(currprice, currencycode, stockcountry) print(currprice_new) print(dividend_year) dividend_year_new = cm.get_LocalCurrencyValue_NewStock( dividend_year, currencycode, stockcountry) print(dividend_year_new) result.append(stockcode) result.append(stockname) result.append(currprice_new) result.append(dividend_year_new) result.append(stockcountry) return result
def main(): parser = argparse.ArgumentParser( description='scrap investing.com daily close') parser.add_argument('-input_file', type=str, default='data_tickers/investing_stock_info.csv', help='input file') parser.add_argument( '-output_prefix', type=str, default='../stock_data/raw_daily_investing_stock/investing_stock_', help='prefix of the output file') parser.add_argument('-date', type=str, help='Specify the date') args = parser.parse_args() if args.date is None: scrap_date = datetime.date.today() args.date = str(scrap_date) filename = args.output_prefix + args.date + '.csv' df_input = pd.read_csv(args.input_file) info_list = [] print('number of tickers:', len(df_input.index)) for index, row in df_input.iterrows(): print('downloading...', row['symbol'], row['country'], '-', index) try: info = investpy.get_stock_information(row['symbol'], row['country']) info_list.append(info) except: print('failed') time.sleep(scrap_delay) df = pd.concat(info_list) df['Date'] = args.date df.to_csv(filename)
def get_company_info(symbol): summary_text = inp.get_stock_information( stock=symbol, country='turkey').set_index('Stock Symbol') return summary_text
def test_investpy_stocks(): """ This function checks that stock data retrieval functions listed in investpy work properly. """ params = [ { 'country': 'spain', }, { 'country': None, }, ] for param in params: investpy.get_stocks(country=param['country']) investpy.get_stocks_list(country=param['country']) params = [ { 'country': None, 'columns': ['full_name', 'name'], 'as_json': True }, { 'country': None, 'columns': ['full_name', 'name'], 'as_json': False }, { 'country': 'spain', 'columns': ['full_name', 'name'], 'as_json': True }, { 'country': 'spain', 'columns': ['full_name', 'name'], 'as_json': False }, { 'country': 'spain', 'columns': None, 'as_json': False }, ] for param in params: investpy.get_stocks_dict(country=param['country'], columns=param['columns'], as_json=param['as_json']) investpy.get_stock_countries() params = [ { 'as_json': True, 'order': 'ascending', }, { 'as_json': False, 'order': 'ascending', }, { 'as_json': True, 'order': 'descending', }, { 'as_json': False, 'order': 'descending', }, ] for param in params: investpy.get_stock_recent_data(stock='BBVA', country='spain', as_json=param['as_json'], order=param['order'], interval='Daily') investpy.get_stock_historical_data(stock='BBVA', country='spain', from_date='01/01/1990', to_date='01/01/2019', as_json=param['as_json'], order=param['order'], interval='Daily') for value in ['spanish', 'english']: investpy.get_stock_company_profile(stock='BBVA', country='spain', language=value) params = [ { 'stock': 'bbva', 'country': 'spain', 'as_json': False }, { 'stock': 'bbva', 'country': 'spain', 'as_json': True }, { 'stock': 'HSBK', 'country': 'kazakhstan', 'as_json': False } ] for param in params: investpy.get_stock_information(stock=param['stock'], country=param['country'], as_json=param['as_json']) params = [ { 'country': 'spain', 'as_json': True, 'n_results': 50 }, { 'country': 'united states', 'as_json': False, 'n_results': 50 }, { 'country': 'bosnia', 'as_json': False, 'n_results': 50 }, { 'country': 'palestine', 'as_json': False, 'n_results': 50 }, { 'country': 'dubai', 'as_json': False, 'n_results': 50 }, { 'country': 'ivory coast', 'as_json': False, 'n_results': 50 } ] for param in params: investpy.get_stocks_overview(country=param['country'], as_json=param['as_json'], n_results=param['n_results']) params = [ { 'stock': 'bbva', 'country': 'spain' }, { 'stock': 'entel', 'country': 'chile' } ] for param in params: investpy.get_stock_dividends(stock=param['stock'], country=param['country']) params = [ { 'stock': 'bbva', 'country': 'spain', 'summary_type': 'balance_sheet', 'period': 'annual' }, { 'stock': 'aapl', 'country': 'united states', 'summary_type': 'income_statement', 'period': 'quarterly' }, { 'stock': 'barc', 'country': 'united kingdom', 'summary_type': 'cash_flow_statement', 'period': 'annual' } ] for param in params: investpy.get_stock_financial_summary(stock=param['stock'], country=param['country'], summary_type=param['summary_type'], period=param['period']) investpy.search_stocks(by='name', value='BBVA')
#test_search_stock_2 # tutorial name: ACESSANDO DADOS DO INVESTING.COM COM PYTHON #2 | Índices e Ações | Python para Investimentos #12 # #link of tutorial: https://www.youtube.com/watch?v=Tv2-BGOLf9E ########################################################### #libraries ########################################################### import investpy as inv ########################################################### #declarations ########################################################### ########################################################### #execution ########################################################### # lista = inv.get_indices_list('brazil') # print(lista) # lista_2 = inv.get_stocks('brazil') # print(lista_2) info = inv.get_stock_information('ELEK4', 'brazil') print(info)
fund = xw.sheets[home_sheet].range('G3').value index = xw.sheets[home_sheet].range('G4').value stock = xw.sheets[home_sheet].range('G5').value bond = xw.sheets[home_sheet].range('G6').value etf = xw.sheets[home_sheet].range('G7').value if fund and fund_country != "": req_fund_info = investpy.get_fund_information(fund=fund, country=fund_country) if index and index_country != "": req_index_info = investpy.get_index_information(index=index, country=index_country) if stock and stock_country != "": req_stock_info = investpy.get_stock_information(stock=stock, country=stock_country) if bond and bond_country != "": req_bond_info = investpy.get_bond_information(bond=bond) if etf and etf_country != "": req_etf_info = investpy.get_etf_information(etf=etf, country=etf_country) def GetFundInformation(): wb = xw.Book.caller() wb.sheets[fund_sheet].range('N1').options( transpose=True).value = req_fund_info def GetIndexInformation():