Skip to content

Commit

Permalink
Integrating the fmp submenu into the fa menu + plotting + ratios (#2102)
Browse files Browse the repository at this point in the history
* Moving changes from previous pr to new branch with working tests

* Fix website

* Tests : stocks/fundamental_analysis

* stocks/fundamental_analysis/fa_controller : fix bug

* Fix requested changes

* Fix linting

* Fix warnings

* Linting

Co-authored-by: Chavithra PARANA <[email protected]>
Co-authored-by: Jeroen Bouma <[email protected]>
  • Loading branch information
3 people authored Jul 21, 2022
1 parent d6291ea commit 64fcbc6
Show file tree
Hide file tree
Showing 268 changed files with 266,235 additions and 262,454 deletions.
12 changes: 10 additions & 2 deletions data_sources_default.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@
"income": [
"yf",
"polygon",
"av"
"av",
"fmp"
],
"balance": [
"yf",
"polygon",
"av"
"av",
"fmp"
],
"cash": [
"yf",
"polygon",
"av",
"fmp"
]
},
"options": {
Expand Down
9 changes: 7 additions & 2 deletions i18n/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,13 @@ en:
stocks/fa/earnings: earnings dates and reported EPS
stocks/fa/fraud: key fraud ratios
stocks/fa/dupont: detailed breakdown for return on equity
stocks/fa/_sources_: Other sources
stocks/fa/fmp: profile,quote,enterprise,dcf,income,ratios,growth from FMP
stocks/fa/profile: company profile
stocks/fa/quote: detailed stock quote information
stocks/fa/enterprise: company enterprise value
stocks/fa/metrics: key metrics over time
stocks/fa/ratios: in-depth ratios over time
stocks/fa/growth: growth of financial statement items and ratios
stocks/fa/dcfc: determine the (historical) discounted cash flow
stocks/res/_ticker: Ticker
stocks/res/macroaxis: www.macroaxis.com
stocks/res/yahoo: www.finance.yahoo.com
Expand Down
110 changes: 96 additions & 14 deletions openbb_terminal/stocks/fundamental_analysis/av_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ def get_key_metrics(ticker: str) -> pd.DataFrame:

@log_start_end(log=logger)
def get_income_statements(
ticker: str, number: int, quarterly: bool = False
ticker: str,
number: int,
quarterly: bool = False,
ratios: bool = False,
plot: bool = False,
) -> pd.DataFrame:
"""Get income statements for company
Expand All @@ -159,11 +163,15 @@ def get_income_statements(
Number of past to get
quarterly : bool, optional
Flag to get quarterly instead of annual, by default False
ratios: bool
Shows percentage change, by default False
plot: bool
If the data shall be formatted ready to plot
Returns
-------
pd.DataFrame
Dataframe of income statements
DataFrame of income statements
"""
url = (
f"https://www.alphavantage.co/query?function=INCOME_STATEMENT&symbol={ticker}"
Expand Down Expand Up @@ -204,15 +212,35 @@ def get_income_statements(
return pd.DataFrame()

df_fa = df_fa.set_index("fiscalDateEnding")
df_fa = df_fa.head(number)
df_fa = df_fa.applymap(lambda x: lambda_long_number_format(x))
return df_fa[::-1].T
df_fa = df_fa[::-1].T

df_fa = df_fa.replace("None", "0")
df_fa.iloc[1:] = df_fa.iloc[1:].astype("float")

df_fa_c = df_fa.iloc[:, -number:].applymap(
lambda x: lambda_long_number_format(x)
)

if ratios:
df_fa_pc = df_fa.iloc[1:].pct_change(axis="columns").fillna(0)
j = 0
for i in list(range(1, 25)):
df_fa.iloc[i] = df_fa_pc.iloc[j]
j += 1

df_fa = df_fa.iloc[:, 0:number]

return df_fa_c if not plot else df_fa
return pd.DataFrame()


@log_start_end(log=logger)
def get_balance_sheet(
ticker: str, number: int, quarterly: bool = False
ticker: str,
number: int,
quarterly: bool = False,
ratios: bool = False,
plot: bool = False,
) -> pd.DataFrame:
"""Get balance sheets for company
Expand All @@ -224,11 +252,15 @@ def get_balance_sheet(
Number of past to get
quarterly : bool, optional
Flag to get quarterly instead of annual, by default False
ratios: bool
Shows percentage change, by default False
plot: bool
If the data shall be formatted ready to plot
Returns
-------
pd.DataFrame
Dataframe of balance sheet statements
DataFrame of the balance sheet
"""
url = f"https://www.alphavantage.co/query?function=BALANCE_SHEET&symbol={ticker}&apikey={cfg.API_KEY_ALPHAVANTAGE}"
r = requests.get(url)
Expand Down Expand Up @@ -262,14 +294,40 @@ def get_balance_sheet(
return pd.DataFrame()

df_fa = df_fa.set_index("fiscalDateEnding")
df_fa = df_fa.head(number)
df_fa = df_fa.applymap(lambda x: lambda_long_number_format(x))
return df_fa[::-1].T
df_fa = df_fa[::-1].T

df_fa = df_fa.replace("None", "0")
df_fa.iloc[1:] = df_fa.iloc[1:].astype("float")

df_fa_c = df_fa.iloc[:, -number:].applymap(
lambda x: lambda_long_number_format(x)
)

if ratios:
df_fa_pc = df_fa.iloc[1:].pct_change(axis="columns").fillna(0)
j = 0
for i in list(range(1, 37)):
df_fa.iloc[i] = df_fa_pc.iloc[j]
j += 1

df_fa_c = df_fa.iloc[:, 0:number].applymap(
lambda x: lambda_long_number_format(x)
)

df_fa = df_fa.iloc[:, 0:number]

return df_fa_c if not plot else df_fa
return pd.DataFrame()


@log_start_end(log=logger)
def get_cash_flow(ticker: str, number: int, quarterly: bool = False) -> pd.DataFrame:
def get_cash_flow(
ticker: str,
number: int,
quarterly: bool = False,
ratios: bool = False,
plot: bool = False,
) -> pd.DataFrame:
"""Get cash flows for company
Parameters
Expand All @@ -280,6 +338,10 @@ def get_cash_flow(ticker: str, number: int, quarterly: bool = False) -> pd.DataF
Number of past to get
quarterly : bool, optional
Flag to get quarterly instead of annual, by default False
ratios: bool
Shows percentage change, by default False
plot: bool
If the data shall be formatted ready to plot
Returns
-------
Expand Down Expand Up @@ -321,9 +383,29 @@ def get_cash_flow(ticker: str, number: int, quarterly: bool = False) -> pd.DataF
return pd.DataFrame()

df_fa = df_fa.set_index("fiscalDateEnding")
df_fa = df_fa.head(number)
df_fa = df_fa.applymap(lambda x: lambda_long_number_format(x))
return df_fa[::-1].T
df_fa = df_fa[::-1].T

df_fa = df_fa.replace("None", "0")
df_fa.iloc[1:] = df_fa.iloc[1:].astype("float")

df_fa_c = df_fa.iloc[:, -number:].applymap(
lambda x: lambda_long_number_format(x)
)

if ratios:
df_fa_pc = df_fa.iloc[1:].pct_change(axis="columns").fillna(0)
j = 0
for i in list(range(1, 37)):
df_fa.iloc[i] = df_fa_pc.iloc[j]
j += 1

df_fa_c = df_fa.iloc[:, 0:number].applymap(
lambda x: lambda_long_number_format(x)
)

df_fa = df_fa.iloc[:, 0:number]

return df_fa_c if not plot else df_fa
return pd.DataFrame()


Expand Down
Loading

0 comments on commit 64fcbc6

Please sign in to comment.