Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yf.Tickers from yfinance to download information for multiple tickers and dynamically access each of them [duplicate]

My question is how to dynamically access each ticker when using yf.Tickers from yfinance in Python?

For example, I have a list of tickers: ['AAPL', 'MSFT', 'AMD'] and use the following code to download thru yfinance:

import yfinance as yf
tickers = yf.Tickers('AAPL MSFT AMD')
tickers.AAPL.info
div = tickers.AAPL.info['trailingAnnualDividendYield']

Now I have to type in each ticker like this: tickers.AAPL.info. Does anyone know how I can access each ticker dynamically?

like image 661
DLW Avatar asked Jan 20 '26 06:01

DLW


1 Answers

You could try the following:

import yfinance as yf

stocks = ['AAPL', 'MSFT', 'AMD']

for stock in stocks:
    info = yf.Ticker(stock).info
    div = info.get('trailingAnnualDividendYield')
    print(stock, div)

The output is:

AAPL 0.013894105
MSFT 0.013502605
AMD None
like image 185
Nikos Oikou Avatar answered Jan 23 '26 21:01

Nikos Oikou



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!