investpy
investpy copied to clipboard
Duplicate Symbol in get_stock_overview
This is the same issue mentioned here - whereby the same symbol is being returned for different stocks. The observation is that the symbol being duplicated is the first symbol for that country found in investpy/resources/stocks.csv
import investpy
investpy.stocks.get_stocks_overview('south africa', as_json=False, n_results=1000).to_csv('/home/zar/stocks.csv')
In the .csv returned:
0,south africa,Anglo American,AGLJ,58231.0,58702.0,56601.0,+1225,+2.15%,1050000,ZAR
40,south africa,Gemfields Group,AGLJ,275.0,290.0,275.0,-5,-1.79%,45000,ZAR
50,south africa,Pick N Pay,AGLJ,6113.0,6145.0,6026.0,+4,+0.07%,1440000,ZAR
In my case, I am searching for South African stocks. The symbol AGLJ is the first symbol for the country South Africa found in investpy/resources/stocks.csv
For the three examples listed above:
This is the correct information returned by get_stocks_overview.
0,south africa,Anglo American,AGLJ,58231.0,58702.0,56601.0,+1225,+2.15%,1050000,ZAR
The second entry here "Gemfields Group" is not found in the investpy/resources/stocks.csv
40,south africa,Gemfields Group,AGLJ,275.0,290.0,275.0,-5,-1.79%,45000,ZAR
This third entry "Pick N Pay" is found in investpy/resources/stocks.csv, but the spelling is slightly different:
- returned from get_stocks_overview
50,south africa,Pick N Pay,AGLJ,6113.0,6145.0,6026.0,+4,+0.07%,1440000,ZAR
- entry found in investpy/resources/stocks.csv
south africa,Picknpay,Picknpay,picknpay,ZAE000005443,50095,ZAR,PIKJ
What I think is happening is that in the investpy/stocks.py
file, under def get_stocks_overview(country, as_json=False, n_results=100):
This line here is attempting to match the stock names against the information from stocks.csv, and if is not finding an exact match its is defaulting to the first stock for the country.
"symbol": stocks.loc[(stocks['name'] == name).idxmax(), 'symbol'],
I've found this issue as well. I see that investpy.stocks.get_stocks_list(country = 'south africa')
returns a better list of symbols i.e. PIKJ for picknpay is in the list, though the list also has 2 entries for AGLJ...
Ive made multiple changes to my stocks.csv file to get the correct symbols. Besides companies being listed/delisted from the market, they also undergo name changes, and then they might also merge with someone else. All these various changes need to be reflected in the stocks.csv file, for which investpy.stocks.get_stocks_overview depends - therefore it my opinion the stocks.csv file needs to be separated for each country and maintained individually.
Here is an example of a stock that is listed on investing.com, but not actually present on the jse(south african market) anymore. Royal Bafokeng Preference Share
There are other example like this. If you remove this entry from the stocks.csv file, the investpy.stocks.get_stocks_overview will still pull data for it and give it a default symbol of 'aglj' which is the first entry for south africa.
Anyway, please find my stocks.csv file attached - hope it helps.