Skip to content

Commit

Permalink
Improved verbosity of dd rating failure, and add color to the chart (#…
Browse files Browse the repository at this point in the history
…2204)

* Added verbosity to rating failure

* Made rating failure verbose and added color

* Fixed tests
  • Loading branch information
colin99d authored Jul 29, 2022
1 parent 7a18ff1 commit da337ab
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
2 changes: 2 additions & 0 deletions openbb_terminal/stocks/due_diligence/fmp_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from openbb_terminal import config_terminal as cfg
from openbb_terminal.decorators import log_start_end
from openbb_terminal.rich_config import console

logger = logging.getLogger(__name__)

Expand All @@ -30,6 +31,7 @@ def get_rating(ticker: str) -> pd.DataFrame:
try:
df = fa.rating(ticker, cfg.API_KEY_FINANCIALMODELINGPREP)
except ValueError as e:
console.print(f"[red]{e}[/red]\n")
logger.exception(str(e))
df = pd.DataFrame()
else:
Expand Down
10 changes: 9 additions & 1 deletion openbb_terminal/stocks/due_diligence/fmp_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
logger = logging.getLogger(__name__)


def add_color(value: str) -> str:
if "buy" in value.lower():
value = f"[green]{value}[/green]"
elif "sell" in value.lower():
value = f"[red]{value}[/red]"
return value


@log_start_end(log=logger)
def rating(ticker: str, num: int, export: str):
"""Display ratings for a given ticker. [Source: Financial Modeling Prep]
Expand All @@ -27,9 +35,9 @@ def rating(ticker: str, num: int, export: str):
df = fmp_model.get_rating(ticker)

# TODO: This could be displayed in a nice rating plot over time
# TODO: Add coloring to table

if not df.empty:
df = df.astype(str).applymap(lambda x: add_color(x))
l_recoms = [col for col in df.columns if "Recommendation" in col]
l_recoms_show = [
recom.replace("rating", "")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
ratingRecommendation ratingDetailsDCFRecommendation ratingDetailsROERecommendation ratingDetailsROARecommendation ratingDetailsDERecommendation ratingDetailsPERecommendation ratingDetailsPBRecommendation
date
2021-11-16 Strong Buy Strong Buy Neutral Neutral Buy Strong Buy Strong Buy
2021-11-15 Strong Buy Strong Buy Neutral Neutral Buy Strong Buy Strong Buy
2021-11-12 Strong Buy Strong Buy Neutral Neutral Buy Strong Buy Strong Buy
2021-11-11 Strong Buy Strong Buy Neutral Neutral Buy Strong Buy Strong Buy
2021-11-10 Strong Buy Strong Buy Neutral Neutral Buy Strong Buy Strong Buy

ratingRecommendation ratingDetailsDCFRecommendation ratingDetailsROERecommendation ratingDetailsROARecommendation ratingDetailsDERecommendation ratingDetailsPERecommendation ratingDetailsPBRecommendation
date
2021-11-16 [green]Strong Buy[/green] [green]Strong Buy[/green] Neutral Neutral [green]Buy[/green] [green]Strong Buy[/green] [green]Strong Buy[/green]
2021-11-15 [green]Strong Buy[/green] [green]Strong Buy[/green] Neutral Neutral [green]Buy[/green] [green]Strong Buy[/green] [green]Strong Buy[/green]
2021-11-12 [green]Strong Buy[/green] [green]Strong Buy[/green] Neutral Neutral [green]Buy[/green] [green]Strong Buy[/green] [green]Strong Buy[/green]
2021-11-11 [green]Strong Buy[/green] [green]Strong Buy[/green] Neutral Neutral [green]Buy[/green] [green]Strong Buy[/green] [green]Strong Buy[/green]
2021-11-10 [green]Strong Buy[/green] [green]Strong Buy[/green] Neutral Neutral [green]Buy[/green] [green]Strong Buy[/green] [green]Strong Buy[/green]

0 comments on commit da337ab

Please sign in to comment.