Add sustainability command from Yahoo Finance

This commit is contained in:
didier
2021-01-31 17:36:19 +00:00
parent d9401d27c4
commit 5079359c94
2 changed files with 48 additions and 2 deletions

View File

@@ -48,6 +48,7 @@ def print_fundamental_analysis(s_ticker, s_start, s_interval):
print("Yahoo Finance API")
print(" info information scope of the company")
print(" shrs hareholders of the company")
print(" sust sustainability values of the company")
print("")
print("Alpha Vantage API")
print(" overview overview of the company")
@@ -104,7 +105,7 @@ def fa_menu(s_ticker, s_start, s_interval):
fa_parser.add_argument('cmd', choices=['help', 'q', 'quit', #
'screener', # Finviz
'mgmt', # Business Insider
'info', 'shrs', # Yahoo Finance
'info', 'shrs', 'sust',# Yahoo Finance
'income', 'assets', 'liabilities', 'operating', 'investing', 'financing', # MW
'overview', 'key', 'incom', 'balance', 'cash', 'earnings', # AV
'profile', 'quote', 'enterprise', 'dcf', # FMP
@@ -172,6 +173,9 @@ def fa_menu(s_ticker, s_start, s_interval):
elif ns_known_args.cmd == 'shrs':
yf_api.shareholders(l_args, s_ticker)
elif ns_known_args.cmd == 'sust':
yf_api.sustainability(l_args, s_ticker)
# ALPHA VANTAGE API
elif ns_known_args.cmd == 'overview':

View File

@@ -65,7 +65,6 @@ def info(l_args, s_ticker):
return
# ---------------------------------------------------- SHAREHOLDERS ----------------------------------------------------
def shareholders(l_args, s_ticker):
parser = argparse.ArgumentParser(prog='shareholders',
@@ -113,3 +112,46 @@ def shareholders(l_args, s_ticker):
print("")
return
# ---------------------------------------------------- SUSTAINABILITY ----------------------------------------------------
def sustainability(l_args, s_ticker):
parser = argparse.ArgumentParser(prog='sustainability',
description="""Sustainability values of the company. The following fields are expected:
Palmoil, Controversialweapons, Gambling, Socialscore, Nuclear, Furleather, Alcoholic, Gmo,
Catholic, Socialpercentile, Peercount, Governancescore, Environmentpercentile, Animaltesting,
Tobacco, Totalesg, Highestcontroversy, Esgperformance, Coal, Pesticides, Adult, Percentile,
Peergroup, Smallarms, Environmentscore, Governancepercentile, Militarycontract [Source: Yahoo Finance API]""")
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}\n")
return
stock = yf.Ticker(s_ticker)
pd.set_option('display.max_colwidth', -1)
df_sustainability = stock.sustainability
df_sustainability.index = [''.join(' ' + char if char.isupper() else char.strip() for char in idx).strip() for idx in df_sustainability.index.tolist()]
df_sustainability.index = [s_val.capitalize() for s_val in df_sustainability.index]
df_sustainability = df_sustainability.rename(index={"Controversialweapons": "Controversial Weapons",
"Socialpercentile": "Social Percentile",
"Peercount": "Peer Count",
"Governancescore": "Governance Score",
"Environmentpercentile": "Environment Percentile",
"Animaltesting": "Animal Testing",
"Highestcontroversy": "Highest Controversy",
"Environmentscore": "Environment Score",
"Governancepercentile": "Governance Percentile",
"Militarycontract": "Military Contract"})
print(df_sustainability.to_string(header=False))
print("")
except:
print("")
return