mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-29 21:42:22 +00:00
add yahoo ulc asc screener to stocks disc menu (#717)
* add ulc & asc to stock disc menu * fix docs * rename under -> ugs & add .dropna()
This commit is contained in:
@@ -44,9 +44,11 @@ class DiscoveryController:
|
||||
"fipo",
|
||||
"gainers",
|
||||
"losers",
|
||||
"under",
|
||||
"ugs",
|
||||
"gtech",
|
||||
"active",
|
||||
"ulc",
|
||||
"asc",
|
||||
"ford",
|
||||
"arkord",
|
||||
"upcoming",
|
||||
@@ -82,9 +84,11 @@ Finnhub:
|
||||
Yahoo Finance:
|
||||
gainers show latest top gainers
|
||||
losers show latest top losers
|
||||
under undervalued growth stocks
|
||||
ugs undervalued stocks with revenue and earnings growth in excess of 25%
|
||||
gtech tech stocks with revenue and earnings growth more than 25%
|
||||
active most active stocks by intraday trade volume
|
||||
ulc potentially undervalued large cap stocks
|
||||
asc small cap stocks with earnings growth rates better than 25%
|
||||
Fidelity:
|
||||
ford orders by Fidelity Customers
|
||||
cathiesark.com:
|
||||
@@ -236,7 +240,7 @@ pennystockflow.com
|
||||
add_help=False,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
prog="gainers",
|
||||
description="Print up to 25 top ticker gainers. [Source: Yahoo Finance]",
|
||||
description="Print up to 25 top gainers. [Source: Yahoo Finance]",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-n",
|
||||
@@ -278,7 +282,7 @@ pennystockflow.com
|
||||
add_help=False,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
prog="losers",
|
||||
description="Print up to 25 top ticker losers. [Source: Yahoo Finance]",
|
||||
description="Print up to 25 top losers. [Source: Yahoo Finance]",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-n",
|
||||
@@ -314,13 +318,16 @@ pennystockflow.com
|
||||
except Exception as e:
|
||||
print(e, "\n")
|
||||
|
||||
def call_under(self, other_args: List[str]):
|
||||
"""Process under command"""
|
||||
def call_ugs(self, other_args: List[str]):
|
||||
"""Process ugs command"""
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
prog="under",
|
||||
description="Print up to 25 top undervalued tickers. [Source: Yahoo Finance]",
|
||||
prog="ugs",
|
||||
description="""
|
||||
Print up to 25 undervalued stocks with revenue and earnings growth in excess of 25%.
|
||||
[Source: Yahoo Finance]
|
||||
""",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-n",
|
||||
@@ -348,7 +355,7 @@ pennystockflow.com
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
yahoofinance_view.display_undervalued(
|
||||
yahoofinance_view.display_ugs(
|
||||
num_stocks=ns_parser.num,
|
||||
export=ns_parser.export,
|
||||
)
|
||||
@@ -362,7 +369,9 @@ pennystockflow.com
|
||||
add_help=False,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
prog="gtech",
|
||||
description="Print up to 25 top growth tech tickers. [Source: Yahoo Finance]",
|
||||
description="""
|
||||
Print up to 25 top tech stocks with revenue and earnings growth in excess of 25%. [Source: Yahoo Finance]
|
||||
""",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-n",
|
||||
@@ -404,7 +413,9 @@ pennystockflow.com
|
||||
add_help=False,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
prog="active",
|
||||
description="Print up to 25 top active tickers. [Source: Yahoo Finance]",
|
||||
description="""
|
||||
Print up to 25 top most actively traded intraday tickers. [Source: Yahoo Finance]
|
||||
""",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-n",
|
||||
@@ -440,6 +451,94 @@ pennystockflow.com
|
||||
except Exception as e:
|
||||
print(e, "\n")
|
||||
|
||||
def call_ulc(self, other_args: List[str]):
|
||||
"""Process ulc command"""
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
prog="ulc",
|
||||
description="""
|
||||
Print up to 25 potentially undervalued large cap stocks. [Source: Yahoo Finance]
|
||||
""",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-n",
|
||||
"--num",
|
||||
action="store",
|
||||
dest="num",
|
||||
type=check_int_range(1, 25),
|
||||
default=5,
|
||||
help="Number of the stocks to display.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--export",
|
||||
choices=["csv", "json", "xlsx"],
|
||||
default="",
|
||||
type=str,
|
||||
dest="export",
|
||||
help="Export dataframe data to csv,json,xlsx file",
|
||||
)
|
||||
try:
|
||||
if other_args:
|
||||
if "-" not in other_args[0]:
|
||||
other_args.insert(0, "-n")
|
||||
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
yahoofinance_view.display_ulc(
|
||||
num_stocks=ns_parser.num,
|
||||
export=ns_parser.export,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
print(e, "\n")
|
||||
|
||||
def call_asc(self, other_args: List[str]):
|
||||
"""Process asc command"""
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
prog="asc",
|
||||
description="""
|
||||
Print up to 25 small cap stocks with earnings growth rates better than 25%. [Source: Yahoo Finance]
|
||||
""",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-n",
|
||||
"--num",
|
||||
action="store",
|
||||
dest="num",
|
||||
type=check_int_range(1, 25),
|
||||
default=5,
|
||||
help="Number of the stocks to display.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--export",
|
||||
choices=["csv", "json", "xlsx"],
|
||||
default="",
|
||||
type=str,
|
||||
dest="export",
|
||||
help="Export dataframe data to csv,json,xlsx file",
|
||||
)
|
||||
try:
|
||||
if other_args:
|
||||
if "-" not in other_args[0]:
|
||||
other_args.insert(0, "-n")
|
||||
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
yahoofinance_view.display_asc(
|
||||
num_stocks=ns_parser.num,
|
||||
export=ns_parser.export,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
print(e, "\n")
|
||||
|
||||
def call_ford(self, other_args: List[str]):
|
||||
"""Process ford command"""
|
||||
parser = argparse.ArgumentParser(
|
||||
|
||||
@@ -6,7 +6,7 @@ import requests
|
||||
|
||||
|
||||
def get_gainers() -> pd.DataFrame:
|
||||
"""Get Yahoo Finance gainers
|
||||
"""Get top gainers. [Source: Yahoo Finance]
|
||||
|
||||
Returns
|
||||
-------
|
||||
@@ -19,7 +19,7 @@ def get_gainers() -> pd.DataFrame:
|
||||
|
||||
|
||||
def get_losers() -> pd.DataFrame:
|
||||
"""Get Yahoo Finance losers
|
||||
"""Get top losers. [Source: Yahoo Finance]
|
||||
|
||||
Returns
|
||||
-------
|
||||
@@ -31,8 +31,8 @@ def get_losers() -> pd.DataFrame:
|
||||
return pd.read_html(requests.get(url_losers).text)[0]
|
||||
|
||||
|
||||
def get_undervalued() -> pd.DataFrame:
|
||||
"""Get Yahoo Finance undervalued growth stocks
|
||||
def get_ugs() -> pd.DataFrame:
|
||||
"""Get stocks with earnings growth rates better than 25% and relatively low PE and PEG ratios. [Source: Yahoo Finance]
|
||||
|
||||
Returns
|
||||
-------
|
||||
@@ -73,3 +73,31 @@ def get_active() -> pd.DataFrame:
|
||||
|
||||
data = pd.read_html(requests.get(url).text)[0]
|
||||
return data
|
||||
|
||||
|
||||
def get_ulc() -> pd.DataFrame:
|
||||
"""Get Yahoo Finance potentially undervalued large cap stocks. [Source: Yahoo Finance]
|
||||
|
||||
Returns
|
||||
-------
|
||||
pd.DataFrame
|
||||
Most undervalued large cap stocks
|
||||
"""
|
||||
url = "https://finance.yahoo.com/screener/predefined/undervalued_large_caps"
|
||||
|
||||
data = pd.read_html(requests.get(url).text)[0]
|
||||
return data
|
||||
|
||||
|
||||
def get_asc() -> pd.DataFrame:
|
||||
"""Get Yahoo Finance small cap stocks with earnings growth rates better than 25%. [Source: Yahoo Finance]
|
||||
|
||||
Returns
|
||||
-------
|
||||
pd.DataFrame
|
||||
Most aggressive small cap stocks
|
||||
"""
|
||||
url = "https://finance.yahoo.com/screener/predefined/aggressive_small_caps"
|
||||
|
||||
data = pd.read_html(requests.get(url).text)[0]
|
||||
return data
|
||||
|
||||
@@ -79,7 +79,7 @@ def display_losers(num_stocks: int, export: str):
|
||||
)
|
||||
|
||||
|
||||
def display_undervalued(num_stocks: int, export: str):
|
||||
def display_ugs(num_stocks: int, export: str):
|
||||
"""Display most undervalued growth stock. [Source: Yahoo Finance]
|
||||
|
||||
Parameters
|
||||
@@ -89,7 +89,7 @@ def display_undervalued(num_stocks: int, export: str):
|
||||
export : str
|
||||
Export dataframe data to csv,json,xlsx file
|
||||
"""
|
||||
df = yahoofinance_model.get_undervalued()
|
||||
df = yahoofinance_model.get_ugs()
|
||||
df.dropna(how="all", axis=1, inplace=True)
|
||||
df = df.replace(float("NaN"), "")
|
||||
|
||||
@@ -110,7 +110,7 @@ def display_undervalued(num_stocks: int, export: str):
|
||||
export_data(
|
||||
export,
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"undervalued",
|
||||
"ugs",
|
||||
df,
|
||||
)
|
||||
|
||||
@@ -185,3 +185,75 @@ def display_active(num_stocks: int, export: str):
|
||||
"active",
|
||||
df,
|
||||
)
|
||||
|
||||
|
||||
def display_ulc(num_stocks: int, export: str):
|
||||
"""Display potentially undervalued large cap stocks. [Source: Yahoo Finance]
|
||||
|
||||
Parameters
|
||||
----------
|
||||
num_stocks: int
|
||||
Number of stocks to display
|
||||
export : str
|
||||
Export dataframe data to csv,json,xlsx file
|
||||
"""
|
||||
df = yahoofinance_model.get_ulc()
|
||||
df.dropna(how="all", axis=1, inplace=True)
|
||||
df = df.replace(float("NaN"), "")
|
||||
|
||||
if df.empty:
|
||||
print("No data found.")
|
||||
else:
|
||||
print(
|
||||
tabulate(
|
||||
df.head(num_stocks).dropna(),
|
||||
headers=df.columns,
|
||||
floatfmt=".2f",
|
||||
showindex=False,
|
||||
tablefmt="fancy_grid",
|
||||
)
|
||||
)
|
||||
print("")
|
||||
|
||||
export_data(
|
||||
export,
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"ulc",
|
||||
df,
|
||||
)
|
||||
|
||||
|
||||
def display_asc(num_stocks: int, export: str):
|
||||
"""Display small cap stocks with earnings growth rates better than 25%. [Source: Yahoo Finance]
|
||||
|
||||
Parameters
|
||||
----------
|
||||
num_stocks: int
|
||||
Number of stocks to display
|
||||
export : str
|
||||
Export dataframe data to csv,json,xlsx file
|
||||
"""
|
||||
df = yahoofinance_model.get_asc()
|
||||
df.dropna(how="all", axis=1, inplace=True)
|
||||
df = df.replace(float("NaN"), "")
|
||||
|
||||
if df.empty:
|
||||
print("No data found.")
|
||||
else:
|
||||
print(
|
||||
tabulate(
|
||||
df.head(num_stocks).dropna(),
|
||||
headers=df.columns,
|
||||
floatfmt=".2f",
|
||||
showindex=False,
|
||||
tablefmt="fancy_grid",
|
||||
)
|
||||
)
|
||||
print("")
|
||||
|
||||
export_data(
|
||||
export,
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"asc",
|
||||
df,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user