Fundamentals

Hello, how can I get basic data for 100 shares from Yahoo finance in this way?

cluster course ​​​​​​​

Hi Durdu,



You can try the following code to download multiple asset's OHLCV data in one place:

import pandas as pd

tickers = ['BAC', 'C', 'META', 'GOOGL', 'INTC', 'KO', 'NFLX', 'TWTR', 'V', 'XRX']
import yfinance as yf
stock_data = {}
for t in tickers:
    stock_data[t] = yf.download(t,'2020-1-1', auto_adjust=True)

# To print
stock_data


Since you would be dealing with large dataset you can store it in a pickle file, and for that, you can use the following code:
import pickle

with open(‘stock_data.bz2’, ‘wb’) as file:
pickle.dump(stock_data,file)




Later on for reading the pickle, you can use the following code:

with open('stock_data.bz2', 'rb') as file:
    stock_data_from_pickle = pickle.load(file)
# To print    
stock_data_from_pickle

We also have a notebook dedicated to fetching data for multiple stocks. This is a part of the Swing Trading Strategies course of Quantra.

Hope you find this helpful!

Thanks
Rushda
1 Like