def yeda2(fileloc, filetype): init_tm = time() # Make dir fsplit = fileloc.split('_') date = fsplit[len(fsplit) - 1][:-4] dirpath = "program2_mpl_out/" + filetype + "/" + date + "/" pathlib.Path(dirpath).mkdir(parents=True, exist_ok=True) # Get List of tickers pf.get_tickerList(date, filetype) for ticker in projLists.ticker_list: data_starttm = time() data = pf.get_tickerData(fileloc, filetype, ticker, "T") print("Got", ticker, "data DF in", time() - data_starttm, "Seconds") ################# # Plotting time # ################# if (data.empty): message = "At date " + date + ", ticker" + ticker + " had no trade data\n" print(message) with open("program2_mpl_" + filetype + "_log.txt", 'a+') as f: f.write(message) continue fig, ax = plt.subplots(figsize=(20, 8)) ax.plot(data.Time, data["Trade Price"], color="red", linewidth=1.0, linestyle='-') ax.set_xlabel('Time (UTC)') ax.set_ylabel('Price') title_date = data.Time[len(data) - 1].strftime('%b %-d, %Y') ax.set_title(ticker + " | " + "Trades | " + title_date) ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') #setting major locator alldays = mdates.HourLocator(interval=1) # 3H interval ax.xaxis.set_major_locator(alldays) ax.xaxis.set_major_formatter(mdates.DateFormatter('%I %p')) #setting minor locator hoursLoc = mdates.HourLocator(interval=30) ax.xaxis.set_minor_locator(hoursLoc) ax.xaxis.set_minor_formatter(mdates.DateFormatter('%M')) ax.legend() imgname = ticker + "_" + "trades_" + filetype + "_" + date + ".png" fig.savefig(dirpath + imgname) plt.close() print("Ticker", ticker, "at date", date, "done") print(date, "plots finished in", time() - init_tm, "seconds")
def program3(fileloc, filetype): init_tm = time() # Make dir fsplit = fileloc.split('_') date = fsplit[len(fsplit) - 1][:-4] dirpath = "program3_out/" + filetype + "/" + date + "/" pathlib.Path(dirpath).mkdir(parents=True, exist_ok=True) # Get List of tickers pf.get_tickerList(date, filetype) for ticker in projLists.ticker_list: data_starttm = time() data = pf.get_tickerData(fileloc, filetype, ticker, "Q") print("Got", ticker, "data DF in", time() - data_starttm, "Seconds") ################# # Plotting time # ################# if(data.empty): message = "At date " + date + ", ticker" + ticker + " had no quote data\n" print(message) with open("program3_" + filetype + "_log.txt", 'a+') as f: f.write(message) continue trace1 = go.Scatter(x = data.Time, y = data["Bid Price"], line = {'color': 'red'}, name = "Bid Price") trace2 = go.Scatter(x = data.Time, y = data["Ask Price"], line = {'color': 'blue'}, name = "Ask Price") title_date = data.Time[len(data) - 1].strftime('%b %-d, %Y') layout = go.Layout(xaxis={'title': 'Time (UTC)', 'type': 'date', 'tickformat': '%I:%M:%S %p'}, yaxis={'title': 'Price'}, title=ticker + " | Quotes | " + title_date) fig = go.Figure(data = [trace1, trace2], layout = layout) # Output the plot imgname = ticker + "_" + "quotes_" + filetype + "_" + date py.plot(fig, filename=dirpath + imgname + ".html", image="png", image_filename=imgname, image_width=1024, image_height=768, auto_open=False, show_link=False) print("Ticker", ticker, "at date", date, "done") print(date, "plots finished in", time() - init_tm, "seconds")
def get_program4Output(filetype, dirpath, collist, fileloc): fsplit = fileloc.split('_') date = fsplit[len(fsplit) - 1][:-4] if (filetype == "A"): venue_q = 8 venue_t = 6 region_q = 9 region_t = 7 volume = 4 else: venue_q = 10 venue_t = 8 region_q = 12 region_t = 11 volume = 6 pf.get_tickerList(date, filetype) projLists.ticker_list.remove("ALL") df = pd.DataFrame(data=0.0, index=projLists.ticker_list, columns=collist) init_tm = time() with open(fileloc, 'r') as finput: for i in range(6): next(finput) for line in finput: split_line = line.split('|') if (split_line[0] == "H"): curr_ticker = split_line[2] elif (split_line[0] == "Q"): # Update Q's for the venue and region df.at[curr_ticker, "Q-ALL"] += 1 df.at[curr_ticker, "Q-" + split_line[venue_q]] += 1 df.at[curr_ticker, "Q-" + split_line[region_q]] += 1 else: # Update T's df.at[curr_ticker, "T-ALL"] += 1 df.at[curr_ticker, "T-" + split_line[venue_t]] += 1 df.loc[curr_ticker, "T-" + split_line[region_t]] += 1 # Update V's. First line is not optimal # If we get empty string, do nothing try: df.at[curr_ticker, "V-ALL"] += float(split_line[volume]) df.at[curr_ticker, "V-" + split_line[venue_t]] += float(split_line[volume]) df.at[curr_ticker, "V-" + split_line[region_t]] += float(split_line[volume]) except ValueError: pass print("DF for " + date + " made in ", time() - init_tm, "seconds") #print(df) df.to_csv(dirpath + "program4_out_" + filetype + "_" + date + ".csv")
def program5a(fileloc, filetype, quotetype): init_tm = time() # Make dir fsplit = fileloc.split('_') date = fsplit[len(fsplit) - 1][:-4] dirpath = "program5a_out/" + filetype + "/" + date + "/" + quotetype + "/" pathlib.Path(dirpath).mkdir(parents=True, exist_ok=True) # Get List of tickers pf.get_tickerList(date, filetype) for ticker in projLists.ticker_list: data_starttm = time() data = pf.get_tickerData(fileloc, filetype, ticker, "Q") print("Got", ticker, "data DF in", time() - data_starttm, "Seconds") ################# # Plotting time # ################# if (data.empty): message = "There is no " + quotetype + " data for " + ticker + " at " + date + "\n" print(message) with open("program5a_" + filetype + "_log.txt", 'a+') as f: f.write(message) continue title_date = data.Time[len(data) - 1].strftime('%b %-d, %Y') layout = go.Layout(xaxis={ 'title': 'Time (UTC)', 'type': 'date', 'tickformat': '%I:%M:%S %p' }, yaxis={'title': 'Price'}, title=ticker + " | " + quotetype + " | " + title_date, showlegend=True) # Make a trace for each venue traces = [] for venue in data["Contributor Id"].unique(): trace = go.Scatter( x=data.Time[data["Contributor Id"] == venue], y=data[quotetype + " Price"][data["Contributor Id"] == venue], name=venue) traces.append(trace) # Output html file fig = go.Figure(data=traces, layout=layout) imgname = ticker + "_" + "quotes_" + quotetype + "_" + filetype \ + "_" + date py.plot(fig, filename=dirpath + imgname + ".html", image="png", image_filename=imgname, image_width=1024, image_height=768, auto_open=False, show_link=False) print("Ticker", ticker, "at date", date, "done") print(date, "plots finished in", time() - init_tm, "seconds")
log = open("program23_getAll_log.txt", "w+") for fileloc in projLists.file_list: # Make a directory for the date fsplit = fileloc.split('_') filedate = fsplit[len(fsplit) - 1][:-4] dirpath = 'plots/' + filetype + '/' + filedate + '/' pathlib.Path(dirpath).mkdir(parents=True, exist_ok=True) # Start timing file filetime_start = time() # Open the data file with open(fileloc, 'r') as finput: pf.get_tickerList(filedate, filetype) projLists.ticker_list.remove("ALL") # Get plots for each ticker for tick in projLists.ticker_list: ticker_start = time() print("----------------------------------------------") print("Program on date", filedate, "and ticker", tick) print("----------------------------------------------") print("Current time", ctime()) pf.go_to_ticker(finput, tick, skip_header=True) print("Getting df from output...") init_tm = time() trades, quotes = pf.get_twoDFs(finput, filetype, one_min=False) print("Got data in", time() - init_tm, "seconds")