Luis David
Luis David

Reputation: 11

How to get a complete and up-to-date list of ticker symbols for any Yahoo Finance index?

Good afternoon everyone, I am currently in a dilemma to which I have tried to find a solution for a whole week but unfortunately I have come to nothing. I have tried to locate a library or create a code to obtain a complete (and updated) list of the symbols of all the companies that trade in a certain index (for example: IBOVESPA (^BVSP), NASDAQ Composite (^IXIC), DAX (^GDAXI), Dow Jones Industrial Average (^DJI) or IPC MEXICO (^MXX).

In Python there is the Yahoo Finance library called

yfinance

and from this you can get a lot of information but not the components of the indices (I have tried but I haven't gotten anywhere), I don't know if there is any other library that can help me and therefore That's why I'm looking for help or any advice you can give me.

First I tried to use the information from Wikipedia but it is very outdated for some indexes, and then they recommended me to use finnhub

pip install finnhub-python

import finnhub
finnhub_client = finnhub.Client(api_key="")

print(finnhub_client.indices_const(symbol = "^GSPC"))

but unfortunately the part that would be useful to me is a paid service. I hope someone can help me and thank you very much for your attention.

Upvotes: 1

Views: 3447

Answers (1)

gru.ai
gru.ai

Reputation: 11

This should work:

from pytickersymbols import PyTickerSymbols

stock_data = PyTickerSymbols()
nasdaq_tickers = stock_data.get_stocks_by_index('NASDAQ 100')  # Corrected index name

# Print the ticker symbols
for stock in nasdaq_tickers:
    print(stock['symbol'])

Upvotes: 1

Related Questions