Based on this post here, I have the possibility to transform the ISIN to some form ticker symbol with help of library investpy. This transformation is correct for most of united states stocks.
But this symbol itself is not in any case the same as the ticker-symbol I need to call pandas_dataframe. I think more exactly it conforms the RIC-symbol (e.g. look here).
For example if I try the following call:
import investpy
df = investpy.stocks.search_stocks(by='isin', value='DE0006048432')
print(df)
My output is:
country name ... currency symbol
0 germany Henkel VZO ... EUR HNKG_p
1 italy Henkel VZO ... EUR HNKG_p
2 switzerland Henkel VZO ... EUR HNKG_pEUR
but
from pandas_datareader import data as pdr
stock = pdr.DataReader('HNKG_p', data_source="yahoo", start="2021-01-01", end="2021-10-30")
gives me an error.
The correct call I need is:
stock = pdr.DataReader('HEN3.DE', data_source="yahoo", start="2021-01-01", end="2021-10-30")
So my question is:
Or more general
Super ugly and error prone but better than nothing:
import investpy as ip
import yahooquery as yq
from pandas_datareader import data as pdr
company_name = ip.stocks.search_stocks(by='isin', value='DE0006048432')
company_name = company_name["name"][0].split(' ')[0]
symbol = yq.search(company_name)["quotes"][0]["symbol"]
stock = pdr.DataReader(symbol, data_source="yahoo", start="2021-01-01", end="2021-10-30")
You could extend this code using things like fuzzywuzzy and an ordinary testing module with doctest. Do not use this code in production.
I am not even sure if this call keeps the order of the returned values:
yq.search(company_name)["quotes"]
So this code might actually behave randomly but it might give you a direction.