From b9765a6d38333111e8fcc0aafda6fc084f3ba41d Mon Sep 17 00:00:00 2001 From: didier Date: Sun, 31 Jan 2021 22:35:59 +0000 Subject: [PATCH] Add next earnings release dates to disc menu --- discovery/disc_menu.py | 8 ++++- discovery/seeking_alpha_api.py | 49 +++++++++++++++++++++++++++ due_diligence/business_insider_api.py | 12 +++---- 3 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 discovery/seeking_alpha_api.py diff --git a/discovery/disc_menu.py b/discovery/disc_menu.py index c188e05a951..b7339a040c0 100644 --- a/discovery/disc_menu.py +++ b/discovery/disc_menu.py @@ -5,6 +5,7 @@ from discovery import yahoo_finance_api from discovery import reddit_api from discovery import finviz_api from discovery import short_interest_api +from discovery import seeking_alpha_api # ----------------------------------------------------------------------------------------------------------------------- @@ -19,6 +20,7 @@ def print_discovery(): print(" map S&P500 index stocks map [Finviz]") print(" sectors show sectors performance [Alpha Vantage]") print(" gainers show latest top gainers [Yahoo Finance]") + print(" earnings next earnings release dates [Seeking Alpha]") print(" high_short show top high short interest stocks of over 20% ratio [www.highshortinterest.com]") print(" low_float show low float stocks under 10M shares float [www.lowfloat.com]") print("") @@ -38,7 +40,7 @@ def disc_menu(): # Add list of arguments that the discovery parser accepts disc_parser = argparse.ArgumentParser(prog='discovery', add_help=False) disc_parser.add_argument('cmd', choices=['help', 'q', 'quit', - 'map', 'sectors', 'gainers', 'high_short', 'low_float', + 'map', 'sectors', 'gainers', 'high_short', 'low_float', 'earnings', 'watchlist', 'spac', 'spac_c', 'wsb', 'popular']) print_discovery() @@ -79,6 +81,10 @@ def disc_menu(): elif ns_known_args.cmd == 'gainers': yahoo_finance_api.gainers(l_args) + # ------------------------------------------------ SEEKING ALPHA ------------------------------------------------ + elif ns_known_args.cmd == 'earnings': + seeking_alpha_api.earnings_release_dates(l_args) + # ------------------------------------------------ SHORT_INTEREST ------------------------------------------------ elif ns_known_args.cmd == 'high_short': short_interest_api.high_short_interest(l_args) diff --git a/discovery/seeking_alpha_api.py b/discovery/seeking_alpha_api.py new file mode 100644 index 00000000000..0876a7a412f --- /dev/null +++ b/discovery/seeking_alpha_api.py @@ -0,0 +1,49 @@ +import argparse +from bs4 import BeautifulSoup +import requests +import pandas as pd +from stock_market_helper_funcs import * + + +# ------------------------------------------------ EARNINGS_RELEASE_DATES ------------------------------------------------- +def earnings_release_dates(l_args): + parser = argparse.ArgumentParser(prog='earnings_release_dates', + description='''Next earnings release dates [Seeking Alpha]''') + + parser.add_argument('-p', "--pages", action="store", dest="n_pages", type=check_positive, default=10, help='Number of pages to read earnings from') + parser.add_argument('-n', "--num", action="store", dest="n_num", type=check_positive, default=3, help='Number of next earnings release dates to show') + + try: + (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) + + if l_unknown_args: + print(f"The following args couldn't be interpreted: {l_unknown_args}") + + l_earnings = list() + for idx in range(0, ns_parser.n_pages): + url_next_earnings = f"https://seekingalpha.com/earnings/earnings-calendar/{idx+1}" + text_soup_earnings = BeautifulSoup(requests.get(url_next_earnings).text, "lxml") + + for bs_stock in text_soup_earnings.findAll('tr', {'data-exchange': 'NASDAQ'}): + l_stock = list() + for stock in bs_stock.contents[:3]: + l_stock.append(stock.text) + l_earnings.append(l_stock) + + df_earnings = pd.DataFrame(l_earnings, columns=['Ticker', 'Name', 'Date']) + df_earnings['Date'] = pd.to_datetime(df_earnings['Date']) + df_earnings = df_earnings.set_index('Date') + + pd.set_option('display.max_colwidth', -1) + for n_days, earning_date in enumerate(df_earnings.index.unique()): + if n_days > (ns_parser.n_num-1): + break + + print(f"Earning Release on {earning_date.date()}") + print("----------------------------------------------") + print(df_earnings[earning_date == df_earnings.index][['Ticker', 'Name']].to_string(index=False, header=False)) + print("") + + except SystemExit: + print("") + return diff --git a/due_diligence/business_insider_api.py b/due_diligence/business_insider_api.py index abca8d91f0c..70dc125890e 100644 --- a/due_diligence/business_insider_api.py +++ b/due_diligence/business_insider_api.py @@ -277,9 +277,9 @@ def insider_activity(l_args, df_stock, s_ticker, s_start, s_interval): n_stock_price = df_stock['4. close'][ind_dt] plt.vlines(x=ind_dt, - ymin= n_stock_price + n_proportion * float(df_insider[df_insider['Type'] == 'Sell'].groupby(by=['Date']).sum()['Trade'][ind]), - ymax= n_stock_price, - colors='red', ls='-', lw=5) + ymin= n_stock_price + n_proportion * float(df_insider[df_insider['Type'] == 'Sell'].groupby(by=['Date']).sum()['Trade'][ind]), + ymax= n_stock_price, + colors='red', ls='-', lw=5) for ind in df_insider[df_insider['Type'] == 'Buy'].groupby(by=['Date']).sum().index: if ind in df_stock.index: @@ -294,9 +294,9 @@ def insider_activity(l_args, df_stock, s_ticker, s_start, s_interval): n_stock_price = df_stock['4. close'][ind_dt] plt.vlines(x=ind_dt, - ymin=n_stock_price, - ymax=n_stock_price + n_proportion * float(df_insider[df_insider['Type'] == 'Buy'].groupby(by=['Date']).sum()['Trade'][ind]), - colors='green', ls='-', lw=5) + ymin=n_stock_price, + ymax=n_stock_price + n_proportion * float(df_insider[df_insider['Type'] == 'Buy'].groupby(by=['Date']).sum()['Trade'][ind]), + colors='green', ls='-', lw=5) plt.grid(b=True, which='major', color='#666666', linestyle='-') plt.minorticks_on()