Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import yfinance as yf
- import datetime
- import os
- def get_ticker(symbol, startDate=datetime.datetime(2022, 4, 1), endDate=datetime.datetime(2022, 4, 8)):
- ticker = yf.Ticker(symbol)
- data = ticker.history(start=startDate, end=endDate, interval="1m")
- return data
- def get_ticker_sharesOutstanding(symbol):
- ticker = yf.Ticker(symbol)
- return int(ticker.get_info()['sharesOutstanding'])
- ticker_names = []
- with open('./Stocks in the Russell 1000 Index.csv', 'r') as f:
- lines = f.readlines()
- for line in lines:
- symbol = line.split(',')[0].replace('"','')
- ticker_names.append(symbol)
- res = []
- for name in ticker_names[1:]:
- try:
- print('Getting data for:', name)
- delta = datetime.timedelta(days=7)
- num_days = 5
- start_week = datetime.datetime(2022, 9, 5)
- date_list = [start_week - datetime.timedelta(days=x*7) for x in reversed(range(num_days))]
- start_date_list = []
- gap_p = []
- for date in date_list[:-1]:
- print(name, date, date + delta)
- data = get_ticker(name, startDate=date, endDate=date + delta)
- #data = get_ticker(name)
- shares_out = get_ticker_sharesOutstanding(name)
- output_path = './data_2/' + name + '_' + str(shares_out) + '.csv'
- output_file_exists = os.path.exists(output_path)
- data.to_csv(output_path, mode='a', header=not output_file_exists)
- except Exception as err:
- print(err)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement