def _build_index(self): def with_index(df, type, column, new_name="symbol"): if not "country" in df: df["country"] = "unknown" else: df["country"] = df["country"].replace({ None: "unknown", "": "unknown" }).fillna('unknown') df.index = pd.MultiIndex.from_tuples([ (s, type, c) for s, c in zip(df[column].to_list(), df["country"].to_list()) ]).rename([ new_name if new_name is not None else column, "type", "country" ]) df = df.drop([column, "country"], axis=1) df = df.drop(df.index[df.index.duplicated('first')], axis=0) return df.loc[df.index.dropna()] symbols_df = pd.concat( [ with_index(ip.get_bonds(), "BOND", "name"), # country "name" full_name with_index( ip.get_certificates(), "CERT", "symbol" ), # country', 'name', 'full_name', '"symbol"', 'issuer', 'isin', 'asset_class', 'underlying' with_index(ip.get_cryptos(), "CRYPTO", "symbol"), # 'name', '"symbol"', 'currency' with_index( ip.get_commodities(), "COMM", "name" ), # 'title', 'country', '"name"', 'full_name', 'currency', 'group' with_index( ip.get_etfs(), "ETF", "symbol" ), # 'country', 'name', 'full_name', '"symbol"', 'isin', 'asset_class', 'currency', 'stock_exchange', 'def_stock_exchange' # with_index(ip.get_funds(), "FUND", "isin"), # 'country', 'name', 'symbol', 'issuer', '"isin"', 'asset_class', 'currency', 'underlying' with_index( ip.get_indices(), "INDEX", "symbol" ), # 'country', 'name', 'full_name', '"symbol"', 'currency', 'class', 'market' with_index( ip.get_stocks(), "STOCK", "symbol" ), # ['country', 'name', 'full_name', 'isin', 'currency', '"symbol"' with_index( pd.DataFrame( [f'{c}/USD' for c in ip.get_available_currencies()], columns=['symbol']), "FX", "symbol") ], axis=0) # update the index table upsert(self.engine, symbols_df, DataProvider.symbols_table_name, if_row_exists='ignore')
def test_investpy_bonds(): """ This function checks that bond data retrieval functions listed in investpy work properly. """ params = [ { 'country': 'spain', }, { 'country': None, }, ] for param in params: investpy.get_bonds(country=param['country']) investpy.get_bonds_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_bonds_dict(country=param['country'], columns=param['columns'], as_json=param['as_json']) investpy.get_bond_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_bond_recent_data(bond='Spain 30Y', as_json=param['as_json'], order=param['order'], interval='Daily') investpy.get_bond_historical_data(bond='Spain 30Y', from_date='01/01/1990', to_date='01/01/2019', as_json=param['as_json'], order=param['order'], interval='Daily') params = [ { 'bond': 'spain 30y', 'as_json': False }, { 'bond': 'argentina 3y', 'as_json': True }, { 'bond': 'germany 3m', 'as_json': False }, ] for param in params: investpy.get_bond_information(bond=param['bond'], as_json=param['as_json']) params = [ { 'country': 'united states', 'as_json': True, }, { 'country': 'united kingdom', 'as_json': False, } ] for param in params: investpy.get_bonds_overview(country=param['country'], as_json=param['as_json']) investpy.search_bonds(by='name', value='Spain')
def test_investpy_bonds(): """ This function checks that bond data retrieval functions listed in investpy work properly. """ params = [ { 'country': 'spain', }, { 'country': None, }, ] for param in params: investpy.get_bonds(country=param['country']) investpy.get_bonds_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_bonds_dict(country=param['country'], columns=param['columns'], as_json=param['as_json']) investpy.get_bond_countries() params = [ { 'as_json': True, 'order': 'ascending', 'debug': False }, { 'as_json': False, 'order': 'ascending', 'debug': True }, { 'as_json': True, 'order': 'descending', 'debug': False }, { 'as_json': False, 'order': 'descending', 'debug': False }, ] for param in params: investpy.get_bond_recent_data(bond='Spain 30Y', country='spain', as_json=param['as_json'], order=param['order'], debug=param['debug']) investpy.get_bond_historical_data(bond='Spain 30Y', country='spain', from_date='01/01/1990', to_date='01/01/2019', as_json=param['as_json'], order=param['order'], debug=param['debug']) investpy.search_bonds(by='name', value='Spain')
crypto_sheet = 'cryptos' home_sheet = 'Home' fund_country = xw.sheets[home_sheet].range('F3').value index_country = xw.sheets[home_sheet].range('F4').value stock_country = xw.sheets[home_sheet].range('F5').value bond_country = xw.sheets[home_sheet].range('F6').value etf_country = xw.sheets[home_sheet].range('F7').value req_funds = investpy.get_funds(country=fund_country) req_indices = investpy.get_indices(country=index_country) req_stocks = investpy.get_stocks(country=stock_country) req_bonds = investpy.get_bonds(country=bond_country) req_etfs = investpy.get_etfs(country=etf_country) def GetFunds(): wb = xw.Book.caller() wb.sheets[fund_sheet].range('D1').value = req_funds def GetIndices(): wb = xw.Book.caller() wb.sheets[index_sheet].range('D1').value = req_indices def GetStocks():
# get data using investing website indice = 'LBMA Gold Fixing Price' country = 'united kingdom' from_date = '19/11/2004' to_date = '25/09/2020' #investpy.indices.get_index_historical_data(indice, country, from_date, to_date, order='ascending', interval='Daily') for item in investpy.search.search_quotes('OZ1'): print(item) # In[72]: # get bonds investpy.get_bonds(country='brazil') # In[73]: # get data using investing website etf = 'SPDR Gold Shares' country = 'united states' from_date = '19/11/2004' to_date = '25/09/2020' investpy.etfs.get_etf_historical_data(etf, country, from_date, to_date, order='ascending', interval='Daily') # In[74]: