Ejemplo n.º 1
0
    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 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
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
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!")
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
    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...' )
Ejemplo n.º 9
0
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')
Ejemplo n.º 10
0
from tkinter import ttk
from yahoo_fin import stock_info as si
from yahoo_fin import options

from tkinter import *
from tkinter.ttk import *

import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg

from pandas import DataFrame

dow_tickers = si.tickers_dow()
sp500_tickers = si.tickers_sp500()
nasdaq_tickers = si.tickers_nasdaq()
other_tickers = si.tickers_other()


class Application(tk.Frame):
    def __init__(self, master=None):
        tk.Frame.__init__(self, master)
        self.createWidgets()

    def createWidgets(self):

        #Button images~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        photo = PhotoImage(
            file=
            r"C:\Users\User\Desktop\Python coding\finance\StockScreening\StockScreener\images\button_update.png"
        )
Ejemplo n.º 11
0
 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
Ejemplo n.º 12
0
Archivo: SymbObj.py Proyecto: hukf/test
 def others(self):
     self.symb = si.tickers_other()