Add next earnings release dates to disc menu

This commit is contained in:
didier
2021-01-31 22:35:59 +00:00
parent 2db75c1d02
commit b9765a6d38
3 changed files with 62 additions and 7 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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()