mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
Extract main key metrics from overview data
This commit is contained in:
@@ -39,8 +39,6 @@ def print_help(s_ticker, s_start, s_interval, b_is_market_open):
|
||||
""" Print help
|
||||
"""
|
||||
print("What do you want to do?")
|
||||
|
||||
print("\nMenu:")
|
||||
print(" gainers show latest top gainers")
|
||||
print(" sectors show sectors performance")
|
||||
print(" view view and load a specific stock ticker for technical analysis")
|
||||
@@ -50,55 +48,21 @@ def print_help(s_ticker, s_start, s_interval, b_is_market_open):
|
||||
print(" quit to abandon the program")
|
||||
|
||||
s_intraday = (f'Intraday {s_interval}', 'Daily')[s_interval == "1440min"]
|
||||
|
||||
if s_ticker and s_start:
|
||||
print(f"\n{s_intraday} Stock: {s_ticker} (from {s_start.strftime('%Y-%m-%d')})")
|
||||
elif s_ticker:
|
||||
print(f"\n{s_intraday} Stock: {s_ticker}")
|
||||
else:
|
||||
print("\nStock: ?")
|
||||
print(f"Market {('CLOSED', 'OPEN')[b_is_market_open]}.")
|
||||
|
||||
if s_ticker:
|
||||
print("\nFundamental Analysis:") # https://github.com/JerBouma/FundamentalAnalysis
|
||||
print(" info provides information on main key metrics of company")
|
||||
print("details:")
|
||||
print(" profile profile of the company [FMP]")
|
||||
print(" rating rating of the company from strong sell to strong buy [FMP]")
|
||||
print(" quote quote of the company [FMP]")
|
||||
print(" enterprise enterprise value of the company over time [FMP]")
|
||||
print(" dcf discounted cash flow of the company over time [FMP]")
|
||||
print(" overview overview of the company [AV]")
|
||||
print(" earnings earnings dates and reported EPS [AV]")
|
||||
print("financial statement:")
|
||||
print(" income income statements of the company [default: AV, FMP]")
|
||||
print(" balance balance sheet of the company [default: AV, FMP]")
|
||||
print(" cash cash flow of the company [default: AV, FMP]")
|
||||
print("ratios:")
|
||||
print(" metrics key metrics of the company [FMP]")
|
||||
print(" ratios financial ratios of the company [FMP]")
|
||||
print(" growth financial statement growth of the company [FMP]")
|
||||
print("\nMenus:")
|
||||
print(" fa fundamental analysis")
|
||||
print(" ta technical analysis")
|
||||
print(" pred prediction techniques")
|
||||
|
||||
print("\nTechnical Analysis:") # https://github.com/twopirllc/pandas-ta
|
||||
print("overlap:")
|
||||
print(" ema exponential moving average")
|
||||
print(" sma simple moving average")
|
||||
if s_interval != "1440min":
|
||||
print(" vwap volume weighted average price")
|
||||
print("momentum:")
|
||||
print(" cci commodity channel index")
|
||||
print(" macd moving average convergence/divergence")
|
||||
print(" rsi relative strength index")
|
||||
print(" stoch stochastic oscillator")
|
||||
print("trend:")
|
||||
print(" adx average directional movement index")
|
||||
print(" aroon aroon indicator")
|
||||
print("volatility:")
|
||||
print(" bbands bollinger bands")
|
||||
print("volume:")
|
||||
print(" ad chaikin accumulation/distribution line values")
|
||||
print(" obv on balance volume")
|
||||
|
||||
'''
|
||||
'''
|
||||
print("\nPrediction:")
|
||||
print(" ma")
|
||||
print(" ema")
|
||||
@@ -108,9 +72,79 @@ def print_help(s_ticker, s_start, s_interval, b_is_market_open):
|
||||
print(" rnn")
|
||||
print(" lstm")
|
||||
print(" prophet")
|
||||
'''
|
||||
print(f"\nMarket {('CLOSED', 'OPEN')[b_is_market_open]}.")
|
||||
print("Stonks and things")
|
||||
'''
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------------
|
||||
def print_fundamental_analysis(s_ticker, s_start, s_interval):
|
||||
""" Print help """
|
||||
|
||||
s_intraday = (f'Intraday {s_interval}', 'Daily')[s_interval == "1440min"]
|
||||
|
||||
if s_start:
|
||||
print(f"\n{s_intraday} Stock: {s_ticker} (from {s_start.strftime('%Y-%m-%d')})")
|
||||
else:
|
||||
print(f"\n{s_intraday} Stock: {s_ticker}")
|
||||
|
||||
print("\nFundamental Analysis:") # https://github.com/JerBouma/FundamentalAnalysis
|
||||
print(" info provides information on main key metrics of company")
|
||||
print(" help show this fundamental analysis menu again")
|
||||
print(" q quit this menu, and shows back to main menu")
|
||||
print(" quit quit to abandon program")
|
||||
print("details:")
|
||||
print(" overview overview of the company [AV]")
|
||||
print(" key main key metrics of the company [AV]")
|
||||
print(" profile profile of the company [FMP]")
|
||||
print(" rating rating of the company from strong sell to strong buy [FMP]")
|
||||
print(" quote quote of the company [FMP]")
|
||||
print(" enterprise enterprise value of the company over time [FMP]")
|
||||
print(" dcf discounted cash flow of the company over time [FMP]")
|
||||
print("financial statement:")
|
||||
print(" income income statements of the company [default: AV, FMP]")
|
||||
print(" balance balance sheet of the company [default: AV, FMP]")
|
||||
print(" cash cash flow of the company [default: AV, FMP]")
|
||||
print(" earnings earnings dates and reported EPS [AV]")
|
||||
print("ratios:")
|
||||
print(" metrics key metrics of the company [FMP]")
|
||||
print(" ratios financial ratios of the company [FMP]")
|
||||
print(" growth financial statement growth of the company [FMP]")
|
||||
print("")
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------------
|
||||
def print_technical_analysis(s_ticker, s_start, s_interval):
|
||||
""" Print help """
|
||||
|
||||
s_intraday = (f'Intraday {s_interval}', 'Daily')[s_interval == "1440min"]
|
||||
|
||||
if s_start:
|
||||
print(f"\n{s_intraday} Stock: {s_ticker} (from {s_start.strftime('%Y-%m-%d')})")
|
||||
else:
|
||||
print(f"\n{s_intraday} Stock: {s_ticker}")
|
||||
|
||||
print("\nTechnical Analysis:") # https://github.com/twopirllc/pandas-ta
|
||||
print(" help show this technical analysis menu again")
|
||||
print(" q quit this menu, and shows back to main menu")
|
||||
print(" quit quit to abandon program")
|
||||
print("overlap:")
|
||||
print(" ema exponential moving average")
|
||||
print(" sma simple moving average")
|
||||
if s_interval != "1440min":
|
||||
print(" vwap volume weighted average price")
|
||||
print("momentum:")
|
||||
print(" cci commodity channel index")
|
||||
print(" macd moving average convergence/divergence")
|
||||
print(" rsi relative strength index")
|
||||
print(" stoch stochastic oscillator")
|
||||
print("trend:")
|
||||
print(" adx average directional movement index")
|
||||
print(" aroon aroon indicator")
|
||||
print("volatility:")
|
||||
print(" bbands bollinger bands")
|
||||
print("volume:")
|
||||
print(" ad chaikin accumulation/distribution line values")
|
||||
print(" obv on balance volume")
|
||||
print("")
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------------
|
||||
@@ -132,14 +166,28 @@ def main():
|
||||
df_stock = df_stock[s_start:]
|
||||
# Delete above in the future
|
||||
|
||||
main_parser = argparse.ArgumentParser(prog='stock_market_bot', add_help=False)
|
||||
|
||||
|
||||
# Add list of arguments that the main parser accepts
|
||||
main_parser.add_argument('cmd', choices=['quit', 'help', 'gainers', 'sectors', 'view', 'load', 'clear',
|
||||
'sma', 'ema', 'macd', 'vwap', 'stoch', 'rsi', 'adx', 'quote',
|
||||
'cci', 'aroon', 'bbands', 'ad', 'obv', 'rating', 'profile',
|
||||
'income', 'balance', 'cash', 'metrics', 'ratios', 'growth',
|
||||
'enterprise', 'dcf', 'overview', 'earnings', 'info'])
|
||||
menu_parser = argparse.ArgumentParser(prog='stock_market_bot', add_help=False)
|
||||
menu_parser.add_argument('cmd', choices=['gainers', 'sectors', 'view', 'clear', 'load',
|
||||
'fa', 'ta', 'help', 'quit'])
|
||||
|
||||
# Add list of arguments that the fundamental analysis parser accepts
|
||||
fa_parser = argparse.ArgumentParser(prog='fundamental_analysis', add_help=False)
|
||||
fa_parser.add_argument('fa', choices=['info', 'help', 'q', 'quit',
|
||||
'overview', 'key', 'profile', 'rating', 'quote', 'enterprise', 'dcf', # details
|
||||
'income', 'balance', 'cash', 'earnings', # financial statement
|
||||
'metrics', 'ratios', 'growth']) # ratios
|
||||
|
||||
# Add list of arguments that the technical analysis parser accepts
|
||||
ta_parser = argparse.ArgumentParser(prog='technical_analysis', add_help=False)
|
||||
ta_parser.add_argument('ta', choices=['help', 'q', 'quit',
|
||||
'ema', 'sma', 'vwap', # overlap
|
||||
'cci', 'macd', 'rsi', 'stoch', # momentum
|
||||
'adx', 'aroon', # trend
|
||||
'bbands', # volatility
|
||||
'ad', 'obv']) # volume
|
||||
|
||||
|
||||
# Print first welcome message and help
|
||||
print("\nWelcome to Didier's Stock Market Bot\n")
|
||||
@@ -153,7 +201,8 @@ def main():
|
||||
|
||||
# Parse main command of the list of possible commands
|
||||
try:
|
||||
(ns_known_args, l_args) = main_parser.parse_known_args(as_input.split())
|
||||
(ns_known_args, l_args) = menu_parser.parse_known_args(as_input.split())
|
||||
|
||||
except SystemExit:
|
||||
print("The command selected doesn't exist\n")
|
||||
continue
|
||||
@@ -165,12 +214,10 @@ def main():
|
||||
# --------------------------------------------------- GAINERS --------------------------------------------------
|
||||
if ns_known_args.cmd == 'gainers':
|
||||
smm.gainers(l_args)
|
||||
continue
|
||||
|
||||
# --------------------------------------------------- SECTORS --------------------------------------------------
|
||||
if ns_known_args.cmd == 'sectors':
|
||||
smm.sectors(l_args)
|
||||
continue
|
||||
|
||||
# --------------------------------------------------- CLEAR ----------------------------------------------------
|
||||
elif ns_known_args.cmd == 'clear':
|
||||
@@ -181,141 +228,180 @@ def main():
|
||||
# ---------------------------------------------------- LOAD ----------------------------------------------------
|
||||
elif ns_known_args.cmd == 'load':
|
||||
[s_ticker, s_start, s_interval, df_stock] = smm.load(l_args, s_ticker, s_start, s_interval, df_stock)
|
||||
continue
|
||||
|
||||
# ---------------------------------------------------- VIEW ----------------------------------------------------
|
||||
elif ns_known_args.cmd == 'view':
|
||||
smm.view(l_args, s_ticker, s_start, s_interval, df_stock)
|
||||
continue
|
||||
|
||||
# ---------------------------------------------------- HELP ----------------------------------------------------
|
||||
# ---------------------------------------------------- HELP ----------------------------------------------------
|
||||
elif ns_known_args.cmd == 'help':
|
||||
print_help(s_ticker, s_start, s_interval, b_is_stock_market_open())
|
||||
|
||||
# ----------------------------------------------------- QUIT ----------------------------------------------------
|
||||
elif ns_known_args.cmd == 'quit':
|
||||
print("Hope you made money today. Good bye my lover, good bye my friend.\n")
|
||||
break
|
||||
return
|
||||
|
||||
# --------------------------------------------------------------------------------------------------------------
|
||||
# ------------------------------------------- FUNDAMENTAL ANALYSIS ---------------------------------------------
|
||||
# --------------------------------------------------------------------------------------------------------------
|
||||
elif ns_known_args.cmd == 'fa':
|
||||
# Print fundamental analysis menun
|
||||
print_fundamental_analysis(s_ticker, s_start, s_interval)
|
||||
|
||||
# -------------------------------------------------- DETAILS --------------------------------------------------
|
||||
elif ns_known_args.cmd == 'info':
|
||||
smfa.info(l_args, s_ticker)
|
||||
continue
|
||||
|
||||
elif ns_known_args.cmd == 'profile':
|
||||
smfa.profile(l_args, s_ticker)
|
||||
continue
|
||||
# Loop forever and ever
|
||||
while True:
|
||||
# Get input command from user
|
||||
as_input = input('> ')
|
||||
|
||||
# Parse fundamental analysis command of the list of possible commands
|
||||
try:
|
||||
(ns_known_args, l_args) = fa_parser.parse_known_args(as_input.split())
|
||||
|
||||
elif ns_known_args.cmd == 'rating':
|
||||
smfa.rating(l_args, s_ticker)
|
||||
continue
|
||||
except SystemExit:
|
||||
print("The command selected doesn't exist\n")
|
||||
continue
|
||||
|
||||
elif ns_known_args.cmd == 'quote':
|
||||
smfa.quote(l_args, s_ticker)
|
||||
continue
|
||||
|
||||
elif ns_known_args.cmd == 'enterprise':
|
||||
smfa.enterprise(l_args, s_ticker)
|
||||
continue
|
||||
if ns_known_args.fa == 'info':
|
||||
smfa.info(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.cmd == 'dcf':
|
||||
smfa.discounted_cash_flow(l_args, s_ticker)
|
||||
continue
|
||||
elif ns_known_args.fa == 'help':
|
||||
print_fundamental_analysis(s_ticker, s_start, s_interval)
|
||||
|
||||
elif ns_known_args.cmd == 'overview':
|
||||
smfa.overview(l_args, s_ticker)
|
||||
continue
|
||||
elif ns_known_args.fa == 'q':
|
||||
print_help(s_ticker, s_start, s_interval, b_is_stock_market_open())
|
||||
break
|
||||
|
||||
elif ns_known_args.cmd == 'earnings':
|
||||
smfa.earnings(l_args, s_ticker)
|
||||
continue
|
||||
elif ns_known_args.fa == 'quit':
|
||||
print("Hope you made money today. Good bye my lover, good bye my friend.\n")
|
||||
return
|
||||
|
||||
# -------------------------------------------------- DETAILS --------------------------------------------------
|
||||
elif ns_known_args.fa == 'profile':
|
||||
smfa.profile(l_args, s_ticker)
|
||||
|
||||
# --------------------------------------------- FINANCIAL STATEMENT --------------------------------------------
|
||||
elif ns_known_args.cmd == 'income':
|
||||
smfa.income_statement(l_args, s_ticker)
|
||||
continue
|
||||
elif ns_known_args.fa == 'rating':
|
||||
smfa.rating(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.cmd == 'balance':
|
||||
smfa.balance_sheet(l_args, s_ticker)
|
||||
continue
|
||||
elif ns_known_args.fa == 'quote':
|
||||
smfa.quote(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.fa == 'enterprise':
|
||||
smfa.enterprise(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.cmd == 'cash':
|
||||
smfa.cash_flow(l_args, s_ticker)
|
||||
continue
|
||||
elif ns_known_args.fa == 'dcf':
|
||||
smfa.discounted_cash_flow(l_args, s_ticker)
|
||||
|
||||
# --------------------------------------------------- RATIOS -----------------------------------------------------
|
||||
elif ns_known_args.cmd == 'metrics':
|
||||
smfa.key_metrics(l_args, s_ticker)
|
||||
continue
|
||||
elif ns_known_args.fa == 'overview':
|
||||
smfa.overview(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.cmd == 'ratios':
|
||||
smfa.financial_ratios(l_args, s_ticker)
|
||||
continue
|
||||
elif ns_known_args.fa == 'key':
|
||||
smfa.key(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.cmd == 'growth':
|
||||
smfa.financial_statement_growth(l_args, s_ticker)
|
||||
continue
|
||||
# --------------------------------------------- FINANCIAL STATEMENT --------------------------------------------
|
||||
elif ns_known_args.fa == 'income':
|
||||
smfa.income_statement(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.fa == 'balance':
|
||||
smfa.balance_sheet(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.fa == 'cash':
|
||||
smfa.cash_flow(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.fa == 'earnings':
|
||||
smfa.earnings(l_args, s_ticker)
|
||||
|
||||
# --------------------------------------------------- RATIOS -----------------------------------------------------
|
||||
elif ns_known_args.fa == 'metrics':
|
||||
smfa.key_metrics(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.fa == 'ratios':
|
||||
smfa.financial_ratios(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.fa == 'growth':
|
||||
smfa.financial_statement_growth(l_args, s_ticker)
|
||||
|
||||
# ------------------------------------------------------------------------------------------------------------
|
||||
else:
|
||||
print("Command not recognized!")
|
||||
|
||||
print("")
|
||||
|
||||
# --------------------------------------------------------------------------------------------------------------
|
||||
# -------------------------------------------- TECHNICAL ANALYSIS ----------------------------------------------
|
||||
# --------------------------------------------------------------------------------------------------------------
|
||||
elif ns_known_args.cmd == 'ta':
|
||||
# Print technical analysis menun
|
||||
print_technical_analysis(s_ticker, s_start, s_interval)
|
||||
|
||||
# -------------------------------------------------- OVERLAP --------------------------------------------------
|
||||
elif ns_known_args.cmd == 'ema':
|
||||
smta.ema(l_args, s_ticker, s_interval, df_stock)
|
||||
continue
|
||||
# Loop forever and ever
|
||||
while True:
|
||||
# Get input command from user
|
||||
as_input = input('> ')
|
||||
|
||||
# Parse fundamental analysis command of the list of possible commands
|
||||
try:
|
||||
(ns_known_args, l_args) = ta_parser.parse_known_args(as_input.split())
|
||||
|
||||
elif ns_known_args.cmd == 'sma':
|
||||
smta.sma(l_args, s_ticker, s_interval, df_stock)
|
||||
continue
|
||||
except SystemExit:
|
||||
print("The command selected doesn't exist\n")
|
||||
continue
|
||||
|
||||
elif ns_known_args.cmd == 'vwap':
|
||||
smta.vwap(l_args, s_ticker, s_interval, df_stock)
|
||||
continue
|
||||
if ns_known_args.ta == 'help':
|
||||
print_technical_analysis(s_ticker, s_start, s_interval)
|
||||
|
||||
# --------------------------------------------------- MOMENTUM ---------------------------------------------------
|
||||
elif ns_known_args.cmd == 'cci':
|
||||
smta.cci(l_args, s_ticker, s_interval, df_stock)
|
||||
continue
|
||||
elif ns_known_args.ta == 'q':
|
||||
print_help(s_ticker, s_start, s_interval, b_is_stock_market_open())
|
||||
break
|
||||
|
||||
elif ns_known_args.cmd == 'macd':
|
||||
smta.macd(l_args, s_ticker, s_interval, df_stock)
|
||||
continue
|
||||
elif ns_known_args.ta == 'quit':
|
||||
print("Hope you made money today. Good bye my lover, good bye my friend.\n")
|
||||
return
|
||||
|
||||
elif ns_known_args.cmd == 'rsi':
|
||||
smta.rsi(l_args, s_ticker, s_interval, df_stock)
|
||||
continue
|
||||
# -------------------------------------------------- OVERLAP --------------------------------------------------
|
||||
elif ns_known_args.ta == 'ema':
|
||||
smta.ema(l_args, s_ticker, s_interval, df_stock)
|
||||
|
||||
elif ns_known_args.cmd == 'stoch':
|
||||
smta.stoch(l_args, s_ticker, s_interval, df_stock)
|
||||
continue
|
||||
|
||||
# ---------------------------------------------------- TREND ----------------------------------------------------
|
||||
elif ns_known_args.cmd == 'adx':
|
||||
smta.adx(l_args, s_ticker, s_interval, df_stock)
|
||||
continue
|
||||
elif ns_known_args.ta == 'sma':
|
||||
smta.sma(l_args, s_ticker, s_interval, df_stock)
|
||||
|
||||
elif ns_known_args.cmd == 'aroon':
|
||||
smta.aroon(l_args, s_ticker, s_interval, df_stock)
|
||||
continue
|
||||
elif ns_known_args.ta == 'vwap':
|
||||
smta.vwap(l_args, s_ticker, s_interval, df_stock)
|
||||
|
||||
# -------------------------------------------------- VOLATILITY --------------------------------------------------
|
||||
elif ns_known_args.cmd == 'bbands':
|
||||
smta.bbands(l_args, s_ticker, s_interval, df_stock)
|
||||
continue
|
||||
# --------------------------------------------------- MOMENTUM ---------------------------------------------------
|
||||
elif ns_known_args.ta == 'cci':
|
||||
smta.cci(l_args, s_ticker, s_interval, df_stock)
|
||||
|
||||
# ---------------------------------------------------- VOLUME ----------------------------------------------------
|
||||
elif ns_known_args.cmd == 'ad':
|
||||
smta.ad(l_args, s_ticker, s_interval, df_stock)
|
||||
continue
|
||||
elif ns_known_args.ta == 'macd':
|
||||
smta.macd(l_args, s_ticker, s_interval, df_stock)
|
||||
|
||||
elif ns_known_args.cmd == 'obv':
|
||||
smta.obv(l_args, s_ticker, s_interval, df_stock)
|
||||
continue
|
||||
elif ns_known_args.ta == 'rsi':
|
||||
smta.rsi(l_args, s_ticker, s_interval, df_stock)
|
||||
|
||||
elif ns_known_args.ta == 'stoch':
|
||||
smta.stoch(l_args, s_ticker, s_interval, df_stock)
|
||||
|
||||
# ---------------------------------------------------- TREND ----------------------------------------------------
|
||||
elif ns_known_args.ta == 'adx':
|
||||
smta.adx(l_args, s_ticker, s_interval, df_stock)
|
||||
|
||||
elif ns_known_args.ta == 'aroon':
|
||||
smta.aroon(l_args, s_ticker, s_interval, df_stock)
|
||||
|
||||
# -------------------------------------------------- VOLATILITY --------------------------------------------------
|
||||
elif ns_known_args.ta == 'bbands':
|
||||
smta.bbands(l_args, s_ticker, s_interval, df_stock)
|
||||
|
||||
# ---------------------------------------------------- VOLUME ----------------------------------------------------
|
||||
elif ns_known_args.ta == 'ad':
|
||||
smta.ad(l_args, s_ticker, s_interval, df_stock)
|
||||
|
||||
elif ns_known_args.ta == 'obv':
|
||||
smta.obv(l_args, s_ticker, s_interval, df_stock)
|
||||
|
||||
# ------------------------------------------------------------------------------------------------------------
|
||||
else:
|
||||
print("Command not recognized!")
|
||||
|
||||
# --------------------------------------------------------------------------------------------------------------
|
||||
# ------------------------------------------------ PREDICTION --------------------------------------------------
|
||||
@@ -324,7 +410,7 @@ def main():
|
||||
else:
|
||||
print('Shouldnt see this command!')
|
||||
|
||||
print("\n")
|
||||
print("")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -38,6 +38,126 @@ def info(l_args, s_ticker):
|
||||
print("ERROR!\n")
|
||||
|
||||
|
||||
# ---------------------------------------------------- OVERVIEW ----------------------------------------------------
|
||||
def overview(l_args, s_ticker):
|
||||
parser = argparse.ArgumentParser(prog='overview',
|
||||
description="""Gives an overview about the company. The following fields are expected:
|
||||
Symbol, Asset type, Name, Description, Exchange, Currency, Country, Sector, Industry,
|
||||
Address, Full time employees, Fiscal year end, Latest quarter, Market capitalization,
|
||||
EBITDA, PE ratio, PEG ratio, Book value, Dividend per share, Dividend yield, EPS,
|
||||
Revenue per share TTM, Profit margin, Operating margin TTM, Return on assets TTM,
|
||||
Return on equity TTM, Revenue TTM, Gross profit TTM, Diluted EPS TTM, Quarterly earnings growth YOY,
|
||||
Quarterly revenue growth YOY, Analyst target price, Trailing PE, Forward PE,
|
||||
Price to sales ratio TTM, Price to book ratio, EV to revenue, EV to EBITDA, Beta, 52 week high,
|
||||
52 week low, 50 day moving average, 200 day moving average, Shares outstanding, Shares float,
|
||||
Shares short, Shares short prior month, Short ratio, Short percent outstanding, Short percent float,
|
||||
Percent insiders, Percent institutions, Forward annual dividend rate, Forward annual dividend yield,
|
||||
Payout ratio, Dividend date, Ex dividend date, Last split factor, and Last split date.
|
||||
[Source: Alpha Vantage API]""")
|
||||
|
||||
try:
|
||||
(ns_parser, l_unknown_args) = parser.parse_known_args(l_args)
|
||||
except SystemExit:
|
||||
print("")
|
||||
return
|
||||
|
||||
if l_unknown_args:
|
||||
print(f"The following args couldn't be interpreted: {l_unknown_args}")
|
||||
|
||||
try:
|
||||
# Request OVERVIEW data from Alpha Vantage API
|
||||
s_req = f"https://www.alphavantage.co/query?function=OVERVIEW&symbol={s_ticker}&apikey={cfg.API_KEY_FINANCIALMODELINGPREP}"
|
||||
result = requests.get(s_req, stream=True)
|
||||
|
||||
# If the returned data was successful
|
||||
if result.status_code == 200:
|
||||
# Parse json data to dataframe
|
||||
df_fa = json_normalize(result.json())
|
||||
# Keep json data sorting in dataframe
|
||||
df_fa = df_fa[list(result.json().keys())].T
|
||||
df_fa = df_fa.applymap(lambda x: long_number_format(x))
|
||||
df_fa.index = [''.join(' ' + char if char.isupper() else char.strip() for char in idx).strip() for idx in df_fa.index.tolist()]
|
||||
df_fa.index = [s_val.capitalize() for s_val in df_fa.index]
|
||||
df_fa = df_fa.rename(index={"E b i t d a":"EBITDA",
|
||||
"P e ratio":"PE ratio",
|
||||
"P e g ratio":"PEG ratio",
|
||||
"E p s":"EPS",
|
||||
"Revenue per share t t m":"Revenue per share TTM",
|
||||
"Operating margin t t m":"Operating margin TTM",
|
||||
"Return on assets t t m":"Return on assets TTM",
|
||||
"Return on equity t t m":"Return on equity TTM",
|
||||
"Revenue t t m":"Revenue TTM",
|
||||
"Gross profit t t m":"Gross profit TTM",
|
||||
"Diluted e p s t t m":"Diluted EPS TTM",
|
||||
"Quarterly earnings growth y o y":"Quarterly earnings growth YOY",
|
||||
"Quarterly revenue growth y o y":"Quarterly revenue growth YOY",
|
||||
"Trailing p e":"Trailing PE",
|
||||
"Forward p e":"Forward PE",
|
||||
"Price to sales ratio t t m":"Price to sales ratio TTM",
|
||||
"E v to revenue":"EV to revenue",
|
||||
"E v to e b i t d a":"EV to EBITDA"})
|
||||
|
||||
pd.set_option('display.max_colwidth', -1)
|
||||
|
||||
print(df_fa.drop(index=['Description']).to_string(header=False))
|
||||
print(f"Description: {df_fa.loc['Description'][0]}")
|
||||
print("")
|
||||
else:
|
||||
print(f"Error: {result.status_code}")
|
||||
|
||||
except:
|
||||
print("ERROR!\n")
|
||||
|
||||
|
||||
# ------------------------------------------------------ KEY ------------------------------------------------------
|
||||
def key(l_args, s_ticker):
|
||||
parser = argparse.ArgumentParser(prog='key',
|
||||
description="""Gives main key metrics about the company (it's a subset of the
|
||||
Overview data from Alpha Vantage API). The following fields are expected:
|
||||
Market capitalization, EBITDA, EPS, PE ratio, PEG ratio, Price to book ratio,
|
||||
Return on equity TTM, Payout ratio, Price to sales ratio TTM, Dividend yield,
|
||||
50 day moving average, Analyst target price, Beta [Source: Alpha Vantage API]""")
|
||||
|
||||
try:
|
||||
(ns_parser, l_unknown_args) = parser.parse_known_args(l_args)
|
||||
except SystemExit:
|
||||
print("")
|
||||
return
|
||||
|
||||
if l_unknown_args:
|
||||
print(f"The following args couldn't be interpreted: {l_unknown_args}")
|
||||
|
||||
try:
|
||||
# Request OVERVIEW data
|
||||
s_req = f"https://www.alphavantage.co/query?function=OVERVIEW&symbol={s_ticker}&apikey={cfg.API_KEY_ALPHAVANTAGE}"
|
||||
result = requests.get(s_req, stream=True)
|
||||
|
||||
# If the returned data was successful
|
||||
if result.status_code == 200:
|
||||
df_fa = json_normalize(result.json())
|
||||
df_fa = df_fa[list(result.json().keys())].T
|
||||
|
||||
df_fa = df_fa.applymap(lambda x: long_number_format(x))
|
||||
df_fa.index = [''.join(' ' + char if char.isupper() else char.strip() for char in idx).strip() for idx in df_fa.index.tolist()]
|
||||
df_fa.index = [s_val.capitalize() for s_val in df_fa.index]
|
||||
df_fa = df_fa.rename(index={"E b i t d a":"EBITDA",
|
||||
"P e ratio":"PE ratio",
|
||||
"P e g ratio":"PEG ratio",
|
||||
"E p s":"EPS",
|
||||
"Return on equity t t m":"Return on equity TTM",
|
||||
"Price to sales ratio t t m":"Price to sales ratio TTM"})
|
||||
as_key_metrics = ["Market capitalization", "EBITDA", "EPS", "PE ratio", "PEG ratio", "Price to book ratio",
|
||||
"Return on equity TTM", "Payout ratio", "Price to sales ratio TTM", "Dividend yield",
|
||||
"50 day moving average", "Analyst target price", "Beta"]
|
||||
print(df_fa.loc[as_key_metrics].to_string(header=False))
|
||||
print("")
|
||||
else:
|
||||
print(f"Error: {result.status_code}")
|
||||
|
||||
except:
|
||||
print("ERROR!\n")
|
||||
|
||||
|
||||
# ---------------------------------------------------- PROFILE ----------------------------------------------------
|
||||
def profile(l_args, s_ticker):
|
||||
parser = argparse.ArgumentParser(prog='profile',
|
||||
@@ -208,77 +328,6 @@ def discounted_cash_flow(l_args, s_ticker):
|
||||
print("ERROR!\n")
|
||||
|
||||
|
||||
# ---------------------------------------------------- OVERVIEW ----------------------------------------------------
|
||||
def overview(l_args, s_ticker):
|
||||
parser = argparse.ArgumentParser(prog='overview',
|
||||
description="""Gives an overview about the company. The following fields are expected:
|
||||
Symbol, Asset type, Name, Description, Exchange, Currency, Country, Sector, Industry,
|
||||
Address, Full time employees, Fiscal year end, Latest quarter, Market capitalization,
|
||||
EBITDA, PE ratio, PEG ratio, Book value, Dividend per share, Dividend yield, EPS,
|
||||
Revenue per share TTM, Profit margin, Operating margin TTM, Return on assets TTM,
|
||||
Return on equity TTM, Revenue TTM, Gross profit TTM, Diluted EPS TTM, Quarterly earnings growth YOY,
|
||||
Quarterly revenue growth YOY, Analyst target price, Trailing PE, Forward PE,
|
||||
Price to sales ratio TTM, Price to book ratio, EV to revenue, EV to EBITDA, Beta, 52 week high,
|
||||
52 week low, 50 day moving average, 200 day moving average, Shares outstanding, Shares float,
|
||||
Shares short, Shares short prior month, Short ratio, Short percent outstanding, Short percent float,
|
||||
Percent insiders, Percent institutions, Forward annual dividend rate, Forward annual dividend yield,
|
||||
Payout ratio, Dividend date, Ex dividend date, Last split factor, and Last split date.
|
||||
[Source: Alpha Vantage API]""")
|
||||
|
||||
try:
|
||||
(ns_parser, l_unknown_args) = parser.parse_known_args(l_args)
|
||||
except SystemExit:
|
||||
print("")
|
||||
return
|
||||
|
||||
if l_unknown_args:
|
||||
print(f"The following args couldn't be interpreted: {l_unknown_args}")
|
||||
|
||||
try:
|
||||
# Request OVERVIEW data from Alpha Vantage API
|
||||
s_req = f"https://www.alphavantage.co/query?function=OVERVIEW&symbol={s_ticker}&apikey={cfg.API_KEY_FINANCIALMODELINGPREP}"
|
||||
result = requests.get(s_req, stream=True)
|
||||
|
||||
# If the returned data was successful
|
||||
if result.status_code == 200:
|
||||
# Parse json data to dataframe
|
||||
df_fa = json_normalize(result.json())
|
||||
# Keep json data sorting in dataframe
|
||||
df_fa = df_fa[list(result.json().keys())].T
|
||||
df_fa = df_fa.applymap(lambda x: long_number_format(x))
|
||||
df_fa.index = [''.join(' ' + char if char.isupper() else char.strip() for char in idx).strip() for idx in df_fa.index.tolist()]
|
||||
df_fa.index = [s_val.capitalize() for s_val in df_fa.index]
|
||||
df_fa = df_fa.rename(index={"E b i t d a":"EBITDA",
|
||||
"P e ratio":"PE ratio",
|
||||
"P e g ratio":"PEG ratio",
|
||||
"E p s":"EPS",
|
||||
"Revenue per share t t m":"Revenue per share TTM",
|
||||
"Operating margin t t m":"Operating margin TTM",
|
||||
"Return on assets t t m":"Return on assets TTM",
|
||||
"Return on equity t t m":"Return on equity TTM",
|
||||
"Revenue t t m":"Revenue TTM",
|
||||
"Gross profit t t m":"Gross profit TTM",
|
||||
"Diluted e p s t t m":"Diluted EPS TTM",
|
||||
"Quarterly earnings growth y o y":"Quarterly earnings growth YOY",
|
||||
"Quarterly revenue growth y o y":"Quarterly revenue growth YOY",
|
||||
"Trailing p e":"Trailing PE",
|
||||
"Forward p e":"Forward PE",
|
||||
"Price to sales ratio t t m":"Price to sales ratio TTM",
|
||||
"E v to revenue":"EV to revenue",
|
||||
"E v to e b i t d a":"EV to EBITDA"})
|
||||
|
||||
pd.set_option('display.max_colwidth', -1)
|
||||
|
||||
print(df_fa.drop(index=['Description']).to_string(header=False))
|
||||
print(f"Description: {df_fa.loc['Description'][0]}")
|
||||
print("")
|
||||
else:
|
||||
print(f"Error: {result.status_code}")
|
||||
|
||||
except:
|
||||
print("ERROR!\n")
|
||||
|
||||
|
||||
# ---------------------------------------------------- EARNINGS ----------------------------------------------------
|
||||
def earnings(l_args, s_ticker):
|
||||
parser = argparse.ArgumentParser(prog='earnings',
|
||||
|
||||
@@ -21,7 +21,7 @@ def sectors(l_args):
|
||||
|
||||
sp = SectorPerformances(key=cfg.API_KEY_ALPHAVANTAGE, output_format='pandas')
|
||||
df_sectors, d_meta_data = sp.get_sector()
|
||||
df_sectorsf['Rank A: Real-Time Performance'].plot(kind='bar')
|
||||
df_sectors['Rank A: Real-Time Performance'].plot(kind='bar')
|
||||
plt.title('Real Time Performance (%) per Sector')
|
||||
plt.tight_layout()
|
||||
plt.grid()
|
||||
|
||||
Reference in New Issue
Block a user