mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
Add cash_flow and income_statement to fundamental analysis
This commit is contained in:
@@ -60,6 +60,8 @@ def print_help(s_ticker, s_start, s_interval, b_is_market_open):
|
||||
if s_ticker:
|
||||
print("\nFundamental Analysis:")
|
||||
print(" ratings company ratings from strong sell to strong buy")
|
||||
print(" income income statements of the company")
|
||||
print(" cash cash flow of the company")
|
||||
|
||||
print("\nTechnical Analysis:")
|
||||
print(" sma simple moving average")
|
||||
@@ -115,7 +117,8 @@ def main():
|
||||
# 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',
|
||||
'cci', 'aroon', 'bbands', 'ad', 'obv', 'ratings'])
|
||||
'cci', 'aroon', 'bbands', 'ad', 'obv', 'ratings',
|
||||
'income', 'cash'])
|
||||
|
||||
# Print first welcome message and help
|
||||
print("\nWelcome to Didier's Stock Market Bot\n")
|
||||
@@ -182,7 +185,15 @@ def main():
|
||||
smfa.ratings(l_args, s_ticker)
|
||||
continue
|
||||
|
||||
#from alpha_vantage.fundamentaldata import FundamentalData
|
||||
# -------------------------------------------------- CASH_FLOW --------------------------------------------------
|
||||
elif ns_known_args.cmd == 'cash':
|
||||
smfa.cash_flow(l_args, s_ticker)
|
||||
continue
|
||||
|
||||
# ----------------------------------------------- INCOME_STATEMENT -----------------------------------------------
|
||||
elif ns_known_args.cmd == 'income':
|
||||
smfa.income_statement(l_args, s_ticker)
|
||||
continue
|
||||
|
||||
# --------------------------------------------------------------------------------------------------------------
|
||||
# -------------------------------------------- TECHNICAL ANALYSIS ----------------------------------------------
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import FundamentalAnalysis as fa
|
||||
from alpha_vantage.fundamentaldata import FundamentalData
|
||||
import config_bot as cfg
|
||||
import argparse
|
||||
from stock_market_helper_funcs import *
|
||||
@@ -25,3 +26,77 @@ def ratings(l_args, s_ticker):
|
||||
print("")
|
||||
except:
|
||||
print("")
|
||||
|
||||
|
||||
# ---------------------------------------------------- INCOME_STATEMENT ----------------------------------------------------
|
||||
def income_statement(l_args, s_ticker):
|
||||
parser = argparse.ArgumentParser(prog='income',
|
||||
description=""" """)
|
||||
|
||||
parser.add_argument('-n', "--num", action="store", dest="n_num", type=check_positive, default=1, help='Number of informations')
|
||||
parser.add_argument('-q', action="store_true", default=False, dest="b_quarter", help='Quarter fundamental data')
|
||||
|
||||
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:
|
||||
fd = FundamentalData(key=cfg.API_KEY_ALPHAVANTAGE, output_format='pandas')
|
||||
if ns_parser.b_quarter:
|
||||
df_fd, d_fd_metadata = fd.get_income_statement_quarterly(symbol=s_ticker)
|
||||
else:
|
||||
df_fd, d_fd_metadata = fd.get_income_statement_annual(symbol=s_ticker)
|
||||
|
||||
df_fd = df_fd.set_index('fiscalDateEnding')
|
||||
df_fd = df_fd.head(n=ns_parser.n_num).T
|
||||
df_fd = df_fd.mask(df_fd.astype(object).eq(ns_parser.n_num*['None'])).dropna()
|
||||
df_fd = df_fd.mask(df_fd.astype(object).eq(ns_parser.n_num*['0'])).dropna()
|
||||
df_fd = df_fd.applymap(lambda x: long_number_format(x))
|
||||
df_fd.index = [''.join(' ' + char if char.isupper() else char.strip() for char in idx).strip() for idx in df_fd.index.tolist()]
|
||||
print(df_fd)
|
||||
print("")
|
||||
except:
|
||||
print("")
|
||||
return
|
||||
|
||||
|
||||
# ---------------------------------------------------- CASH_FLOW ----------------------------------------------------
|
||||
def cash_flow(l_args, s_ticker):
|
||||
parser = argparse.ArgumentParser(prog='cash',
|
||||
description=""" """)
|
||||
|
||||
parser.add_argument('-n', "--num", action="store", dest="n_num", type=check_positive, default=1, help='Number of informations')
|
||||
parser.add_argument('-q', action="store_true", default=False, dest="b_quarter", help='Quarter fundamental data')
|
||||
|
||||
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:
|
||||
fd = FundamentalData(key=cfg.API_KEY_ALPHAVANTAGE, output_format='pandas')
|
||||
if ns_parser.b_quarter:
|
||||
df_fd, d_fd_metadata = fd.get_cash_flow_quarterly(symbol=s_ticker)
|
||||
else:
|
||||
df_fd, d_fd_metadata = fd.get_cash_flow_annual(symbol=s_ticker)
|
||||
|
||||
df_fd = df_fd.set_index('fiscalDateEnding')
|
||||
df_fd = df_fd.head(n=ns_parser.n_num).T
|
||||
df_fd = df_fd.mask(df_fd.astype(object).eq(ns_parser.n_num*['None'])).dropna()
|
||||
df_fd = df_fd.mask(df_fd.astype(object).eq(ns_parser.n_num*['0'])).dropna()
|
||||
df_fd = df_fd.applymap(lambda x: long_number_format(x))
|
||||
df_fd.index = [''.join(' ' + char if char.isupper() else char.strip() for char in idx).strip() for idx in df_fd.index.tolist()]
|
||||
print(df_fd)
|
||||
print("")
|
||||
except:
|
||||
print("")
|
||||
return
|
||||
|
||||
@@ -135,6 +135,8 @@ def long_number_format(s_num):
|
||||
while abs(n_num) >= 1000:
|
||||
magnitude += 1
|
||||
n_num /= 1000.0
|
||||
# add more suffixes if you need them
|
||||
return '%.2f%s' % (n_num, ['', ' K', ' M', ' G', ' T', ' P'][magnitude])
|
||||
if n_num.is_integer():
|
||||
return '%d%s' % (n_num, ['', ' K', ' M', ' B', ' T', ' P'][magnitude])
|
||||
else:
|
||||
return '%.2f%s' % (n_num, ['', ' K', ' M', ' B', ' T', ' P'][magnitude])
|
||||
return s_num
|
||||
Reference in New Issue
Block a user