Last active
August 19, 2024 20:53
-
-
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
So generally, the steps to clean the data involve handling missing data, feature engineering, and normalizing/scaling the data. If you are looking for something specific, please do let us know.