Last active
February 13, 2024 21:27
-
-
Save quantra-go-algo/ac5180bf164a7894f70969fa563627b2 to your computer and use it in GitHub Desktop.
Python code to get price data for all S&P500 tickers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import packages | |
import yfinance as yf | |
import pandas as pd | |
# Read and print the stock tickers that make up S&P500 | |
tickers = pd.read_html( | |
'https://en.wikipedia.org/wiki/List_of_S%26P_500_companies')[0] | |
print(tickers.head()) | |
# Get the data for this tickers from yahoo finance | |
data = yf.download(tickers.Symbol.to_list(),'2021-1-1','2021-7-12', auto_adjust=True)['Close'] | |
print(data.head()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment