Last active
January 4, 2024 05:28
-
-
Save shashankvemuri/3de4b93d934cf61974efebb1b5dd58fe to your computer and use it in GitHub Desktop.
Import these dependencies and set the variables
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
# Imports | |
from pandas_datareader import data as pdr | |
from pandas import ExcelWriter | |
import yfinance as yf | |
import pandas as pd | |
import datetime | |
import time | |
import requests | |
yf.pdr_override() | |
# Get tickers for all S&P 500 stocks from Wikipedia | |
def tickers_sp500(): | |
url = 'https://en.wikipedia.org/wiki/List_of_S%26P_500_companies' | |
html = requests.get(url).text | |
df = pd.read_html(html, header=0)[0] | |
tickers = df['Symbol'].tolist() | |
return tickers | |
# Variables | |
tickers = tickers_sp500() | |
tickers = [item.replace(".", "-") for item in tickers] # Yahoo Finance uses dashes instead of dots | |
index_name = '^GSPC' # S&P 500 | |
start_date = datetime.datetime.now() - datetime.timedelta(days=365) | |
end_date = datetime.date.today() | |
exportList = pd.DataFrame(columns=['Stock', "RS_Rating", "50 Day MA", "150 Day Ma", "200 Day MA", "52 Week Low", "52 week High"]) | |
returns_multiples = [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment