mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 04:52:07 +00:00
Add screener and insider commands using Finviz API
This commit is contained in:
61
fundamental_analysis/finviz_api.py
Normal file
61
fundamental_analysis/finviz_api.py
Normal file
@@ -0,0 +1,61 @@
|
||||
import finviz
|
||||
import argparse
|
||||
from stock_market_helper_funcs import *
|
||||
import pandas as pd
|
||||
|
||||
|
||||
# ---------------------------------------------------- SCREENER ----------------------------------------------------
|
||||
def screener(l_args, s_ticker):
|
||||
parser = argparse.ArgumentParser(prog='screener',
|
||||
description="""Gives several metrics about the company. The following fields are expected:
|
||||
Company, Sector, Industry, Country, Index, P/E, EPS (ttm), Insider Own, Shs Outstand, Perf Week,
|
||||
Market Cap, Forward P/E, EPS next Y, Insider Trans, Shs Float, Perf Month, Income, EPS next Q,
|
||||
Inst Own, Short Float, Perf Quarter, Sales, P/S, EPS this Y, Inst Trans, Short Ratio, Perf Half Y,
|
||||
Book/sh, P/B, ROA, Target Price, Perf Year, Cash/sh, P/C, ROE, 52W Range, Perf YTD, P/FCF,
|
||||
EPS past 5Y, ROI, 52W High, Beta, Quick Ratio, Sales past 5Y, Gross Margin, 52W Low, ATR, Employees,
|
||||
Current Ratio, Sales Q/Q, Oper. Margin, RSI (14), Volatility, Optionable, Debt/Eq, EPS Q/Q,
|
||||
Profit Margin, Rel Volume, Prev Close, Shortable, LT Debt/Eq, Earnings, Payout, Avg Volume,
|
||||
Price, Recom, SMA20, SMA50, SMA200, Volume, Change. [Source: Finviz 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}")
|
||||
|
||||
d_finviz_stock = finviz.get_stock(s_ticker)
|
||||
df_fa = pd.DataFrame.from_dict(d_finviz_stock, orient='index', columns=['Values'])
|
||||
df_fa = df_fa[df_fa.Values != '-']
|
||||
print(df_fa.to_string(header=False))
|
||||
print("")
|
||||
|
||||
except:
|
||||
print("ERROR!\n")
|
||||
return
|
||||
|
||||
|
||||
# ---------------------------------------------------- INSIDER ----------------------------------------------------
|
||||
def insider(l_args, s_ticker):
|
||||
parser = argparse.ArgumentParser(prog='insider',
|
||||
description="""Gives information about inside traders. The following fields are expected:
|
||||
Date, Relationship, Transaction, #Shares, Cost, Value ($), #Shares Total, Insider Trading,
|
||||
SEC Form 4. [Source: Finviz API]""")
|
||||
|
||||
parser.add_argument('-n', "--num", action="store", dest="n_num", type=check_positive, default=10, help='Number of latest inside traders')
|
||||
|
||||
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}")
|
||||
|
||||
d_finviz_insider = finviz.get_insider(s_ticker)
|
||||
df_fa = pd.DataFrame.from_dict(d_finviz_insider)
|
||||
df_fa.set_index("Date", inplace=True)
|
||||
df_fa = df_fa[['Relationship', 'Transaction', '#Shares', 'Cost', 'Value ($)', '#Shares Total', 'Insider Trading', 'SEC Form 4']]
|
||||
print(df_fa.head(n=ns_parser.n_num))
|
||||
print("")
|
||||
|
||||
except:
|
||||
print("ERROR!\n")
|
||||
return
|
||||
@@ -12,6 +12,7 @@ from pandas.io.json import json_normalize
|
||||
|
||||
from fundamental_analysis import alpha_vantage_api as av_api
|
||||
from fundamental_analysis import financial_modeling_prep_api as fmp_api
|
||||
from fundamental_analysis import finviz_api as f_api
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------------
|
||||
@@ -43,12 +44,15 @@ def print_fundamental_analysis(s_ticker, s_start, s_interval):
|
||||
print(" quote quote of the company")
|
||||
print(" enterprise enterprise value of the company over time")
|
||||
print(" dcf discounted cash flow of the company over time")
|
||||
print(" income income statements of the company")
|
||||
print(" balance balance sheet of the company")
|
||||
print(" cash cash flow of the company")
|
||||
print(" inc income statements of the company")
|
||||
print(" bal balance sheet of the company")
|
||||
print(" cashf cash flow of the company")
|
||||
print(" metrics key metrics of the company")
|
||||
print(" ratios financial ratios of the company")
|
||||
print(" growth financial statement growth of the company")
|
||||
print("\nFinviz API")
|
||||
print(" screener screen info about the company")
|
||||
print(" insider insider trading of the company")
|
||||
print("")
|
||||
|
||||
|
||||
@@ -146,13 +150,13 @@ def fa_menu(fa_parser, s_ticker, s_start, s_interval):
|
||||
fmp_api.discounted_cash_flow(l_args, s_ticker)
|
||||
|
||||
# Financial statement:
|
||||
elif ns_known_args.fa == 'income':
|
||||
elif ns_known_args.fa == 'inc':
|
||||
fmp_api.income_statement(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.fa == 'balance':
|
||||
elif ns_known_args.fa == 'bal':
|
||||
fmp_api.balance_sheet(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.fa == 'cash':
|
||||
elif ns_known_args.fa == 'cashf':
|
||||
fmp_api.cash_flow(l_args, s_ticker)
|
||||
|
||||
# Ratios:
|
||||
@@ -165,6 +169,13 @@ def fa_menu(fa_parser, s_ticker, s_start, s_interval):
|
||||
elif ns_known_args.fa == 'growth':
|
||||
fmp_api.financial_statement_growth(l_args, s_ticker)
|
||||
|
||||
# -------------------------------------------------- FINVIZ -----------------------------------------------
|
||||
elif ns_known_args.fa == 'screener':
|
||||
f_api.screener(l_args, s_ticker)
|
||||
|
||||
elif ns_known_args.fa == 'insider':
|
||||
f_api.insider(l_args, s_ticker)
|
||||
|
||||
# ------------------------------------------------------------------------------------------------------------
|
||||
else:
|
||||
print("Command not recognized!")
|
||||
@@ -62,9 +62,10 @@ def main():
|
||||
# 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
|
||||
'overview', 'key', 'income', 'balance', 'cash', 'earnings', # AV
|
||||
'profile', 'rating', 'quote', 'enterprise', 'dcf', # FMP
|
||||
'inc', 'bal', 'cashf', 'metrics', 'ratios', 'growth', # FMP
|
||||
'screener', 'insider']) # Finviz
|
||||
|
||||
# Add list of arguments that the technical analysis parser accepts
|
||||
ta_parser = argparse.ArgumentParser(prog='technical_analysis', add_help=False)
|
||||
@@ -133,7 +134,7 @@ def main():
|
||||
print("Hope you made money today. Good bye my lover, good bye my friend.\n")
|
||||
return
|
||||
else:
|
||||
print_help(s_ticker, s_start, s_interval, b_is_stock_market_open())
|
||||
cmd.print_help(s_ticker, s_start, s_interval, b_is_stock_market_open())
|
||||
|
||||
# -------------------------------------------- TECHNICAL ANALYSIS ----------------------------------------------
|
||||
elif ns_known_args.opt == 'ta':
|
||||
@@ -143,7 +144,7 @@ def main():
|
||||
print("Hope you made money today. Good bye my lover, good bye my friend.\n")
|
||||
return
|
||||
else:
|
||||
print_help(s_ticker, s_start, s_interval, b_is_stock_market_open())
|
||||
cmd.print_help(s_ticker, s_start, s_interval, b_is_stock_market_open())
|
||||
|
||||
# ------------------------------------------------ PREDICTION --------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user