def get_tickers(): ''' Get ticker symbols for stocks listed on major stock exchanges. At time of writing, this function retrieves 9899 stock symbols ''' print("Retrieving Stock Symbols...") dow_tickers = stock_info.tickers_dow() nasdaq_ticker = stock_info.tickers_nasdaq() sp500_ticker = stock_info.tickers_sp500() other_tickers = stock_info.tickers_other() all_tickers = list( set(dow_tickers + nasdaq_ticker + sp500_ticker + other_tickers)) print(f"\nTotal number of stock symbols retrieved: {len(all_tickers)}") tickers_dict = { 'DOW': dow_tickers, 'NASDAQ': nasdaq_ticker, 'SP500': sp500_ticker, 'others': other_tickers } for exchange_name, ticker_list in tickers_dict.items(): print(f"\t{exchange_name}: {len(ticker_list)}") return all_tickers
def load_tickers(self, cur, conn): self.df_ticker = pd.DataFrame() self.nasdaq = si.tickers_nasdaq() self.sp500 = si.tickers_sp500() self.dow = si.tickers_dow() self.other = si.tickers_other() self.tickers = list(set([*nasdaq, *sp500, *dow, *other])) self.df_ticker['ticker'] = self.tickers self.df_ticker.replace("", float("NaN"), inplace=True) self.df_ticker.dropna(subset=["ticker"], inplace=True) self.df_ticker['isdow'] = self.df_ticker['ticker'].isin(self.dow) self.df_ticker['issp500'] = self.df_ticker['ticker'].isin(self.sp500) self.df_ticker['isnasdaq'] = self.df_ticker['ticker'].isin(self.nasdaq) self.insert = [ list(row) for row in self.df_ticker.itertuples(index=False) ] self.SQL_Ticker_insert = """ INSERT INTO public.tickers(ticker,isdow, isnasdaq, issp500) VALUES (%s,%s,%s,%s) ON CONFLICT DO NOTHING""" self.cur.executemany(self.SQL_Ticker_insert, self.insert) self.conn.commit() self.rowcount = self.cur.rowcount return None
def listStock_gen(self, combobox): # gather stock symbols from major US exchanges df1 = pd.DataFrame( si.tickers_sp500() ) df2 = pd.DataFrame( si.tickers_nasdaq() ) df3 = pd.DataFrame( si.tickers_dow() ) df4 = pd.DataFrame( si.tickers_other() ) # convert DataFrame to list, then to sets sym1 = set( symbol for symbol in df1[0].values.tolist() ) sym2 = set( symbol for symbol in df2[0].values.tolist() ) sym3 = set( symbol for symbol in df3[0].values.tolist() ) sym4 = set( symbol for symbol in df4[0].values.tolist() ) # join the 4 sets into one. Because it's a set, there will be no duplicate symbols symbols = set.union( sym1, sym2, sym3, sym4 ) # Some stocks are 5 characters. Those stocks with the suffixes listed below are not of interest. my_list = ['W', 'R', 'P', 'Q'] del_set = set() sav_set = set() for symbol in symbols: if len( symbol ) > 4 and symbol[-1] in my_list: del_set.add( symbol ) else: sav_set.add( symbol ) for ticker in sav_set: combobox.addItem(str(ticker))
def main(): # get key stats, financial statements, and prices data of SP500 stocks tickers_nasdaq = set(si.tickers_nasdaq()) tickers_other = set(si.tickers_other()) tickers_sp500 = set(si.tickers_sp500()) tickers_nasdaq_ = list(tickers_nasdaq - tickers_sp500) tickers_other_ = list(tickers_other - tickers_sp500) tickers_sp500 = list(tickers_sp500) yr = YahooReader() yr.save_data(tickers_nasdaq_, folder_path='data_nasdaq') print("All Done!")
def tickers(request): dow = si.tickers_dow() nasdaq = si.tickers_nasdaq() sp500 = si.tickers_sp500() other = si.tickers_other() all = json.dumps({ 'dow': dow, 'nasdaq': nasdaq, 'sp500': sp500, 'other': other }) return HttpResponse(all)
def get_US_price(start_date, end_date): """ Download US stocks prices. Parameters ---------- start_date : string example : '2000-01-01'. end_date : string example : '2019-12-31'. Returns ------- total_df : pd.DataFrame Stocks prices from start_date to end_date. """ dow_list = si.tickers_dow() sp500_list = si.tickers_sp500() nasdaq_list = si.tickers_nasdaq() other_list = si.tickers_other() ticker = dow_list + sp500_list + nasdaq_list + other_list ticker = [ticker[i] for i in range(len(ticker)) if not ticker[i] in ticker[:i]] ticker = pd.DataFrame(ticker, columns=['Ticker']) for num, code in enumerate(ticker['Ticker']): try: print(num, code) time.sleep(1) try: df = fdr.DataReader(code, start_date, end_date) df = df['Close'] df = pd.DataFrame(df) df.columns = [code] except Exception as e: print(e, 'Error in Ticker', code) continue if num == 0: total_df = df else: total_df = pd.merge(total_df, df, how='outer', right_index=True, left_index=True) except ValueError: continue except KeyError: continue total_df.to_csv(r'C:\Users\Samsung\Downloads\quant\Python\data\US_price.csv') return total_df
def get_index_companies(index_tinker): index_stocklist = { 'DOW': si.tickers_sp500(), 'NASDAQ': si.tickers_nasdaq(), "S&P500": si.tickers_sp500(), 'FTSE100': ftsc100() } if isinstance(index_tinker, str): stocklist = index_stocklist.get(index_tinker) if stocklist: return stocklist else: return [index_tinker] else: return index_tinker
def __init__(self): #self.tickers_dow = si.tickers_dow() self.tickers_ftse100 = si.tickers_ftse100() self.tickers_ftse250 = si.tickers_ftse250() self.tickers_nasdaq = si.tickers_nasdaq() self.tickers_other = si.tickers_other() self.tickers_sp500 = si.tickers_sp500() self.tickers_all = self.get_all_tickers() self.tickers_high_vol = [] self.my_stocks = {} # Train data for all my_stocks self.X = None self.y = None self.label = None
def gather_all_stock_symbols(): """ Retrieves all available stock symbols from yahoo-fin.stock_info(si) and then removes duplicates. Total number of symbols = 9181. """ # ......... MongoDb initialization................................ db = client['trading'] coll = db['all_stock_symbols'] ##................................................................ # Some stocks are 5 characters. Those stocks with the suffixes listed below are not of interest. my_list = ['W', 'R', 'P', ] del_set = set() sav_set = set() # gather stock symbols from major US exchanges df1 = pd.DataFrame( si.tickers_sp500() ) df2 = pd.DataFrame( si.tickers_nasdaq() ) # df3 = pd.DataFrame(si.tickers_dow()) df4 = pd.DataFrame( si.tickers_other() ) # convert DataFrame to list, then to sets sym1 = set( symbol for symbol in df1[0].values.tolist() ) sym2 = set( symbol for symbol in df2[0].values.tolist() ) # sym3 = set( symbol for symbol in df3[0].values.tolist() ) sym4 = set( symbol for symbol in df4[0].values.tolist() ) # join the 4 sets into one. Because it's a set, there will be no duplicate symbols symbols = set.union( sym1, sym2, sym4 ) # sym3, for symbol in symbols: if len( symbol ) > 4 and symbol[-1] in my_list: # we identify the above suffixed symbols here, del_set.add( symbol ) # and separate them here else: sav_set.add( symbol ) # updated data without suffixed symbols # insert data to MongoDb.......................................... for symbol in sav_set: coll.insert_one( {"symbol": symbol} ) ##................................................................ print( f'Removed {len( del_set )} unqualified stock symbols...' ) print( f'There are {len( sav_set )} qualified stock symbols...' )
def get_symbols(index): symbols = [] if index == CFG.INDEX_DOW: symbols = si.tickers_dow() elif index == CFG.INDEX_NASDAQ: symbols = si.tickers_nasdaq() elif index == CFG.INDEX_SP500: symbols = si.tickers_sp500() return { 'fulfillmentText': str(symbols), 'displayText': '25', 'source': 'webhookdata', 'platform': 'FACEBOOK', }
def update_tickers(path, name): ''' Gets a list of tickers from the yahoo finance database and saves the list to a .csv file under a given directory and name :param path: string, must be denoted as path\\to\\main\\folder\\ :param name: string, will be the name of the .csv file saved, must not have any file denotion in it :return: saves a list of tickers to path\\name.csv ''' sources, tickers = [ stock_info.tickers_dow(), stock_info.tickers_nasdaq(), stock_info.tickers_other(), stock_info.tickers_sp500() ], [] for source in sources: for ticker in source: if ticker not in tickers: tickers.append(ticker) pd.DataFrame(tickers).to_csv(path + name + '.csv')
def fetch(ticker): # pull from yf_nasdaq db ticker_list = si.tickers_nasdaq() # calls for variation # Dow == si.tickers_dow() # S&P500 == si.tickers_sp500() # Others == si.tickers_other() # all tickers in currently selected list #print(ticker_list) #initialize and fill new array with data objects data = si.get_data(ticker)['open'][ -1] # select last element of open column # !! this print causing an error #print("data = " + data) # nested for loop to fill data array #for x in range(0, len(ticker_list)-1): # for ticker in ticker_list: # dataArr[x] = si.get_data(ticker) # if there's multiple tickers here, dataArr[x] will be overwritten and only the last ticker will be stored at dataArr[x] # print(dataArr[x]) #for x in range(0, len(ticker_list)-1): # for ticker in ticker_list: #dataArr[x] = si.get_data(ticker) #print(dataArr[0][0]) # return jsonified data to script #print("printing data jsonified: " + str(jsonify(data))) #return jsonified data array # xmltodict is causing an error here, just gonna json the data #Data = xmltodict.parse(data) return jsonify(data)
yf.pdr_override() # Override yfinance API in order to use Pandas DataReader import numpy as np import os end = datetime.date.today() end = datetime.datetime(end.year, end.month, end.day) # to midnight of that day #Going back 3 years ensures that we can accumulate a 200 day MA for the most recent 100 days #These are isolated after attaching the 200 day MA start = (end - relativedelta(years=3)) # return list of Dow tickers dow_tickers = pd.Series(stock_info.tickers_dow()).unique() sp_tickers = pd.Series(stock_info.tickers_sp500()).unique() nasdaq_tickers = pd.Series(stock_info.tickers_nasdaq()).unique() all_tickers = np.unique(np.hstack((nasdaq_tickers, dow_tickers, sp_tickers))) indicators = [ 'dma', 'volume_delta', 'close_12_ema', 'close_26_ema', 'macd', 'macd_9_ema', 'macds', 'macdh' ] # Functions # Returns the OCHLV for a stock over a 10 year period def get_ticker_data(ticker): '''Takes a list of stock symbols and appends the open, close, high, low and trading day data from Yahoo Finance for that period.''' # return stock_info.get_data (ticker, start_date=start, end_date=end)
from yahoo_fin import stock_info as si import numpy as np from finsymbols import symbols from pprint import pprint nasdaq_tickers = si.tickers_nasdaq() #print (len(nasdaq_tickers)) #print(len(si.tickers_sp500())) #print(len(si.tickers_dow()))
import lib from yahoo_fin import stock_info as si import numpy import pandas as pd import arrow import datetime import pickle nasdaq = si.tickers_nasdaq() #print(nasdaq) rawData = {} for a in nasdaq: try: d = lib.get_quote_data(a, '5d', '1m') rawData[a] = d print("Success on ", a) except: print("Failed on ", a) print(d) file = "nasdaq/nasdaqRaw.pkl" with open(file, 'wb') as handle: pickle.dump(rawData, handle, protocol=pickle.HIGHEST_PROTOCOL) print("EOF")
def nasdaq(self): self.symb = si.tickers_nasdaq()
def stock_screener( index_tinker_name='S&P500', min_vol=5e6, min_price=0, days=365, min_rs_rating=70, ): # help(si) ## fix for yahoo_fin start_date, end_date = period(days) yf.pdr_override() index_tinker = {'DOW': 'DOW', 'NASDAQ': '^IXIC', "S&P500": '^GSPC'} index_list = { 'DOW': si.tickers_sp500(), 'NASDAQ': si.tickers_nasdaq(), "S&P500": si.tickers_sp500() } st.header(f'Stock Screener {index_tinker_name}') # stocklist = si.tickers_sp500() min_volume = min_vol # index_name = '^GSPC' # SPY or S&P 500 stocklist = index_list.get(index_tinker_name)[:] index_rs_strange_value = calc_relative_strength( get_stock(index_tinker[index_tinker_name], days)) final = [] index = [] exclude_list = [] all_data = [] latest_iteration = st.empty() having_break = st.empty() bar = st.progress(0) total = len(stocklist) for num, stock_name in enumerate(stocklist): print(f"checking {num}:{stock_name}") if stock_name in exclude_list: continue FAILED = False df = get_stock(stock_name) # print('**',df) if df is False: print(f'SKIPPED to download {stock_name} {num}') continue stock_meta = Moving_avg(stock_name, df, index_rs_strange_value, min_rs_rating) time.sleep(0.2) if stock_meta.all_conditions(): print(f'Passed conditions: {stock_name}') final.append(stock_meta.as_dict()) else: print(f'Failed conditions: {stock_name}') # all_data.append(stock_meta.as_dict()) latest_iteration.text(f'Stocks Processed: {(num+1)}/{total}') bar.progress((num + 1) / total) if num == 0: continue if num % 10 == 0: for i in list(range(5))[::-1]: having_break.text(f'waiting for {i}sec') time.sleep(1) # having_break = st.empty() if num % 100 == 0: for i in list(range(3))[::-1]: having_break.text(f'waiting for {i}min') time.sleep(60) # having_break = st.empty() # time.sleep(5*60) final_df = pd.DataFrame(final) # all_data_df = pd.DataFrame(all_data) return final_df
else: if i < 14: i=i+1 else: return new_row else: if i < 14: i=i+1 else: return new_row if made_cut == True: return new_row else: return False except: return False if __name__ == "__main__": THREAD_NO=200 tickers = si.tickers_sp500() tickers.extend(si.tickers_nasdaq()) tickers = list(dict.fromkeys(tickers)) df_screened = pd.DataFrame(columns=['Stock','Earnings Count', "Percent Positive","Percent Negative", "Days Before ER", "AVG Delta", "Max Delta", "Worst Delta"]) threads_start = time.time() with concurrent.futures.ThreadPoolExecutor(max_workers=THREAD_NO) as executor: results = executor.map(getStockData, tickers) for result in results: if result !=False: df_screened = df_screened.append(result, ignore_index=True) print("With threads time:", time.time() - threads_start) print(df_screened) df_screened.to_csv(r'14DaysNas_and_SP500_pre_ER.csv')
import requests, time, re, os import pandas as pd from secrets import IEX_CLOUD_API_TOKEN from webull import paper_webull, webull import math import argparse from datetime import datetime import time import yahoo_fin.stock_info as yf import json nasdaq_list = yf.tickers_nasdaq() # sp500_list = yf.tickers_sp500() now = datetime.now() # CREDENTIALS while True: ap = argparse.ArgumentParser() ap.add_argument( "-a", "--acc", required=True, help="input type of account e.i. --acc paper or --acc real") args = vars(ap.parse_args()) if args['acc'] == 'paper': from webull import paper_webull wb = paper_webull() result = wb.login('*****@*****.**', 'Svelty+9', device_name='', mfa='195001')
last_year = datetime.today() - timedelta(days=365) last_year = last_year.strftime('%Y-%m-%d') # Format pandas to remove scientific notation pd.options.display.float_format = '{:.2f}'.format ''' Create a list of tickers to scan ''' # Russell 1000 # Tickers = ['TWOU', 'MMM', 'ABT', 'ABBV', 'ABMD', 'ACHC', 'ACN', 'ATVI', 'AYI', 'ADNT', 'ADBE', 'ADT', 'AAP', 'AMD', 'ACM', 'AES', 'AMG', 'AFL', 'AGCO', 'A', 'AGIO', 'AGNC', 'AL', 'APD', 'AKAM', 'ALK', 'ALB', 'AA', 'ARE', 'ALXN', 'ALGN', 'ALKS', 'Y', 'ALLE', 'AGN', 'ADS', 'LNT', 'ALSN', 'ALL', 'ALLY', 'ALNY', 'GOOGL', 'GOOG', 'MO', 'AMZN', 'AMCX', 'DOX', 'UHAL', 'AEE', 'AAL', 'ACC', 'AEP', 'AXP', 'AFG', 'AMH', 'AIG', 'ANAT', 'AMT', 'AWK', 'AMP', 'ABC', 'AME', 'AMGN', 'APH', 'ADI', 'NLY', 'ANSS', 'AR', 'ANTM', 'AON', 'APA', 'AIV', 'APY', 'APLE', 'AAPL', 'AMAT', 'ATR', 'APTV', 'WTR', 'ARMK', 'ACGL', 'ADM', 'ARNC', 'ARD', 'ANET', 'AWI', 'ARW', 'ASH', 'AZPN', 'ASB', 'AIZ', 'AGO', 'T', 'ATH', 'TEAM', 'ATO', 'ADSK', 'ADP', 'AN', 'AZO', 'AVB', 'AGR', 'AVY', 'AVT', 'EQH', 'AXTA', 'AXS', 'BKR', 'BLL', 'BAC', 'BOH', 'BK', 'OZK', 'BKU', 'BAX', 'BDX', 'WRB', 'BRK.B', 'BERY', 'BBY', 'BYND', 'BGCP', 'BIIB', 'BMRN', 'BIO', 'TECH', 'BKI', 'BLK', 'HRB', 'BLUE', 'BA', 'BOKF', 'BKNG', 'BAH', 'BWA', 'BSX', 'BDN', 'BFAM', 'BHF', 'BMY', 'BRX', 'AVGO', 'BR', 'BPYU', 'BRO', 'BFA', 'BFB', 'BRKR', 'BC', 'BG', 'BURL', 'BWXT', 'CHRW', 'CABO', 'CBT', 'COG', 'CACI', 'CDNS', 'CZR', 'CPT', 'CPB', 'CMD', 'COF', 'CAH', 'CSL', 'KMX', 'CCL', 'CRI', 'CASY', 'CTLT', 'CAT', 'CBOE', 'CBRE', 'CBS', 'CDK', 'CDW', 'CE', 'CELG', 'CNC', 'CDEV', 'CNP', 'CTL', 'CDAY', 'BXP', 'CF', 'CRL', 'CHTR', 'CHE', 'LNG', 'CHK', 'CVX', 'CIM', 'CMG', 'CHH', 'CB', 'CHD', 'CI', 'XEC', 'CINF', 'CNK', 'CTAS', 'CSCO', 'CIT', 'C', 'CFG', 'CTXS', 'CLH', 'CLX', 'CME', 'CMS', 'CNA', 'CNX', 'KO', 'CGNX', 'CTSH', 'COHR', 'CFX', 'CL', 'CLNY', 'CXP', 'COLM', 'CMCSA', 'CMA', 'CBSH', 'COMM', 'CAG', 'CXO', 'CNDT', 'COP', 'ED', 'STZ', 'CERN', 'CPA', 'CPRT', 'CLGX', 'COR', 'GLW', 'OFC', 'CSGP', 'COST', 'COTY', 'CR', 'CACC', 'CCI', 'CCK', 'CSX', 'CUBE', 'CFR', 'CMI', 'CW', 'CVS', 'CY', 'CONE', 'DHI', 'DHR', 'DRI', 'DVA', 'SITC', 'DE', 'DELL', 'DAL', 'XRAY', 'DVN', 'DXCM', 'FANG', 'DKS', 'DLR', 'DFS', 'DISCA', 'DISCK', 'DISH', 'DIS', 'DHC', 'DOCU', 'DLB', 'DG', 'DLTR', 'D', 'DPZ', 'CLR', 'COO', 'DEI', 'DOV', 'DD', 'DPS', 'DTE', 'DUK', 'DRE', 'DNB', 'DNKN', 'DXC', 'ETFC', 'EXP', 'EWBC', 'EMN', 'ETN', 'EV', 'EBAY', 'SATS', 'ECL', 'EIX', 'EW', 'EA', 'EMR', 'ESRT', 'EHC', 'EGN', 'ENR', 'ETR', 'EVHC', 'EOG', 'EPAM', 'EPR', 'EQT', 'EFX', 'EQIX', 'EQC', 'ELS', 'EQR', 'ERIE', 'ESS', 'EL', 'EEFT', 'EVBG', 'EVR', 'RE', 'EVRG', 'ES', 'UFS', 'DCI', 'EXPE', 'EXPD', 'STAY', 'EXR', 'XOG', 'XOM', 'FFIV', 'FB', 'FDS', 'FICO', 'FAST', 'FRT', 'FDX', 'FIS', 'FITB', 'FEYE', 'FAF', 'FCNCA', 'FDC', 'FHB', 'FHN', 'FRC', 'FSLR', 'FE', 'FISV', 'FLT', 'FLIR', 'FND', 'FLO', 'FLS', 'FLR', 'FMC', 'FNB', 'FNF', 'FL', 'F', 'FTNT', 'FTV', 'FBHS', 'FOXA', 'FOX', 'BEN', 'FCX', 'AJG', 'GLPI', 'GPS', 'EXAS', 'EXEL', 'EXC', 'GTES', 'GLIBA', 'GD', 'GE', 'GIS', 'GM', 'GWR', 'G', 'GNTX', 'GPC', 'GILD', 'GPN', 'GL', 'GDDY', 'GS', 'GT', 'GRA', 'GGG', 'EAF', 'GHC', 'GWW', 'LOPE', 'GPK', 'GRUB', 'GWRE', 'HAIN', 'HAL', 'HBI', 'THG', 'HOG', 'HIG', 'HAS', 'HE', 'HCA', 'HDS', 'HTA', 'PEAK', 'HEI.A', 'HEI', 'HP', 'JKHY', 'HLF', 'HSY', 'HES', 'GDI', 'GRMN', 'IT', 'HGV', 'HLT', 'HFC', 'HOLX', 'HD', 'HON', 'HRL', 'HST', 'HHC', 'HPQ', 'HUBB', 'HPP', 'HUM', 'HBAN', 'HII', 'HUN', 'H', 'IAC', 'ICUI', 'IEX', 'IDXX', 'INFO', 'ITW', 'ILMN', 'INCY', 'IR', 'INGR', 'PODD', 'IART', 'INTC', 'IBKR', 'ICE', 'IGT', 'IP', 'IPG', 'IBM', 'IFF', 'INTU', 'ISRG', 'IVZ', 'INVH', 'IONS', 'IPGP', 'IQV', 'HPE', 'HXL', 'HIW', 'HRC', 'JAZZ', 'JBHT', 'JBGS', 'JEF', 'JBLU', 'JNJ', 'JCI', 'JLL', 'JPM', 'JNPR', 'KSU', 'KAR', 'K', 'KEY', 'KEYS', 'KRC', 'KMB', 'KIM', 'KMI', 'KEX', 'KLAC', 'KNX', 'KSS', 'KOS', 'KR', 'LB', 'LHX', 'LH', 'LRCX', 'LAMR', 'LW', 'LSTR', 'LVS', 'LAZ', 'LEA', 'LM', 'LEG', 'LDOS', 'LEN', 'LEN.B', 'LII', 'LBRDA', 'LBRDK', 'FWONA', 'IRM', 'ITT', 'JBL', 'JEC', 'LLY', 'LECO', 'LNC', 'LGF.A', 'LGF.B', 'LFUS', 'LYV', 'LKQ', 'LMT', 'L', 'LOGM', 'LOW', 'LPLA', 'LULU', 'LYFT', 'LYB', 'MTB', 'MAC', 'MIC', 'M', 'MSG', 'MANH', 'MAN', 'MRO', 'MPC', 'MKL', 'MKTX', 'MAR', 'MMC', 'MLM', 'MRVL', 'MAS', 'MASI', 'MA', 'MTCH', 'MAT', 'MXIM', 'MKC', 'MCD', 'MCK', 'MDU', 'MPW', 'MD', 'MDT', 'MRK', 'FWONK', 'LPT', 'LSXMA', 'LSXMK', 'LSI', 'CPRI', 'MIK', 'MCHP', 'MU', 'MSFT', 'MAA', 'MIDD', 'MKSI', 'MHK', 'MOH', 'TAP', 'MDLZ', 'MPWR', 'MNST', 'MCO', 'MS', 'MORN', 'MOS', 'MSI', 'MSM', 'MSCI', 'MUR', 'MYL', 'NBR', 'NDAQ', 'NFG', 'NATI', 'NOV', 'NNN', 'NAVI', 'NCR', 'NKTR', 'NTAP', 'NFLX', 'NBIX', 'NRZ', 'NYCB', 'NWL', 'NEU', 'NEM', 'NWSA', 'NWS', 'MCY', 'MET', 'MTD', 'MFA', 'MGM', 'JWN', 'NSC', 'NTRS', 'NOC', 'NLOK', 'NCLH', 'NRG', 'NUS', 'NUAN', 'NUE', 'NTNX', 'NVT', 'NVDA', 'NVR', 'NXPI', 'ORLY', 'OXY', 'OGE', 'OKTA', 'ODFL', 'ORI', 'OLN', 'OHI', 'OMC', 'ON', 'OMF', 'OKE', 'ORCL', 'OSK', 'OUT', 'OC', 'OI', 'PCAR', 'PKG', 'PACW', 'PANW', 'PGRE', 'PK', 'PH', 'PE', 'PTEN', 'PAYX', 'PAYC', 'PYPL', 'NEE', 'NLSN', 'NKE', 'NI', 'NBL', 'NDSN', 'PEP', 'PKI', 'PRGO', 'PFE', 'PCG', 'PM', 'PSX', 'PPC', 'PNFP', 'PF', 'PNW', 'PXD', 'ESI', 'PNC', 'PII', 'POOL', 'BPOP', 'POST', 'PPG', 'PPL', 'PRAH', 'PINC', 'TROW', 'PFG', 'PG', 'PGR', 'PLD', 'PFPT', 'PB', 'PRU', 'PTC', 'PSA', 'PEG', 'PHM', 'PSTG', 'PVH', 'QGEN', 'QRVO', 'QCOM', 'PWR', 'PBF', 'PEGA', 'PAG', 'PNR', 'PEN', 'PBCT', 'RLGY', 'RP', 'O', 'RBC', 'REG', 'REGN', 'RF', 'RGA', 'RS', 'RNR', 'RSG', 'RMD', 'RPAI', 'RNG', 'RHI', 'ROK', 'ROL', 'ROP', 'ROST', 'RCL', 'RGLD', 'RES', 'RPM', 'RSPP', 'R', 'SPGI', 'SABR', 'SAGE', 'CRM', 'SC', 'SRPT', 'SBAC', 'HSIC', 'SLB', 'SNDR', 'SCHW', 'SMG', 'SEB', 'SEE', 'DGX', 'QRTEA', 'RL', 'RRC', 'RJF', 'RYN', 'RTN', 'NOW', 'SVC', 'SHW', 'SBNY', 'SLGN', 'SPG', 'SIRI', 'SIX', 'SKX', 'SWKS', 'SLG', 'SLM', 'SM', 'AOS', 'SJM', 'SNA', 'SON', 'SO', 'SCCO', 'LUV', 'SPB', 'SPR', 'SRC', 'SPLK', 'S', 'SFM', 'SQ', 'SSNC', 'SWK', 'SBUX', 'STWD', 'STT', 'STLD', 'SRCL', 'STE', 'STL', 'STOR', 'SYK', 'SUI', 'STI', 'SIVB', 'SWCH', 'SGEN', 'SEIC', 'SRE', 'ST', 'SCI', 'SERV', 'TPR', 'TRGP', 'TGT', 'TCO', 'TCF', 'AMTD', 'TDY', 'TFX', 'TDS', 'TPX', 'TDC', 'TER', 'TEX', 'TSRO', 'TSLA', 'TCBI', 'TXN', 'TXT', 'TFSL', 'CC', 'KHC', 'WEN', 'TMO', 'THO', 'TIF', 'TKR', 'TJX', 'TOL', 'TTC', 'TSCO', 'TDG', 'RIG', 'TRU', 'TRV', 'THS', 'TPCO', 'TRMB', 'TRN', 'TRIP', 'SYF', 'SNPS', 'SNV', 'SYY', 'DATA', 'TTWO', 'TMUS', 'TFC', 'UBER', 'UGI', 'ULTA', 'ULTI', 'UMPQ', 'UAA', 'UA', 'UNP', 'UAL', 'UPS', 'URI', 'USM', 'X', 'UTX', 'UTHR', 'UNH', 'UNIT', 'UNVR', 'OLED', 'UHS', 'UNM', 'URBN', 'USB', 'USFD', 'VFC', 'MTN', 'VLO', 'VMI', 'VVV', 'VAR', 'VVC', 'VEEV', 'VTR', 'VER', 'VRSN', 'VRSK', 'VZ', 'VSM', 'VRTX', 'VIAC', 'TWLO', 'TWTR', 'TWO', 'TYL', 'TSN', 'USG', 'UI', 'UDR', 'VMC', 'WPC', 'WBC', 'WAB', 'WBA', 'WMT', 'WM', 'WAT', 'WSO', 'W', 'WFTLF', 'WBS', 'WEC', 'WRI', 'WBT', 'WCG', 'WFC', 'WELL', 'WCC', 'WST', 'WAL', 'WDC', 'WU', 'WLK', 'WRK', 'WEX', 'WY', 'WHR', 'WTM', 'WLL', 'JW.A', 'WMB', 'WSM', 'WLTW', 'WTFC', 'WDAY', 'WP', 'WPX', 'WYND', 'WH', 'VIAB', 'VICI', 'VIRT', 'V', 'VC', 'VST', 'VMW', 'VNO', 'VOYA', 'ZAYO', 'ZBRA', 'ZEN', 'ZG', 'Z', 'ZBH', 'ZION', 'ZTS', 'ZNGA', 'WYNN', 'XEL', 'XRX', 'XLNX', 'XPO', 'XYL', 'YUMC', 'YUM'] # Add a few extra tickers (precious metals, international, VIX, blockchain) Tickers = Tickers + ['GLD', 'FREL', 'VOO', 'TOK', 'PGJ', 'ADRE', 'IPAC', 'SPEU', 'EFAD', 'UIVM', 'SCHC', 'DIM', 'VNQI', 'ILF', 'SDIV', 'XME', 'PICK', 'REMX', 'BATT', 'BLCN'] # Add the nasdaq Tickers = Tickers + sp.tickers_nasdaq() # Alphabetize and remove duplicates Tickers = sorted(list(set(Tickers))) # Create a dataframe to populate # StockInfo = pd.DataFrame() def build_df(): # Add the list of tickers to the StockInfo dataframe StockInfo['Ticker'] = Tickers # Set the tickers as the index StockInfo.set_index('Ticker', inplace = True) # Add some columns that will be used by the functions to determine what needs to be filled #
import pandas as pd import numpy as np import random from datetime import datetime from datetime import timedelta from datetime import date import re import os import pickle import matplotlib.pyplot as plt from tqdm import tqdm import mplfinance as mpf yf.pdr_override() stocklist = np.array(si.tickers_nasdaq()) index_name = '^GSPC' # S&P 500 todays_date = str(datetime.datetime.now().date()) final = [] index = [] n = -1 exportList = pd.DataFrame(columns=['Stock', "RS_Rating", "50 Day MA", "150 Day Ma", "200 Day MA", "52 Week Low", "52 week High"]) for stock in stocklist: #random.choices(np.array(stocklist),k=100): n += 1 #time.sleep(1) print ("\npulling {} with index {}".format(stock, n))
insurance_df = load_dataset(dataset='insurance', simfin_api_key=SIMFIN_API_KEY, shareprices_df=shareprices_df) # TRAIN general_model = train(general_df, winsor_quantile=0.01, model_name='general_model', feature_name='general', param=dict(learning_rate=0.01, max_depth=3, subsample=.5, colsample_bylevel=0.7, colsample_bytree=0.7, n_estimators=200), custom_filter=si.tickers_nasdaq()) banks_model = train(banks_df, winsor_quantile=0.05, model_name='banks_model', feature_name='banks', param=dict(learning_rate=0.01, max_depth=2, subsample=.8, colsample_bylevel=0.7, colsample_bytree=0.7, n_estimators=200)) insurance_model = train(insurance_df, winsor_quantile=0.08, model_name='insurance_model',
Markets = ("NASDAQ", "DOW", "SP500") Market = input("Select Market Index: ") while Market not in Markets: print("Please Select between DOW, NASDAQ or SP500") Market = input("Select Market Index: ") if Market == "DOW": Market = yf.tickers_dow() print("Fetching DOW JONES tickers") elif Market == "SP500": Market = yf.tickers_sp500() print("Fetching S&P500 tickers") elif Market == "NASDAQ": Market = yf.tickers_nasdaq() print("Fetching NASDAQ tickers") else: print("Market Data currently unavailabe") Market = input("Select Market Index: ") Ticker = input("Select Stock: ") if Ticker in Market: print("Fetching Required Data for " + str(Ticker) + " Please Follow Forward.") if Ticker not in Market: print("Ticker Not Found. Please select a valid Ticker from the market") Ticker = input("Select Stock: ") SDate = input("Enter a start date in YYYY-MM-DD format")
import pandas as pd import requests_html from datetime import datetime, timedelta import time from decimal import * import matplotlib.pyplot as plt import random import numpy as np import math import finnhub lukas="cool" # Setup client tickerlist = si.tickers_nasdaq() jona = "sandbox_buql2av48v6s4fu1gq10" boss = "sandbox_buo1gon48v6vd0a73mkg" fclient = finnhub.Client(api_key=jona) print(fclient.recommendation_trends("tsla")) tickerlist_short = ["AACG","AACQ","AACQU","AAL"] def number_encoder(inputstring): if inputstring[-1] == "K": return Decimal(inputstring[:-1]) * 1000 elif inputstring[-1] == "M": return Decimal(inputstring[:-1]) * 1000000
from yahoo_fin import stock_info as si dow_list = si.tickers_nasdaq() for i in dow_list: print(si.get_data(i)) print(dow_list)
from typing import Optional import yahoo_fin.stock_info as si from great_expectations.core.expectation_configuration import ExpectationConfiguration from great_expectations.execution_engine import PandasExecutionEngine from great_expectations.expectations.expectation import ColumnMapExpectation from great_expectations.expectations.metrics import ( ColumnMapMetricProvider, column_condition_partial, ) NASDAQ_TICKERS_LIST = [t.lower() for t in si.tickers_nasdaq()] # This method compares a string to the valid NASDAQ ticker def is_valid_nasdaq_ticker(ticker: str) -> bool: return ticker.lower() in NASDAQ_TICKERS_LIST # This class defines a Metric to support your Expectation. # For most ColumnMapExpectations, the main business logic for calculation will live in this class. class ColumnValuesToBeValidNasdaqTicker(ColumnMapMetricProvider): # This is the id string that will be used to reference your metric. condition_metric_name = "column_values.valid_nasdaq_ticker" # This method implements the core logic for the PandasExecutionEngine @column_condition_partial(engine=PandasExecutionEngine) def _pandas(cls, column, **kwargs): return column.apply(lambda x: is_valid_nasdaq_ticker(x))
def get_nasdaq_tickers(): return si.tickers_nasdaq()
days = 0 constDate = str("0001") + "-" + str("01") + "-" + str("01") if args.days: days = int(args.days) if args.processes: noOfProcesses = int(args.processes) else: noOfProcesses = 10 if args.filename: fileName = args.filename + ".xlsx" else: fileName = "insider_trading.xlsx" if args.stocklist: l1 = args.stocklist.split(',') else: l1 = si.tickers_sp500() + si.tickers_nasdaq() + si.tickers_other() + si.tickers_dow() l1 = list(set(l1)) l1.sort() l1.pop(0) tickerList = [] for i,ticker in enumerate(l1): if not re.search(r"\$", ticker): tickerList.append(ticker) l1 = tickerList if args.insidersales: value = int(args.insidersales) if value > 1: print("ERROR insider sales value can only be 0 or 1 and you have passed %d" %(value)) sys.exit(1) else: insiderSales = value
customer=input() print(80*'=') print('Choose the index analysis:Our analysis will be made on stocks composites of index you want,type:(DOW has the smallest index with 30 components)') print('SP500 : for S&P 500 composites') print('DOW : for DOW JONES composites') print('NASDAQ : for NASDAQ composites') print(80*'=') print('What is your choice?') stocklist=input('NASDAQ/DOW/SP500 : ') while stocklist!='NASDAQ' and stocklist!='DOW' and stocklist!='SP500' : print('Please choose the right option') stocklist=input() if stocklist=='NASDAQ': stocklist=si.tickers_nasdaq() elif stocklist=='DOW': stocklist=si.tickers_dow() else: stocklist=si.tickers_sp500() start_date=date.today()-timedelta(days=360) end_date=date.today() print('Do you want to use the dividend yields or not(Y/N)?') yn=input() while yn!='Y' and yn!='N': print('You can type Y or N') yn=input() print('Do you want to use the pricing for American Options or European ones?(type A or E)')
def getNasdaqList(): return si.tickers_nasdaq()