Skip to content

Commit

Permalink
Update contributing guide (added a new feature while doing so) (#4391)
Browse files Browse the repository at this point in the history
* Update contributing guide

* lint md

* lint md

* lint md

* Tests + fix some markdownlint things

* Get rid of irritating newline on reset

* Trying something small

* try something else

* linting

* Change cfg to the new user object

* words

* minor improvements

* some adjustments to the contributing guidelines

* Another pass at contributing

* spelling

* we need a local markdown linter

* why does this pylint disable still fail

---------

Co-authored-by: Henrique Joaquim <h.joaquim@campus.fct.unl.pt>
  • Loading branch information
jmaslek and hjoaquim authored Mar 9, 2023
1 parent 03c18f5 commit 36c0c0f
Show file tree
Hide file tree
Showing 8 changed files with 490 additions and 234 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ jobs:
MPLBACKEND: Agg
run: |
source $VENV
pytest tests/ --optimization --cov --cov-fail-under=50 --autodoc -n auto --durations=10 --timeout=30
pytest tests/ --optimization --cov --cov-fail-under=50 --autodoc -n auto --durations=10 --timeout=30 --cov-report=xml
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3

- name: Start Terminal and exit
run: |
Expand Down
572 changes: 372 additions & 200 deletions CONTRIBUTING.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Crypto Technical Analysis Controller Module"""
__docformat__ = "numpy"
# pylint: disable=too-many-lines,R0904,C0201
# pylint: disable=C0302,R0904,C0201

import argparse
import logging
Expand Down
2 changes: 1 addition & 1 deletion openbb_terminal/miscellaneous/data_sources_default.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
"epsfc": ["SeekingAlpha"],
"revfc": ["SeekingAlpha"],
"est": ["BusinessInsider"],
"pt": ["BusinessInsider"],
"pt": ["BusinessInsider", "FinancialModelingPrep"],
"dcf": ["StockAnalysis"],
"dcfc": ["FinancialModelingPrep"]
},
Expand Down
52 changes: 23 additions & 29 deletions openbb_terminal/stocks/fundamental_analysis/fa_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1782,7 +1782,7 @@ def call_pt(self, other_args: List[str]):
parser = argparse.ArgumentParser(
add_help=False,
prog="pt",
description="""Prints price target from analysts. [Source: Business Insider]""",
description="""Prints price target from analysts. [Source: Business Insider and Financial Modeling Prep]""",
)
parser.add_argument(
"-t",
Expand All @@ -1792,26 +1792,10 @@ def call_pt(self, other_args: List[str]):
type=str,
default=None,
)
parser.add_argument(
"--raw",
action="store_true",
dest="raw",
help="Only output raw data",
)
parser.add_argument(
"-l",
"--limit",
action="store",
dest="limit",
type=check_positive,
default=10,
help="Limit of latest price targets from analysts to print.",
)

if other_args and "-" not in other_args[0][0]:
other_args.insert(0, "-l")
ns_parser = self.parse_known_args_and_warn(
parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES
parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES, raw=True, limit=10
)
if ns_parser:
if ns_parser.ticker:
Expand All @@ -1821,17 +1805,27 @@ def call_pt(self, other_args: List[str]):
console.print(no_ticker_message)
return

business_insider_view.price_target_from_analysts(
symbol=self.ticker,
data=self.stock,
start_date=self.start,
limit=ns_parser.limit,
raw=ns_parser.raw,
export=ns_parser.export,
sheet_name=" ".join(ns_parser.sheet_name)
if ns_parser.sheet_name
else None,
)
if ns_parser.source == "BusinessInsider":
business_insider_view.price_target_from_analysts(
symbol=self.ticker,
data=self.stock,
start_date=self.start,
limit=ns_parser.limit,
raw=ns_parser.raw,
export=ns_parser.export,
sheet_name=" ".join(ns_parser.sheet_name)
if ns_parser.sheet_name
else None,
)
elif ns_parser.source == "FinancialModelingPrep":
fmp_view.display_price_targets(
symbol=self.ticker,
limit=ns_parser.limit,
export=ns_parser.export,
sheet_name=" ".join(ns_parser.sheet_name)
if ns_parser.sheet_name
else None,
)

@log_start_end(log=logger)
def call_est(self, other_args: List[str]):
Expand Down
39 changes: 38 additions & 1 deletion openbb_terminal/stocks/fundamental_analysis/fmp_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from openbb_terminal.core.session.current_user import get_current_user
from openbb_terminal.decorators import check_api_key, log_start_end
from openbb_terminal.helper_funcs import lambda_long_number_format
from openbb_terminal.helper_funcs import lambda_long_number_format, request
from openbb_terminal.rich_config import console
from openbb_terminal.stocks.fundamental_analysis.fa_helper import clean_df_index

Expand Down Expand Up @@ -779,3 +779,40 @@ def get_rating(symbol: str) -> pd.DataFrame:
else:
df = pd.DataFrame()
return df


@log_start_end(log=logger)
@check_api_key(["API_KEY_FINANCIALMODELINGPREP"])
def get_price_targets(symbol: str) -> pd.DataFrame:
"""Get price targets for a company [Source: Financial Modeling Prep]
Parameters
----------
symbol : str
Symbol to get data for
Returns
-------
pd.DataFrame
DataFrame of price targets
"""
current_user = get_current_user()

url = (
"https://financialmodelingprep.com/api/v4/price-target?"
f"symbol={symbol}&apikey={current_user.credentials.API_KEY_FINANCIALMODELINGPREP}"
)
response = request(url)

# Check if response is valid
if response.status_code != 200 or "Error Message" in response.json():
message = f"Error, Status Code: {response.status_code}."
message = (
message
if "Error Message" not in response.json()
else message + "\n" + response.json()["Error Message"] + ".\n"
)
console.print(message)
return pd.DataFrame()

return pd.DataFrame(response.json())
50 changes: 50 additions & 0 deletions openbb_terminal/stocks/fundamental_analysis/fmp_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import logging
import os
from datetime import datetime
from typing import Optional

import pandas as pd
Expand Down Expand Up @@ -817,3 +818,52 @@ def rating(
df,
sheet_name,
)


@log_start_end(log=logger)
@check_api_key(["API_KEY_FINANCIALMODELINGPREP"])
def display_price_targets(
symbol: str, limit: int = 10, export: str = "", sheet_name: Optional[str] = None
):
"""Display price targets for a given ticker. [Source: Financial Modeling Prep]
Parameters
----------
symbol : str
Symbol
limit: int
Number of last days ratings to display
export: str
Export dataframe data to csv,json,xlsx file
sheet_name: str
Optionally specify the name of the sheet the data is exported to.
"""
columns_to_show = [
"publishedDate",
"analystCompany",
"adjPriceTarget",
"priceWhenPosted",
]
price_targets = fmp_model.get_price_targets(symbol)
if price_targets.empty:
console.print(f"[red]No price targets found for {symbol}[/red]\n")
return
price_targets["publishedDate"] = price_targets["publishedDate"].apply(
lambda x: datetime.strptime(x, "%Y-%m-%dT%H:%M:%S.%fZ").strftime(
"%Y-%m-%d %H:%M"
)
)
export_data(
export,
os.path.dirname(os.path.abspath(__file__)),
"pt",
price_targets,
sheet_name,
)

print_rich_table(
price_targets[columns_to_show].head(limit),
headers=["Date", "Company", "Target", "Posted Price"],
show_index=False,
title=f"{symbol.upper()} Price Targets",
)
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Future Expectations:
epsfc Earning Estimate by Analysts - EPS [SeekingAlpha]
revfc Earning Estimate by Analysts - Revenue [SeekingAlpha]
est quarter and year analysts earnings estimates [BusinessInsider]
pt price targets over time [BusinessInsider]
pt price targets over time [BusinessInsider, FinancialModelingPrep]
dcf advanced Excel customizable discounted cash flow [StockAnalysis]
dcfc determine the (historical) discounted cash flow [FinancialModelingPrep]

0 comments on commit 36c0c0f

Please sign in to comment.