Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing equity report issue #4922

Merged
merged 6 commits into from
May 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 54 additions & 69 deletions openbb_terminal/reports/templates/equity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@
"\n",
"user = get_current_user()\n",
"\n",
"cfg.theme = TerminalStyle(\n",
" user.preferences.MPL_STYLE,\n",
" user.preferences.PMF_STYLE,\n",
" user.preferences.RICH_STYLE,\n",
")"
"from openbb_terminal import theme\n",
"\n",
"#cfg.theme = TerminalStyle(\n",
"# user.preferences.MPL_STYLE,\n",
"# user.preferences.PMF_STYLE,\n",
"# user.preferences.RICH_STYLE,\n",
"#)"
]
},
{
Expand Down Expand Up @@ -97,7 +99,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 = \"IONQ\"\n",
"symbol = \"FRC\"\n",
"report_name = f\"Equity report for {symbol}\""
]
},
Expand Down Expand Up @@ -142,7 +144,7 @@
"metadata": {},
"outputs": [],
"source": [
"info = openbb.stocks.fa.data(symbol=symbol).transpose()\n",
"info = openbb.stocks.fa.overview(symbol=symbol, source=\"Finviz\").transpose()\n",
"\n",
"info\n",
"try:\n",
Expand Down Expand Up @@ -183,7 +185,7 @@
" df_quarter_earnings,\n",
" df_quarter_revenues,\n",
") = openbb.stocks.fa.est(symbol=symbol)\n",
"df_quarter_revenues"
"df_quarter_revenues.transpose()"
]
},
{
Expand All @@ -204,14 +206,14 @@
"metadata": {},
"outputs": [],
"source": [
"tables = openbb.etf.news(info[\"Short name\"][0], 5) if \"Short name\" in info else symbol\n",
"tables = openbb.stocks.news(symbol)\n",
"\n",
"for table in tables:\n",
" if not isinstance(table, pd.DataFrame):\n",
" continue\n",
"\n",
" table[0].loc[\"link\"] = (\n",
" table[0].loc[\"link\"].apply(lambda x: f'<a href=\"{x}\">{x}</a>')\n",
" table[0].loc[\"URL\"] = (\n",
" table[0].loc[\"URL\"].apply(lambda x: f'<a href=\"{x}\">{x}</a>')\n",
" )"
]
},
Expand All @@ -222,7 +224,7 @@
"metadata": {},
"outputs": [],
"source": [
"quote_data = openbb.stocks.quote([symbol])\n",
"quote_data = info[[\"Price\", \"Prev Close\", \"Change\", \"Volume\", \"52W Range\", \"Perf YTD\"]]\n",
"quote_data"
]
},
Expand All @@ -238,39 +240,21 @@
"df_institutional_shareholders"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e101e24e",
"metadata": {},
"outputs": [],
"source": [
"openbb.stocks.fa.shrs(symbol)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "51dfd9d2",
"metadata": {},
"outputs": [],
"source": [
"df_institutional_shareholders = openbb.stocks.fa.shrs(symbol)\n",
"df_institutional_shareholders.index += 1\n",
"df_institutional_shareholders"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3022130e",
"metadata": {},
"outputs": [],
"source": [
"df_sec_filings = openbb.stocks.fa.sec(symbol)[\n",
" [\"Company Name\", \"Reporting Owner\", \"Form Type\", \"Period\"]\n",
"].head(5)\n",
"df_sec_filings"
"#this command works 1/2 the time - really need to fix this - but this will catch the errors and stop it from breaking the report\n",
"try:\n",
" df_sec_filings = openbb.stocks.fa.sec(symbol)[\n",
" [\"Company Name\", \"Reporting Owner\", \"Form Type\", \"Period\", \"View\"]\n",
" ].head(5)\n",
" df_sec_filings\n",
"except:\n",
" df_sec_filings = \"Error with Nasdaq API\""
]
},
{
Expand All @@ -280,25 +264,25 @@
"metadata": {},
"outputs": [],
"source": [
"df_analyst = openbb.stocks.fa.analyst(symbol=symbol)\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",
" df_analyst[\"target\"] = df_analyst[\"target_to\"].combine_first(\n",
" df_analyst[\"target\"]\n",
" )\n",
" else:\n",
" df_analyst[\"target\"] = df_analyst[\"target\"]\n",
" df_analyst = df_analyst[[\"category\", \"analyst\", \"rating\", \"target\"]].rename(\n",
" columns={\n",
" \"category\": \"Category\",\n",
" \"analyst\": \"Analyst\",\n",
" \"rating\": \"Rating\",\n",
" \"target\": \"Price Target\",\n",
" }\n",
" )\n",
"df_analyst"
"df_analyst = openbb.stocks.fa.pt(symbol=symbol).sort_index(ascending = False)\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",
"# df_analyst[\"target\"] = df_analyst[\"target_to\"].combine_first(\n",
"# df_analyst[\"target\"]\n",
"# )\n",
"# else:\n",
"# df_analyst[\"target\"] = df_analyst[\"target\"]\n",
"# df_analyst = df_analyst[[\"category\", \"analyst\", \"rating\", \"target\"]].rename(\n",
"# columns={\n",
"# \"category\": \"Category\",\n",
"# \"analyst\": \"Analyst\",\n",
"# \"rating\": \"Rating\",\n",
"# \"target\": \"Price Target\",\n",
"# }\n",
"# )\n",
"df_analyst.head(10)"
]
},
{
Expand Down Expand Up @@ -469,7 +453,7 @@
"metadata": {},
"outputs": [],
"source": [
"similar_companies = openbb.stocks.ca.similar(symbol, source=\"Polygon\")\n",
"similar_companies = openbb.stocks.ca.similar(symbol, source=\"Finviz\")[0:5]\n",
"if similar_companies:\n",
" similar_companies.append(symbol)"
]
Expand Down Expand Up @@ -666,7 +650,7 @@
"metadata": {},
"outputs": [],
"source": [
"df = openbb.stocks.fa.pt(symbol=symbol)\n",
"df = df_analyst.copy()\n",
"avg_ratings_last_30_days = 0\n",
"days = 0\n",
"if not df.empty:\n",
Expand Down Expand Up @@ -840,6 +824,7 @@
"ticker_data_all = openbb.stocks.load(\n",
" symbol=symbol,\n",
" start_date=datetime.datetime.now() - datetime.timedelta(days=5 * 12 * 21),\n",
" verbose = False\n",
")\n",
"ticker_data_all[\"Returns\"] = ticker_data_all[\"Adj Close\"].pct_change()"
]
Expand Down Expand Up @@ -889,8 +874,8 @@
"metadata": {},
"outputs": [],
"source": [
"income_df = openbb.stocks.fa.income(symbol, source=\"FinancialModelingPrep\")\n",
"data_df = openbb.stocks.fa.data(symbol)\n",
"income_df = openbb.stocks.fa.income(symbol, source = 'FinancialModelingPrep')\n",
"data_df = openbb.stocks.fa.overview(symbol, source = 'FinancialModelingPrep')\n",
"mgmt_df = openbb.stocks.fa.mgmt(symbol)\n",
"try:\n",
" if not mgmt_df.empty:\n",
Expand Down Expand Up @@ -1029,7 +1014,7 @@
"<style>\n",
"@font-face {{\n",
" font-family: \"Fira Code\";\n",
" src: url(\"{(OpenBBFigure.plotlyjs_path.parent.parent / \"web\"/\"css\").as_uri()}/fonts/FiraCode-Regular.ttf\") format(\"truetype\");\n",
" src: url(\"{(OpenBBFigure.plotlyjs_path.parent.parent / \"web\"/\"css\").as_uri()}/fonts/Consolas-Regular.ttf\") format(\"truetype\");\n",
" font-weight: 400 700;\n",
" font-stretch: 50%;\n",
"}}\n",
Expand Down Expand Up @@ -1162,12 +1147,12 @@
" htmlcode += widgets.row([widgets.h(3, \"Analyst Ratings\") + df_analyst.to_html()])\n",
"except:\n",
" pass\n",
"try:\n",
" htmlcode += widgets.row(\n",
" [widgets.h(3, \"Analyst Recommendations\") + df_rating.to_html()]\n",
" )\n",
"except:\n",
" pass\n",
"#try:\n",
"# htmlcode += widgets.row(\n",
"# [widgets.h(3, \"Analyst Recommendations\") + df_rating.to_html()]\n",
"# )\n",
"#except:\n",
"# pass\n",
"\n",
"body += widgets.add_tab(\"Analyst Opinions\", htmlcode)\n",
"\n",
Expand Down Expand Up @@ -1405,7 +1390,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
"version": "3.10.8"
},
"vscode": {
"interpreter": {
Expand Down