def comparestocks(dataset,start_date,end_date,company_name, company): tickerlist =[] tickerlist.append(company) MaxStockLimit = input("Please enter the number of companies you want to compare prices, Max limit is 3\n") try: if(int(MaxStockLimit)<=3): for i in range(int(MaxStockLimit)): print("\n Please enter the ticker symbol for the stock(s) you want to proceed(Max 3)") ticker = input("(Press 1 to exit when you want to quit loading):\n").upper() all_symbols= web.get_nasdaq_symbols() symbols = list(all_symbols.loc[:, "NASDAQ Symbol"]) if ticker in symbols: tickerlist.append(ticker) else: print("You have entered Invalid ticker") comparestocks(dataset,start_date,end_date,company_name, company) else: print("You have exceeded the maximum limit to compare stocks") comparestocks(dataset,start_date,end_date,company_name, company) except ValueError: print("***Please enter integer value as 1,2 or 3***") comparestocks(dataset,start_date,end_date,company_name, company) if(len(tickerlist)<=4): getdataForMultipleTickers(tickerlist,start_date,end_date,dataset,company_name, company)
def getCompanyDetails(companyTicker): #Checking if entered ticker is registered on NASDAQ all_symbols= web.get_nasdaq_symbols() company_details = pd.read_csv("http://www.nasdaq.com/screening/companies-by-name.aspx?letter=0&exchan0ge=nasdaq&render=download", usecols = [*range(0,7)]) symbols = list(all_symbols.loc[:, "NASDAQ Symbol"]) # Input from the user for Ticker symbol if companyTicker in symbols: company_details = company_details.loc[company_details['Symbol'] == companyTicker] company_details.index = range(len(company_details)) symbol_details = all_symbols.loc[all_symbols['NASDAQ Symbol'] == companyTicker] symbol_details.index = range(len(symbol_details)) company_name = company_details["Name"][0] print("*" *100) print("\nGeneral Information about the Company\n ") print("Company Name : ",company_details["Name"][0]) # Access elements such as Name, Market cap, etc from the csv for that company print("Last Sale Information : ",company_details["LastSale"][0]) print("Market Cap : ",company_details["MarketCap"][0]) print("IPO years : ",company_details["IPOyear"][0]) print("Sector of the company : ",company_details["Sector"][0]) print("Industry the company belong to : ",company_details["industry"][0]) print("NextShares Information : ",symbol_details["NextShares"][0]) print("*" *100) return companyTicker,company_name else: print("Invalid Ticker Symbol.Please Re-enter Valid ticker symbol") main()
def get_symbols_and_URLs(): existing_file = pd.read_csv('symbols.csv') #原文件 new_file = pd.DataFrame() old_lists = existing_file['symbols'] #原列表 df = pdr.get_nasdaq_symbols() symbols = df.index #获取新列表 new_lists = [] for i in symbols: #SPAC的symbol特点是5个字母,以U结尾,作为条件筛选 if (i[-1] == 'R') and (len(i) == 5): new_lists.append(i) extra = list(set(new_lists).difference(set(old_lists))) #对比新老列表,给出提示 if extra == []: print('今天没有新增的SPAC') else: for i in extra: print(i) print('为今天新增SPAC!') new_file['symbols'] = new_lists new_urls = [] for i in new_lists: url = 'http://data.eastmoney.com/notices/stock/{}.html'.format(i) new_urls.append(url) new_file['url'] = new_urls #存储新列表和url new_file.to_csv('symbols.csv') #新开文件代替原有 return new_lists
def get_all_symbols_and_write(): """ The generate a csv file including companies' names, symbols and other information. Now we assume the file is 'Nasdaq Company List'. Because of Nasdaq update the file everyday. So we should run this function everyday to follow the official updating. :return: """ all_nasdaq = web.get_nasdaq_symbols() all_nasdaq.to_csv(path_or_buf='./data/nasdaq_symbols_all.csv') return True
def get_symbols(query: str) -> dict[str, str]: PATH = './web/symbols.json' last_good_date = datetime.now() - timedelta(days=1) if not os.path.exists(PATH) \ or datetime.fromtimestamp(os.path.getmtime(PATH)) < last_good_date: df = pdr.get_nasdaq_symbols() df = df['Security Name'] df.to_json(path_or_buf=PATH) all_symbols = json.load(open(PATH, 'r')) query = query.lower() res = { k: all_symbols[k] for k in all_symbols if query in k.lower() or query in all_symbols[k].lower() } return res
def get_all_symbols_in_rows(rows, output_csv_name='nasdaq_symbols_in_rows.csv'): """ Scrape all stock symbols from Nasdaq Company List and store them in a csv file by rows. :param rows: Int. Number of rows of stock symbols the csv file will have. Note that number of symbols in each row would be same except the last row. :param output_csv_name: Int. Name of the csv file :return: Int. Total number of stock symbols in the Nasdaq Company List. This returning would be used to judge the HTCondor cluster has done all jobs or not. """ all_nasdaq = web.get_nasdaq_symbols().index number_of_normal_rows = len(all_nasdaq) // (rows - 1) number_of_last_row = len(all_nasdaq) % (rows - 1) with open(output_csv_name, 'w', newline='') as csv_file: csv_writer = csv.writer(csv_file) for r in range(rows): if r < rows - 1: csv_writer.writerow( list(all_nasdaq[r * number_of_normal_rows:(r + 1) * number_of_normal_rows])) else: csv_writer.writerow( list(all_nasdaq[(-1 * number_of_last_row):])) return len(all_nasdaq)
def get_nasdaq(): return pdr.get_nasdaq_symbols(5, 10)
import pandas as pd import datetime #usa get data online on my own datetoday = datetime.datetime.today().strftime('%Y%m%d') '''对于规范的结构以下代码适用 url='http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange=NASDAQ&render=download' dataString=requests.get(url).content tickersrawdata=pd.read_csv(io.StringIO(dataString.decode('utf-8')),sep=None)#解码 path= tickersrawdata.to_csv(path,index=False) ''' import pandas_datareader as pdrusa rawdata = pdrusa.get_nasdaq_symbols(timeout=10) path = '../data/' rawdata.to_csv(path + datetoday + 'usa.csv')
#!/usr/bin/env python3 from datetime import datetime as dt import pandas as pd import dash import dash_core_components as dcc import dash_html_components as html from dash.dependencies import Input, Output, State import plotly.graph_objs as go pd.core.common.is_list_like = pd.api.types.is_list_like import pandas_datareader as web app = dash.Dash() df = web.get_nasdaq_symbols() stocks = [{'value': i, 'label': df.loc[i]['Security Name']} for i in df.index] app.layout = html.Div([ html.H1(id='title', children='Stock Ticker Symbol'), html.Div([ html.Pre(id='pre1', children='Select stock symbols:') ], style={'width': '30%', 'display': 'inline-block'}), html.Div([ html.Pre(id='pre2', children='Select start and end dates:'), ], style={'width': '70%', 'display': 'inline-block'}), html.Div([ dcc.Dropdown(id='stock-dropdown', options=stocks, # multi=True ),
def __init__(self, **kwargs): super(Main_Page, self).__init__(**kwargs) self.data = web.get_nasdaq_symbols() self.symbols = self.data['NASDAQ Symbol'] # 8854 self.security_name = self.data['Security Name'] # Set orientation of the Box Layout self.box = BoxLayout(orientation='vertical', size_hint_y=None, height=Window.height, spacing=15) # self.box.pos_hint = {'x': 0,'y': 0} self.add_widget(self.box) self.flayout = FloatLayout() self.grid = GridLayout(cols=2) # Create and set up text input box self.text = TextInput(size_hint=(None, None), width='350dp', height='48dp') # Create and set up search button self.search = Button(text = 'search', size_hint=(None, None), width='60dp', height='48dp') self.search.bind(on_press=self.search_function) # Add input and button to 2 cols grid self.grid.add_widget(self.text) self.grid.add_widget(self.search) self.grid.pos_hint = {'x': 0, 'top': 9} self.flayout.add_widget(self.grid) # Add two cols grid to Box Layout self.box.add_widget(self.flayout) self.counter = 0 self.arr_symbol = [] self.arr_name = [] self.arr_button = [] for i in range(20): self.temp = GridLayout(cols=3) self.symbol_label = Label(text=self.symbols[i]) self.symbol_label.font_size = 18 self.symbol_label.size_hint_y = None self.symbol_label.size_hint_x = 0.08 self.symbol_label.height = 19 self.symbol_label.pos_hint = {'x': 0.1, 'top': 5} self.arr_symbol.append(self.symbol_label) # with self.symbol_label.canvas: # Color(0, 1, 0, 0.25) # Rectangle(pos=self.symbol_label.pos, size=self.symbol_label.size) self.flayout = FloatLayout() self.flayout.add_widget(self.symbol_label) self.temp.add_widget(self.flayout) self.name_label = Label(text=self.security_name[i]) self.name_label.size_hint_y = None self.name_label.size_hint_x = 0.8 self.name_label.font_size = 18 self.name_label.height = 19 self.name_label.pos_hint = {'x':0.1, 'top': 5} self.arr_name.append(self.name_label) self.flayout = FloatLayout() self.flayout.add_widget(self.name_label) # with self.flayout.canvas: # Color(0, 1, 0, 0.25) # Rectangle(pos=self.flayout.pos, size=self.flayout.size) # print(self.flayout.size) self.temp.add_widget(self.flayout) # self.button = Button(size_hint=(None, None), text='Predict', width='60dp', height='40dp') self.button.id = self.symbols[i] self.button.bind(on_press=self.click) self.button.size_hint = (None,None) self.button.height = 25 self.button.width = 70 self.button.pos_hint = {'right': 1, 'top': 5} self.arr_button.append(self.button) self.flayout = FloatLayout() self.flayout.add_widget(self.button) self.temp.add_widget(self.flayout) # self.box.add_widget(self.temp) # self.scroll.add_widget(self.temp) # self.add_widget(self.box) self.arr_page = [] self.current_page = 1 self.prev_page = 1 self.last = GridLayout(cols=30) # List of stocks for i in range(1, 31): self.page = Button(size_hint=(None, None), text='{}'.format(i), width='30dp', height='30dp') self.page.pos_hint = {'right': 1, 'bottom': 3} self.page.bind(on_press=self.page_function) self.arr_page.append(self.page) self.flayout = FloatLayout() self.flayout.add_widget(self.page) self.last.add_widget(self.flayout) self.arr_page[0].background_color = (0, 0, 1, 0.25) self.box.add_widget(self.last) self.arr_page_numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30] self.arr_page_numbers2 = [414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443] self.page_index_prev = 0 self.page_index_cur = 0