mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 04:52:07 +00:00
reports fixing - equity / etf (#4814)
* fixing some equity edge cases on reports * back to msft * adding a etf tab
This commit is contained in:
85
openbb_terminal/reports/templates/equity.ipynb
vendored
85
openbb_terminal/reports/templates/equity.ipynb
vendored
@@ -97,7 +97,7 @@
|
||||
"source": [
|
||||
"# Parameters that will be replaced when calling this notebook\n",
|
||||
"# Do not leave parameters blank as notebook will not run otherwise\n",
|
||||
"symbol = \"msft\"\n",
|
||||
"symbol = \"IONQ\"\n",
|
||||
"report_name = f\"Equity report for {symbol}\""
|
||||
]
|
||||
},
|
||||
@@ -142,17 +142,25 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"info = openbb.stocks.fa.info(symbol=symbol).transpose()\n",
|
||||
"info = openbb.stocks.fa.data(symbol=symbol).transpose()\n",
|
||||
"\n",
|
||||
"long_summary = \"Long business summary\"\n",
|
||||
"long_name = \"Long name\"\n",
|
||||
"info \n",
|
||||
"try:\n",
|
||||
" company_name = info['Company'][0]\n",
|
||||
"except:\n",
|
||||
" company_name = \"N/A\"\n",
|
||||
"try:\n",
|
||||
" company_sector = info['Sector'][0]\n",
|
||||
"except:\n",
|
||||
" company_sector = \"N/A\"\n",
|
||||
"\n",
|
||||
"if long_summary in info and info[long_summary][0] != \"NA\":\n",
|
||||
" overview = info[long_summary][0]\n",
|
||||
"elif long_name in info:\n",
|
||||
" overview = info[long_name][0]\n",
|
||||
"else:\n",
|
||||
" overview = \"\""
|
||||
"try: \n",
|
||||
" company_industry = info['Industry'][0]\n",
|
||||
"except:\n",
|
||||
" company_industry = \"N/A\"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"overview = [company_name, company_sector, company_industry]\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -273,7 +281,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"df_analyst = openbb.stocks.fa.analyst(symbol=symbol)\n",
|
||||
"\n",
|
||||
"print(df_analyst)\n",
|
||||
"if not df_analyst.empty:\n",
|
||||
" if \"target\" in df_analyst.columns:\n",
|
||||
" if \"target_to\" in df_analyst.columns:\n",
|
||||
@@ -281,7 +289,7 @@
|
||||
" df_analyst[\"target\"]\n",
|
||||
" )\n",
|
||||
" else:\n",
|
||||
" df_analyst[\"target\"] = df_analyst[\"target_to\"]\n",
|
||||
" df_analyst[\"target\"] = df_analyst[\"target\"]\n",
|
||||
" df_analyst = df_analyst[[\"category\", \"analyst\", \"rating\", \"target\"]].rename(\n",
|
||||
" columns={\n",
|
||||
" \"category\": \"Category\",\n",
|
||||
@@ -779,8 +787,11 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"df_sentiment_finbrain = openbb.stocks.ca.sentiment(symbols=[symbol])\n",
|
||||
"finbrain_sentiment_val = float(df_sentiment_finbrain.values[-1][0])"
|
||||
"try:\n",
|
||||
" df_sentiment_finbrain = openbb.stocks.ca.sentiment(symbols=[symbol])\n",
|
||||
" finbrain_sentiment_val = float(df_sentiment_finbrain.values[-1][0])\n",
|
||||
"except Exception as e:\n",
|
||||
" finbrain_sentiment_val = \"N/A\""
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -881,17 +892,21 @@
|
||||
"income_df = openbb.stocks.fa.income(symbol, source=\"FinancialModelingPrep\")\n",
|
||||
"data_df = openbb.stocks.fa.data(symbol)\n",
|
||||
"mgmt_df = openbb.stocks.fa.mgmt(symbol)\n",
|
||||
"if not mgmt_df.empty:\n",
|
||||
" mgmt_df[\"Info\"] = mgmt_df[\"Info\"].apply(lambda x: f'<a href=\"{x}\">{x}</a>')\n",
|
||||
" mgmt_df[\"Insider Activity\"] = mgmt_df[\"Insider Activity\"].apply(\n",
|
||||
" lambda x: f'<a href=\"{x}\">{x}</a>' if x != \"-\" else x\n",
|
||||
" )\n",
|
||||
"try:\n",
|
||||
" if not mgmt_df.empty:\n",
|
||||
" mgmt_df[\"Info\"] = mgmt_df[\"Info\"].apply(lambda x: f'<a href=\"{x}\">{x}</a>')\n",
|
||||
" mgmt_df[\"Insider Activity\"] = mgmt_df[\"Insider Activity\"].apply(\n",
|
||||
" lambda x: f'<a href=\"{x}\">{x}</a>' if x != \"-\" else x\n",
|
||||
" )\n",
|
||||
"except:\n",
|
||||
" pass\n",
|
||||
"try:\n",
|
||||
" hist_dcf = openbb.stocks.fa.dcfc(symbol)\n",
|
||||
"except:\n",
|
||||
" pass\n",
|
||||
"\n",
|
||||
"enterprise_df = openbb.stocks.fa.enterprise(symbol)\n",
|
||||
"score = openbb.stocks.fa.score(symbol, years=10)"
|
||||
"score = openbb.stocks.fa.score(symbol, years=10)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1083,15 +1098,18 @@
|
||||
" )\n",
|
||||
"except:\n",
|
||||
" pass\n",
|
||||
"htmlcode += widgets.kpi(\n",
|
||||
" [-0.1, 0.1],\n",
|
||||
" [\n",
|
||||
" \"Last FinBrain sentiment is bearish\",\n",
|
||||
" \" Last FinBrain sentiment is neutral\",\n",
|
||||
" \"Last FinBrain sentiment is bullish\",\n",
|
||||
" ],\n",
|
||||
" finbrain_sentiment_val,\n",
|
||||
")\n",
|
||||
"try:\n",
|
||||
" htmlcode += widgets.kpi(\n",
|
||||
" [-0.1, 0.1],\n",
|
||||
" [\n",
|
||||
" \"Last FinBrain sentiment is bearish\",\n",
|
||||
" \" Last FinBrain sentiment is neutral\",\n",
|
||||
" \"Last FinBrain sentiment is bullish\",\n",
|
||||
" ],\n",
|
||||
" finbrain_sentiment_val,\n",
|
||||
" )\n",
|
||||
"except:\n",
|
||||
" pass\n",
|
||||
"if score and score[\"Total Score\"]:\n",
|
||||
" htmlcode += widgets.kpi(\n",
|
||||
" [25, 75],\n",
|
||||
@@ -1106,7 +1124,12 @@
|
||||
"\n",
|
||||
"htmlcode = \"\"\n",
|
||||
"if overview:\n",
|
||||
" htmlcode += widgets.row([widgets.h(3, \"Description\") + widgets.p(overview)])\n",
|
||||
" titles = [\"Company\", \"Sector\", \"Industry\"]\n",
|
||||
" m = 0\n",
|
||||
" for x in overview:\n",
|
||||
" print(x)\n",
|
||||
" htmlcode += widgets.row([widgets.h(3, titles[m]) + widgets.p(x)])\n",
|
||||
" m += 1\n",
|
||||
"htmlcode += widgets.row([widgets.h(3, \"Price Chart\") + (price_chart or \"\")])\n",
|
||||
"\n",
|
||||
"try:\n",
|
||||
@@ -1382,7 +1405,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.9.13"
|
||||
"version": "3.10.5"
|
||||
},
|
||||
"vscode": {
|
||||
"interpreter": {
|
||||
|
||||
149
openbb_terminal/reports/templates/etf.ipynb
vendored
149
openbb_terminal/reports/templates/etf.ipynb
vendored
@@ -25,6 +25,7 @@
|
||||
"from openbb_terminal.core.config.paths import REPOSITORY_DIRECTORY\n",
|
||||
"from openbb_terminal import OpenBBFigure, theme\n",
|
||||
"from openbb_terminal.helper_classes import TerminalStyle\n",
|
||||
"from openbb_terminal.core.plots.plotly_ta.ta_class import PlotlyTA\n",
|
||||
"\n",
|
||||
"warnings.filterwarnings(\"ignore\")"
|
||||
]
|
||||
@@ -94,7 +95,7 @@
|
||||
"source": [
|
||||
"# Parameters that will be replaced when calling this notebook\n",
|
||||
"# Do not leave parameters blank as notebook will not run otherwise\n",
|
||||
"symbol = \"VTI\"\n",
|
||||
"symbol = \"GLD\"\n",
|
||||
"report_name = \"Equity Report for VTI\""
|
||||
]
|
||||
},
|
||||
@@ -269,6 +270,131 @@
|
||||
"holdings"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "b60ebf25",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"indicators = dict(\n",
|
||||
" ema=dict(length=[50]),\n",
|
||||
" sma=dict(length=[50]),\n",
|
||||
" wma=dict(length=[50]),\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"ma_chart = PlotlyTA.plot(ticker_data, indicators, symbol, candles=False, volume=False)\n",
|
||||
"\n",
|
||||
"if ma_chart:\n",
|
||||
" ma_chart = ma_chart.show(external=True)\n",
|
||||
" ma_chart = ma_chart.to_html()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "fa02a874",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"macd_chart = openbb.ta.macd_chart(\n",
|
||||
" ticker_data[\"Close\"], symbol=symbol, external_axes=True\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"if macd_chart:\n",
|
||||
" macd_chart = macd_chart.to_html()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "de3d59c7",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"cci_chart = openbb.ta.cci_chart(ticker_data, symbol=symbol, external_axes=True)\n",
|
||||
"\n",
|
||||
"if cci_chart:\n",
|
||||
" cci_chart = cci_chart.to_html()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "44326981",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"stoch_chart = openbb.ta.stoch_chart(ticker_data, symbol=symbol, external_axes=True)\n",
|
||||
"\n",
|
||||
"if stoch_chart:\n",
|
||||
" stoch_chart = stoch_chart.to_html()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "3e171fe5",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"adx_chart = openbb.ta.adx_chart(ticker_data, symbol=symbol, external_axes=True)\n",
|
||||
"\n",
|
||||
"if adx_chart:\n",
|
||||
" adx_chart = adx_chart.to_html()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "fc1a5418",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"bbands_chart = openbb.ta.bbands_chart(ticker_data, symbol=symbol, external_axes=True)\n",
|
||||
"\n",
|
||||
"if bbands_chart:\n",
|
||||
" bbands_chart = bbands_chart.to_html()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "d4be9f55",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ad_chart = openbb.ta.ad_chart(ticker_data, symbol=symbol, external_axes=True)\n",
|
||||
"\n",
|
||||
"if ad_chart:\n",
|
||||
" ad_chart = ad_chart.to_html()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "4d29aafa",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ta_rsi = openbb.ta.rsi_chart(ticker_data[\"Close\"], external_axes=True)\n",
|
||||
"\n",
|
||||
"if ta_rsi:\n",
|
||||
" ta_rsi = ta_rsi.to_html()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "e539e995",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"df = openbb.ta.rsi(ticker_data[\"Close\"])\n",
|
||||
"rsi_value = round(df.values[-1][0], 2)\n",
|
||||
"rsi_value"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "ac501a32-124d-4d21-aae1-a8d147bb1071",
|
||||
@@ -313,7 +439,12 @@
|
||||
" f\"<b>ETF RESEARCH REPORT:</b> {ticker.upper()}\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"body += widgets.tablinks([\"SUMMARY\"])\n",
|
||||
"body += widgets.tablinks(\n",
|
||||
" [\n",
|
||||
" \"SUMMARY\",\n",
|
||||
" \"Technical Analysis\",\n",
|
||||
" ]\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"htmlcode = widgets.h(3, \"Summary\")\n",
|
||||
"# htmlcode += widgets.p(info)\n",
|
||||
@@ -329,10 +460,22 @@
|
||||
"\n",
|
||||
"body += widgets.add_tab(\"SUMMARY\", htmlcode)\n",
|
||||
"\n",
|
||||
"htmlcode = widgets.row([widgets.h(3, f\"Moving Averages for {symbol}\") + ma_chart])\n",
|
||||
"htmlcode += widgets.row([macd_chart or \"\"])\n",
|
||||
"htmlcode += widgets.row([ta_rsi or \"\"])\n",
|
||||
"htmlcode += widgets.row([stoch_chart or \"\"])\n",
|
||||
"htmlcode += widgets.row([cci_chart or \"\"])\n",
|
||||
"htmlcode += widgets.row([ad_chart or \"\"])\n",
|
||||
"htmlcode += widgets.row([bbands_chart or \"\"])\n",
|
||||
"htmlcode += widgets.row([adx_chart or \"\"])\n",
|
||||
"body += widgets.add_tab(\"Technical Analysis\", htmlcode)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"body += widgets.tab_clickable_and_save_evt()\n",
|
||||
"\n",
|
||||
"report = widgets.html_report(title=report_name, stylesheet=stylesheet, body=body)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# to save the results\n",
|
||||
"with open(report_name + \".html\", \"w\", encoding=\"utf-8\") as fh:\n",
|
||||
" fh.write(report)"
|
||||
@@ -356,7 +499,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.9"
|
||||
"version": "3.10.5"
|
||||
},
|
||||
"vscode": {
|
||||
"interpreter": {
|
||||
|
||||
@@ -41,6 +41,8 @@ def get_score(symbol: str, years: int) -> Dict[str, Any]:
|
||||
|
||||
current_user = get_current_user()
|
||||
|
||||
scores = {}
|
||||
|
||||
try:
|
||||
valstock = valinvest.Fundamental(
|
||||
symbol, current_user.credentials.API_KEY_FINANCIALMODELINGPREP
|
||||
|
||||
Reference in New Issue
Block a user