mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-28 20:23:36 +00:00
* set fred keys through api * linting * doc change * expose api keys dict * allow optional persistency of api key change * black * place decorators * add keys paths * av and fmp keys * some fixes * rewrite av, fmp, fred cassettes * quandl key * polygon key * rewrite polygon cassette * news and tradier * cmc key * change some docstring * change some docstring * filtered keys dict on mykeys * simplify mykeys collection * revert arg to persist * finnhub * iex key * reddit key * reddit docstring * check for prefix before removing * glassnode key * glassnode virtual path * bitquery keys * twitter key * robinhood key * degiro keys * oanda key * binance keys * si key * coinbase key * refactor btcrb dates and logic * walert key * coinglass key * regenerate cassettes * cpanic keys * ethplorer keys * replace ouput status failed msg * smartstake keys * gitub keys * messari keys * eodhd keys * santiment keys * remove unused imports * typo formatting test * remove forbidden arg * fix btcrb test * fix test import * revert cassette changes * fix more tests * fix last failing * black * try to change status to int code * change status to int * first try at keys controller refactoring * fix some tests accordingly * display msg on set * change some vars * remove elifs * add progress bar and remove duplicate key check * add mykeys and refresh to menu * remove unused import * change mykeys output to df * remove check keys from keys ctrl tests * update test split to new structure * reduce duplicate code * upper case * change var name * rename mykeys df cols * add keys integrations tests * add mykeys test to keys controller * fix mykeys * fix wrong eodhd var name * pylint * test_set_key * black * patch dotenv kinda * fix mypy * remove refresh * filter mykeys df * filter mykeys df * update integration tests * first unit test for set api key * add 2 more test cases to fred * add persist test to fred unittest * add av unittest * add polygon unittest * generate av cassettes * add unittests av, fmp, quandl, polygon, fred * change si token to key * forgot controller func * unittest: news, tradier, cmc, finnhub, iex, bitquery * add si unittest * update eodhd key name * add unittest: walert, glassnode, coinglass, cpanic, ethplorer, github, messari, eodhd, santiment * black * add reddit unittest * refactor unittests to handle multi args * regenerate cassettes * add more unittests * add degiro, oanda and rh unittest * generate oanda records * fix rh and degiro unittest * fix oanda unittest * black * flake8 * fix si controller test * move tmp * pylint * fix av test * fix fmp key check * rewrite fmp * rewrite oanda output * fix quandl check * rewrite expected * supress logger exception * fix iex cloud key * remove iex warning * fix coinglass check key * cpanic fix * regenerate cpanic cassettes * flake8 * fix smartstake keys check * regenerate expected output * fix eodhd * try at binance * black * fix controller tests * pylint * disable warning * flake * add option to show keys * add Enum to model * regenerate test output * update contributing * flake * fix type hint * remove status msg dict * pylint * regenerate and remove unecessary cassettes * remove duplicate return * supress traceback * remove unused imports * update some docstrings * add todo * add export option to mykeys * minor change * refactor color scheme * update contributing * update contributing * regenerate cassettes * fix check output * small msg change * small details * rewrite some tests Co-authored-by: hjoaquim <h.joaquim@campus.fct.unl.pt> Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com>
132 lines
4.5 KiB
Python
132 lines
4.5 KiB
Python
"""eodhd view"""
|
|
__docformat__ = "numpy"
|
|
import logging
|
|
import os
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
from openbb_terminal.config_terminal import theme
|
|
from openbb_terminal.config_plot import PLOT_DPI
|
|
from openbb_terminal.decorators import check_api_key, log_start_end
|
|
from openbb_terminal.helper_funcs import (
|
|
export_data,
|
|
lambda_long_number_format,
|
|
print_rich_table,
|
|
plot_autoscale,
|
|
)
|
|
from openbb_terminal.stocks.fundamental_analysis import eodhd_model
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
@check_api_key(["API_EODHD_KEY"])
|
|
def display_fundamentals(
|
|
symbol: str,
|
|
statement: str,
|
|
limit: int = 10,
|
|
quarterly: bool = False,
|
|
ratios: bool = False,
|
|
plot: list = None,
|
|
export: str = "",
|
|
):
|
|
"""Display tickers balance sheet; income statement; cash flow statement
|
|
|
|
Parameters
|
|
----------
|
|
symbol: str
|
|
Stock ticker symbol
|
|
statement:str
|
|
Either balance or income or cashflow
|
|
limit: int
|
|
Number of results to show, by default 10
|
|
quarterly: bool
|
|
Flag to get quarterly reports, by default False
|
|
ratios: bool
|
|
Shows percentage change, by default False
|
|
plot: list
|
|
List of row labels to plot
|
|
export: str
|
|
Format to export data
|
|
"""
|
|
fundamentals = eodhd_model.get_financials(symbol, statement, quarterly, ratios)
|
|
title_str = {
|
|
"Balance_Sheet": "Balance Sheet",
|
|
"Income_Statement": "Income Statement",
|
|
"Cash_Flow": "Cash Flows",
|
|
}[statement]
|
|
|
|
if fundamentals.empty:
|
|
return
|
|
|
|
if ratios or plot:
|
|
fundamentals = fundamentals.iloc[:, :limit]
|
|
|
|
if plot:
|
|
rows_plot = len(plot)
|
|
fundamentals_plot_data = fundamentals.transpose().fillna(-1)
|
|
fundamentals_plot_data.columns = fundamentals_plot_data.columns.str.lower()
|
|
fundamentals_plot_data = fundamentals_plot_data.replace("-", "-1")
|
|
fundamentals_plot_data = fundamentals_plot_data.astype(float)
|
|
if "ttm" in list(fundamentals_plot_data.index):
|
|
fundamentals_plot_data = fundamentals_plot_data.drop(["ttm"])
|
|
fundamentals_plot_data = fundamentals_plot_data.sort_index()
|
|
|
|
if not ratios:
|
|
maximum_value = fundamentals_plot_data.max().max()
|
|
if maximum_value > 1_000_000_000_000:
|
|
df_rounded = fundamentals_plot_data / 1_000_000_000_000
|
|
denomination = "in Trillions"
|
|
elif maximum_value > 1_000_000_000:
|
|
df_rounded = fundamentals_plot_data / 1_000_000_000
|
|
denomination = "in Billions"
|
|
elif maximum_value > 1_000_000:
|
|
df_rounded = fundamentals_plot_data / 1_000_000
|
|
denomination = "in Millions"
|
|
elif maximum_value > 1_000:
|
|
df_rounded = fundamentals_plot_data / 1_000
|
|
denomination = "in Thousands"
|
|
else:
|
|
df_rounded = fundamentals_plot_data
|
|
denomination = ""
|
|
else:
|
|
df_rounded = fundamentals_plot_data
|
|
denomination = ""
|
|
|
|
if rows_plot == 1:
|
|
fig, ax = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
|
ax.bar(df_rounded.index, df_rounded[plot[0].replace("_", " ")])
|
|
title = (
|
|
f"{plot[0].replace('_', ' ').capitalize()} QoQ Growth of {symbol.upper()}"
|
|
if ratios
|
|
else f"{plot[0].replace('_', ' ').capitalize()} of {symbol.upper()} {denomination}"
|
|
)
|
|
plt.title(title)
|
|
theme.style_primary_axis(ax)
|
|
theme.visualize_output()
|
|
else:
|
|
fig, axes = plt.subplots(rows_plot)
|
|
for i in range(rows_plot):
|
|
axes[i].bar(
|
|
df_rounded.index, df_rounded[plot[i].replace("_", " ")], width=0.5
|
|
)
|
|
axes[i].set_title(f"{plot[i].replace('_', ' ')} {denomination}")
|
|
theme.style_primary_axis(axes[0])
|
|
fig.autofmt_xdate()
|
|
else:
|
|
# Snake case to english
|
|
fundamentals.index = fundamentals.index.to_series().apply(
|
|
lambda x: x.replace("_", " ").title()
|
|
)
|
|
|
|
# Readable numbers
|
|
fundamentals = fundamentals.applymap(lambda_long_number_format).fillna("-")
|
|
print_rich_table(
|
|
fundamentals.iloc[:, :limit].applymap(lambda x: "-" if x == "nan" else x),
|
|
show_index=True,
|
|
title=f"{symbol} {title_str}",
|
|
)
|
|
export_data(
|
|
export, os.path.dirname(os.path.abspath(__file__)), statement, fundamentals
|
|
)
|