-2

I parsed a html table for financial transactions and have 3 different lists: 1. DATE 2. TICKER 3. MOTHER COMPANY

I would like to populate a stock prices for stocks from my TICKER list for a maximum possible period I am new to python and cant figure out how to get the data for the stocks from my TICKER list... Any guidance would be of great help

Many thanks in advance

TICKERS ['OSR', 'NWSA', 'MNK', 'ZTS', 'FNAC', 'WWAV', 'NRZ', 'CST', 'BPY', 'ERA', 'AXLL', 'LMCAD', 'ABBV']

I am trying with a simple code but cant get through:

import yfinance as yf
for ticker in tickers:
    data = yf.download(ticker, period="max")
Tomas
  • 15
  • 6

1 Answers1

1

The download function in yfinance accepts a list of tickers separated by spaces. In order to download the data for all your tickers for a max period simply call it this way.

For example, if you want to download the data for 'OSR', 'NWA' and 'MNK':

import yfinance as yf
tickers = 'OSR NWA MNK'
data = yf.download(tickers, period='max')

You can then access each ticker's data using data[ticker].

If you have your tickers as a list and want to convert to a space-delimited string use join:

ticker_list = ['OSR', 'NWA', 'MNK']
ticker_str = ' '.join(ticker_list)
  • Many thanks Amir! and is there a way how to start dowloading the stock price from a particular date for each stock? – Tomas Jun 09 '20 at 08:20
  • You're welcome. And yes, there's a way to do just that: For example: `data = yf.download("SPY AAPL", start="2017-01-01", end="2017-04-30")`. You should take a look at the yfinance documentation, everything is detailed there: [link](https://pypi.org/project/yfinance/) – Amir Yaacobi Jun 09 '20 at 08:40