def get_finance_stats(ticker): finance_stats = eq_data.get_finance_stats(ticker) if finance_stats is None: return print(f"Financial statistics for {ticker.upper()}") print() print() for i in finance_stats: print("{:<15s}".format(i + ":"), "\t\t", end="") # change "nan" to "N/A" for prettier printing if type(finance_stats[i]) == float: if math.isnan(finance_stats[i]): to_print = "N/A" else: to_print = str(round(finance_stats[i], 2)) else: to_print = str(finance_stats[i]) # make them look pretty print("{:>15s}".format(to_print)) print() input("Press enter to return...") eq_utilities.screen_clear() return
def print_sim_menu(): portfolio = load_portfolio() # main event loop while True: print("EduQuant Stock Simulator") print() print() print(portfolio) print() print() print("What would you like to do?") print("1. Purchase a stock") print("2. Sell a stock") print("3. Back to main menu") # validate input response = input() try: response = int(response) except: eq_utilities.screen_clear() print("-----------Not a valid response. Try again!") print() print() continue # sanity checks if response > 4 or response < 1: eq_utilities.screen_clear() print("-----------Not a valid response. Try again!") print() print() continue # else we're all good # Purchase a stock if response == 1: ticker = eq_utilities.get_ticker_input() eq_utilities.screen_clear() portfolio = purchase_stock(ticker, portfolio) # Sell a stock if response == 2: ticker = eq_utilities.get_ticker_input() eq_utilities.screen_clear() portfolio = sell_stock(ticker, portfolio) # Back to main menu if response == 3: eq_utilities.screen_clear() break
def get_tweets(ticker): print(f"Recent tweets for {ticker.upper()}") print() print() # get corresponding handle from ticker handle = eq_twitter.retrieve_handle_from_ticker(ticker) # scrape the timeline of tweets timeline = eq_twitter.scrape_timeline(handle) for tweet in timeline: print(tweet) print() print() input("Press enter to return...") eq_utilities.screen_clear()
def get_stock_prices(ticker): closing_prices = eq_data.get_closing_prices(ticker) if closing_prices is None: return print(f"Stock prices for {ticker.upper()}") print() print() # print headers print("Date", "\t\t\t", "Closing Price", "\t\t", "Change") # print weekly price # every 5 days = once a week for idx, val in enumerate(closing_prices[::5]): print(val[0] + ":", end="") # print it pretty print("\t\t", "{:>6}".format(val[1]), "\t\t", end="") # calculate the difference of a closing price compared # to the closing price of one week ago (one week = 5 business days) if idx * 5 < len(closing_prices) - 5: diff = float(val[1]) - float(closing_prices[idx * 5 + 5][1]) # print it pretty print("{0:>6.2f}".format(diff)) else: print() print() # build a line plot of the recent closing prices response = input("Would you like to generate a graph?(y/n): ") if response.lower() == "y": eq_utilities.print_line_plot(closing_prices, ticker) print() input("Press enter to return...") eq_utilities.screen_clear() return
def check_sec_menu(url): while True: if len(url)>66: file_name = url[66:72] else: file_name = url[53:59] print( "Would you like to check if the SEC has published Filing Data for " + file_name + "?" ) print("You will need a minimum of 500MB of diskspace to process!") print("Y/N") response = input() try: response = str(response) except: eq_utilities.screen_clear() print("Not a valid response. Try again!") continue if response != "Y" and response != "N": eq_utilities.screen_clear() print("Not a valid response. Try again!") continue if response == "Y": eq_utilities.screen_clear() if check_new_sec_exist(url) == True: print("The SEC has published " + file_name + "!") will_download_file = True else: print("There is no file") will_download_file = False break else: will_download_file = False eq_utilities.screen_clear() break del response return will_download_file
def main_menu(): # main event loop while True: print("Welcome to EduQuant") print("Please pick an option below by typing the corresponding number") print("1. See stocks") print("2. Stock simulator") print("3. See recent financial news") print("4. Update data") print("5. Exit") # validate input response = input() try: response = int(response) except: eq_utilities.screen_clear() print("-----------Not a valid response. Try again!") print() print() continue # sanity checks if response > 5 or response < 1: eq_utilities.screen_clear() print("-----------Not a valid response. Try again!") print() print() continue # else we're all good # See stocks if response == 1: eq_utilities.screen_clear() # stock menu event loop eq_stocks.print_stock_menu() # Stock simulator elif response == 2: eq_utilities.screen_clear() # simulator menu event loop eq_simulator.print_sim_menu() # TODO # See recent financial news elif response == 3: eq_utilities.screen_clear() news_scrape.print_news() # Update data elif response == 4: while True: eq_utilities.screen_clear() print("What would you like to update?") print("1. Stock closing prices") print("2. Stock financial statistics") print("3. SEC data") print("4. All (Warning: this takes forever)") print("5. Back to main menu") response = input() try: response = int(response) except: eq_utilities.screen_clear() print("-----------Not a valid response. Try again!") print() print() continue # sanity check if response > 5 or response < 1: eq_utilities.screen_clear() print("-----------Not a valid response. Try again!") print() print() continue # 1. Stock closing prices if response == 1: eq_utilities.screen_clear() yfinance_scrape.update_data("cp") # 2. Stock financial statistics elif response == 2: eq_utilities.screen_clear() yfinance_scrape.update_data("fs") # 3. SEC data elif response == 3: eq_utilities.screen_clear() sec_scrape.update_data() # 4. All elif response == 4: eq_utilities.screen_clear() yfinance_scrape.update_data("cp") yfinance_scrape.update_data("fs") sec_scrape.update_data() # 5. Back to main menu elif response == 5: eq_utilities.screen_clear() break # 5. Back to main menu elif response == 5: eq_utilities.screen_clear() break
def print_stock_menu(): # event loop while True: print(""" EduQuant focuses on the tech stock market. There are over 100 tech stocks available in this application for you to explore. You can look at each stock's information including their historical prices, tweets from the company, and advanced financial statistics to inform your stock purchases. """) print() print("What would you like to do?") print("1. See list of stocks") print("2. Check a company's stock prices") print("3. Check a company's financial statistics") print("4. Read a company's tweets") print("5. Back to main menu") # validate input response = input() try: response = int(response) except: eq_utilities.screen_clear() print("Not a valid response. Try again!") continue # sanity checks if response > 5 or response < 1: eq_utilities.screen_clear() print("Not a valid response. Try again!") continue # else we're all good # See list of stocks if response == 1: eq_utilities.screen_clear() print_stock_list() # Check a company's stock prices if response == 2: ticker = eq_utilities.get_ticker_input() eq_utilities.screen_clear() get_stock_prices(ticker) # Check a company's financial statistics if response == 3: ticker = eq_utilities.get_ticker_input() eq_utilities.screen_clear() get_finance_stats(ticker) # Read a company's tweets if response == 4: ticker = eq_utilities.get_ticker_input() eq_utilities.screen_clear() get_tweets(ticker) # Back to main menu elif response == 5: eq_utilities.screen_clear() break