Skip to content

Instantly share code, notes, and snippets.

@quantra-go-algo
Last active August 19, 2024 20:53
Show Gist options
  • Save quantra-go-algo/ac5180bf164a7894f70969fa563627b2 to your computer and use it in GitHub Desktop.
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
# 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())
@quantra-go-algo
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment