mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-30 05:52:23 +00:00
* switch auto print_help on exits * display help when home called from home directory * change in test to expect help cmd * change in test to expect help cmd * sets autoexithelp flag on conftest * supress help string print on quit * adapt tests to expect help * adds help on 3 tests missing * run black * respect literal bool type * second attemp to respect literal bool Co-authored-by: minhhoang1023 <40023817+minhhoang1023@users.noreply.github.com>
827 lines
24 KiB
Plaintext
Vendored
827 lines
24 KiB
Plaintext
Vendored
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "70ba2c8a",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Notebook setup"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "driven-billion",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import os\n",
|
|
"import io\n",
|
|
"import warnings\n",
|
|
"import datetime\n",
|
|
"import numpy as np\n",
|
|
"import base64\n",
|
|
"\n",
|
|
"import matplotlib.pyplot as plt\n",
|
|
"import matplotlib_inline.backend_inline\n",
|
|
"\n",
|
|
"# import sys\n",
|
|
"# sys.path.append('../../')\n",
|
|
"\n",
|
|
"from openbb_terminal import api as openbb\n",
|
|
"from openbb_terminal.helper_classes import TerminalStyle\n",
|
|
"\n",
|
|
"%matplotlib inline\n",
|
|
"matplotlib_inline.backend_inline.set_matplotlib_formats(\"svg\")\n",
|
|
"warnings.filterwarnings(\"ignore\")\n",
|
|
"\n",
|
|
"# Detect if prediction capabilities are present. If they are not, disable prediction in the rest of the script\n",
|
|
"# so that the report can still be generated without prediction results.\n",
|
|
"predictions = True\n",
|
|
"try:\n",
|
|
" openbb.stocks.pred.models\n",
|
|
"except Exception as e:\n",
|
|
" predictions = False"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "c3fe7db5-ec6a-42cf-9e66-52dc1de22370",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"try:\n",
|
|
" theme = TerminalStyle(\"light\", \"light\", \"light\")\n",
|
|
"except:\n",
|
|
" pass\n",
|
|
"stylesheet = openbb.widgets.html_report_stylesheet()\n",
|
|
"with open(\"./openbb_terminal/reports/OpenBB_reports_logo.png\", \"rb\") as image_file:\n",
|
|
" openbb_image_encoded = base64.b64encode(image_file.read())"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "807fda4e",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Select Ticker"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "intended-sherman",
|
|
"metadata": {
|
|
"tags": [
|
|
"parameters"
|
|
]
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Parameters that will be replaced when calling this notebook\n",
|
|
"ticker = \"TSLA\"\n",
|
|
"report_name = \"\""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "a441ddbc-d75b-4a18-84d4-e01b677674d3",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"if \".\" in ticker:\n",
|
|
" import sys\n",
|
|
"\n",
|
|
" sys.exit(0)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "1be26dae-cafe-4a22-80aa-eff296fc1a9b",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"ticker_data = openbb.stocks.load(\n",
|
|
" ticker, start=datetime.datetime.now() - datetime.timedelta(days=4 * 30)\n",
|
|
")\n",
|
|
"ticker_data = openbb.stocks.process_candle(ticker_data)\n",
|
|
"\n",
|
|
"author = \"Didier Rodrigues Lopes\"\n",
|
|
"report_title = f\"INVESTMENT RESEARCH REPORT ON {ticker.upper()}\"\n",
|
|
"report_date = datetime.datetime.now().strftime(\"%d %B, %Y\")\n",
|
|
"report_time = datetime.datetime.now().strftime(\"%H:%M\")\n",
|
|
"report_timezone = datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo\n",
|
|
"report_title, report_date, report_time, report_timezone"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "e3b15d6f-dc9e-4f97-aa07-37d949a4e4bb",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"info = openbb.stocks.fa.models.yahoo_finance.get_info(ticker=ticker).transpose()\n",
|
|
"\n",
|
|
"if info[\"Long business summary\"][0] != \"NA\":\n",
|
|
" overview = info[\"Long business summary\"][0]\n",
|
|
"else:\n",
|
|
" overview = info[\"Long name\"][0]\n",
|
|
"overview"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "f8a0d747",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Data"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "aca4b6ef",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"(\n",
|
|
" df_year_estimates,\n",
|
|
" df_quarter_earnings,\n",
|
|
" df_quarter_revenues,\n",
|
|
") = openbb.stocks.dd.models.business_insider.get_estimates(ticker)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "c0f0a1ca",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"display_year = sorted(df_year_estimates.columns.tolist())[:3]\n",
|
|
"df_year_estimates = df_year_estimates[display_year].head(5)\n",
|
|
"df_year_estimates"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "fde46353",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"df_quarter_earnings"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "51dfd9d2",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"df_quarter_revenues"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "3022130e",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"df_sec_filings = openbb.stocks.dd.models.marketwatch.get_sec_filings(ticker)[\n",
|
|
" [\"Type\", \"Category\", \"Link\"]\n",
|
|
"].head(5)\n",
|
|
"df_sec_filings"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "4662b1ac",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"df_analyst = openbb.stocks.dd.models.finviz.get_analyst_data(ticker)\n",
|
|
"df_analyst[\"target_to\"] = df_analyst[\"target_to\"].combine_first(df_analyst[\"target\"])\n",
|
|
"df_analyst = df_analyst[[\"category\", \"analyst\", \"rating\", \"target_to\"]].rename(\n",
|
|
" columns={\n",
|
|
" \"category\": \"Category\",\n",
|
|
" \"analyst\": \"Analyst\",\n",
|
|
" \"rating\": \"Rating\",\n",
|
|
" \"target_to\": \"Price Target\",\n",
|
|
" }\n",
|
|
")\n",
|
|
"df_analyst"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "324e2d4b-b2f6-4da3-bac4-ef785ad4e436",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"fig, ax1 = plt.subplots(figsize=(11, 5), dpi=150)\n",
|
|
"ax2 = ax1.twinx()\n",
|
|
"openbb.stocks.dps.spos(\n",
|
|
" ticker,\n",
|
|
" num=84,\n",
|
|
" raw=False,\n",
|
|
" export=\"\",\n",
|
|
" external_axes=[ax1, ax2],\n",
|
|
")\n",
|
|
"fig.tight_layout()\n",
|
|
"\n",
|
|
"f = io.BytesIO()\n",
|
|
"fig.savefig(f, format=\"svg\")\n",
|
|
"net_short_position = f.getvalue().decode(\"utf-8\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "ac0bfbda-e4b8-4b3b-b8e7-c02639fdb971",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"fig, (ax1, ax2) = plt.subplots(nrows=2, ncols=1, figsize=(11, 5), dpi=150)\n",
|
|
"openbb.stocks.dps.dpotc(\n",
|
|
" ticker,\n",
|
|
" external_axes=[ax1, ax2],\n",
|
|
")\n",
|
|
"fig.tight_layout()\n",
|
|
"\n",
|
|
"f = io.BytesIO()\n",
|
|
"fig.savefig(f, format=\"svg\")\n",
|
|
"dark_pools = f.getvalue().decode(\"utf-8\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "e40a2b8f-8076-4220-89ad-388def38971c",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"fig, ax = plt.subplots(figsize=(11, 5), dpi=150)\n",
|
|
"openbb.stocks.dps.volexch(\n",
|
|
" ticker,\n",
|
|
" external_axes=[ax],\n",
|
|
")\n",
|
|
"fig.tight_layout()\n",
|
|
"\n",
|
|
"f = io.BytesIO()\n",
|
|
"fig.savefig(f, format=\"svg\")\n",
|
|
"volexch = f.getvalue().decode(\"utf-8\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "d8bb53c1-147e-4342-af61-0d0a9cc56e59",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"fig, (ax1, ax2) = plt.subplots(nrows=2, ncols=1, figsize=(11, 5), dpi=150)\n",
|
|
"ax3 = ax1.twinx()\n",
|
|
"openbb.stocks.dps.psi_sg(\n",
|
|
" ticker,\n",
|
|
" external_axes=[ax1, ax2, ax3],\n",
|
|
")\n",
|
|
"fig.tight_layout()\n",
|
|
"\n",
|
|
"f = io.BytesIO()\n",
|
|
"fig.savefig(f, format=\"svg\")\n",
|
|
"price_vs_short_interest = f.getvalue().decode(\"utf-8\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "394668e1-1158-4a2b-8a38-04c72a6abdd6",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"fig, (candles, volume) = plt.subplots(nrows=2, ncols=1, figsize=(11, 5), dpi=150)\n",
|
|
"openbb.stocks.candle(\n",
|
|
" s_ticker=ticker,\n",
|
|
" df_stock=ticker_data,\n",
|
|
" use_matplotlib=True,\n",
|
|
" external_axes=[candles, volume],\n",
|
|
")\n",
|
|
"candles.set_xticklabels(\"\")\n",
|
|
"fig.tight_layout()\n",
|
|
"\n",
|
|
"f = io.BytesIO()\n",
|
|
"fig.savefig(f, format=\"svg\")\n",
|
|
"price_chart = f.getvalue().decode(\"utf-8\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "900686a3",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"fig, ax = plt.subplots(figsize=(11, 3), dpi=150)\n",
|
|
"openbb.stocks.dd.pt(\n",
|
|
" ticker=ticker,\n",
|
|
" start=\"2022-01-01\",\n",
|
|
" interval=\"1440min\",\n",
|
|
" stock=ticker_data,\n",
|
|
" num=10,\n",
|
|
" raw=False,\n",
|
|
" external_axes=[ax],\n",
|
|
")\n",
|
|
"fig.tight_layout()\n",
|
|
"f = io.BytesIO()\n",
|
|
"fig.savefig(f, format=\"svg\")\n",
|
|
"price_target_chart = f.getvalue().decode(\"utf-8\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "61d62e1a-199e-481d-b57d-38ab486951be",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"df = openbb.stocks.dd.models.business_insider.get_price_target_from_analysts(ticker)\n",
|
|
"avg_ratings_last_30_days = round(\n",
|
|
" np.mean(\n",
|
|
" df[datetime.datetime.now() - datetime.timedelta(days=30) :][\n",
|
|
" \"Price Target\"\n",
|
|
" ].values\n",
|
|
" ),\n",
|
|
" 2,\n",
|
|
")\n",
|
|
"last_price = round(ticker_data[\"Close\"][-1], 2)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "f3733ff2",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"fig, ax = plt.subplots(figsize=(11, 3), dpi=150)\n",
|
|
"openbb.stocks.dd.rot(\n",
|
|
" ticker=ticker,\n",
|
|
" num=10,\n",
|
|
" raw=False,\n",
|
|
" export=\"\",\n",
|
|
" external_axes=[ax],\n",
|
|
")\n",
|
|
"fig.tight_layout()\n",
|
|
"f = io.BytesIO()\n",
|
|
"fig.savefig(f, format=\"svg\")\n",
|
|
"ratings_over_time_chart = f.getvalue().decode(\"utf-8\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "924f8042-e58a-449c-91a3-7923158ff714",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"fig, (ax1, ax2) = plt.subplots(nrows=2, ncols=1, figsize=(11, 3), dpi=150)\n",
|
|
"openbb.stocks.ta.rsi(ticker_data[\"Close\"], external_axes=[ax1, ax2])\n",
|
|
"fig.tight_layout()\n",
|
|
"f = io.BytesIO()\n",
|
|
"fig.savefig(f, format=\"svg\")\n",
|
|
"ta_rsi = f.getvalue().decode(\"utf-8\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "953a340e-7ea1-4aa3-ae1d-872683dced41",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"df = openbb.stocks.ta.models.momentum.rsi(ticker_data[\"Close\"])\n",
|
|
"rsi_value = round(df.values[-1][0], 2)\n",
|
|
"rsi_value"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "dce71711-20b3-4c69-af52-e0f9a69991f8",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from sklearn.linear_model import LinearRegression\n",
|
|
"\n",
|
|
"model = LinearRegression().fit(\n",
|
|
" np.array(range(len(ticker_data[\"Close\"][-30:].index))).reshape(-1, 1),\n",
|
|
" ticker_data[\"Close\"][-30:].values,\n",
|
|
")\n",
|
|
"regression_slope = round(model.coef_[0], 2)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "6272e34b-9511-4b48-9eea-ea882ce9846a",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"df_insider = pd.DataFrame.from_dict(\n",
|
|
" openbb.stocks.ins.models.finviz.get_last_insider_activity(ticker)\n",
|
|
").head(10)\n",
|
|
"df_insider[\"Val ($)\"] = df_insider[\"Value ($)\"].replace({\",\": \"\"}, regex=True)\n",
|
|
"df_insider[\"Trade\"] = df_insider.apply(\n",
|
|
" lambda row: (-1 * float(row[\"Val ($)\"]))\n",
|
|
" if row[\"Transaction\"] == \"Sale\"\n",
|
|
" else (float(row[\"Val ($)\"]) if row[\"Transaction\"] == \"Buy\" else 0),\n",
|
|
" axis=1,\n",
|
|
")\n",
|
|
"last_10_insider_trading = round(sum(df_insider[\"Trade\"]) / 1_000_000, 2)\n",
|
|
"df_insider = df_insider.drop(columns=[\"Val ($)\", \"Trade\"])\n",
|
|
"df_insider"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "29254666-58c6-4686-87e6-2635ad8387e2",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"fig, ax = plt.subplots(figsize=(11, 3), dpi=150)\n",
|
|
"openbb.stocks.ba.headlines(ticker, external_axes=[ax])\n",
|
|
"fig.tight_layout()\n",
|
|
"f = io.BytesIO()\n",
|
|
"fig.savefig(f, format=\"svg\")\n",
|
|
"finbrain_sentiment = f.getvalue().decode(\"utf-8\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "b8251b47-8ecc-47be-83f3-d9f108596898",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"df_sentiment_finbrain = openbb.stocks.ba.models.finbrain.get_sentiment(ticker)\n",
|
|
"finbrain_sentiment_val = float(df_sentiment_finbrain.values[-1][0])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "6fe6e513-d568-41b4-8aa0-37cc578c9dc3",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"(\n",
|
|
" watchlist_count,\n",
|
|
" n_cases,\n",
|
|
" n_bull,\n",
|
|
" n_bear,\n",
|
|
") = openbb.stocks.ba.models.stocktwits.get_bullbear(ticker)\n",
|
|
"stocktwits_sentiment = f\"Watchlist count: {watchlist_count}</br>\"\n",
|
|
"if n_cases > 0:\n",
|
|
" stocktwits_sentiment += f\"\\nLast {n_cases} sentiment messages:</br>\"\n",
|
|
" stocktwits_sentiment += f\"Bullish {round(100*n_bull/n_cases, 2)}%</br>\"\n",
|
|
" stocktwits_sentiment += f\"Bearish {round(100*n_bear/n_cases, 2)}%\"\n",
|
|
"else:\n",
|
|
" stocktwits_sentiment += \"No messages found\""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "bfb75909-b877-4b3a-82a7-21ce174a7bb4",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"fig, (ax1, ax2) = plt.subplots(nrows=2, ncols=1, figsize=(11, 5), dpi=150)\n",
|
|
"openbb.stocks.ba.snews(ticker, external_axes=[ax1, ax2])\n",
|
|
"fig.tight_layout()\n",
|
|
"f = io.BytesIO()\n",
|
|
"fig.savefig(f, format=\"svg\")\n",
|
|
"snews = f.getvalue().decode(\"utf-8\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "329c9e1b-e1de-4836-91fd-656cc87f7111",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"ticker_data_all = openbb.stocks.load(\n",
|
|
" ticker, start=datetime.datetime.now() - datetime.timedelta(days=5 * 12 * 21)\n",
|
|
")\n",
|
|
"ticker_data_all[\"Returns\"] = ticker_data_all[\"Adj Close\"].pct_change()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "37743ef3-2f16-4166-bfcc-a0fe3eb959bc",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"fig, ax = plt.subplots(figsize=(11, 3), dpi=150)\n",
|
|
"openbb.stocks.qa.bw(ticker, ticker_data_all, \"Returns\", False, external_axes=[ax])\n",
|
|
"fig.tight_layout()\n",
|
|
"f = io.BytesIO()\n",
|
|
"fig.savefig(f, format=\"svg\")\n",
|
|
"bw_month = f.getvalue().decode(\"utf-8\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "16b33868-23dc-4c77-ac00-acb452da386c",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"fig, ax = plt.subplots(figsize=(11, 3), dpi=150)\n",
|
|
"openbb.stocks.qa.bw(ticker, ticker_data_all, \"Returns\", True, external_axes=[ax])\n",
|
|
"fig.tight_layout()\n",
|
|
"f = io.BytesIO()\n",
|
|
"fig.savefig(f, format=\"svg\")\n",
|
|
"bw_year = f.getvalue().decode(\"utf-8\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "c688fa89-3773-41fe-8ab8-bb6a610f2287",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"if predictions:\n",
|
|
" regression_val = round(\n",
|
|
" openbb.stocks.pred.models.regression.get_regression_model(\n",
|
|
" ticker_data_all[\"Close\"], 1, 80, 20, 1\n",
|
|
" )[0][-1],\n",
|
|
" 2,\n",
|
|
" )\n",
|
|
" regression_val"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "66e51d40-3dca-46c0-abd6-4c1f04f59732",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"if predictions:\n",
|
|
" fig, ax = plt.subplots(figsize=(11, 3), dpi=150)\n",
|
|
" openbb.stocks.pred.regression(\n",
|
|
" ticker, ticker_data_all[\"Close\"], 1, 80, 20, 1, external_axes=[ax]\n",
|
|
" )\n",
|
|
" fig.tight_layout()\n",
|
|
" f = io.BytesIO()\n",
|
|
" fig.savefig(f, format=\"svg\")\n",
|
|
" regression = f.getvalue().decode(\"utf-8\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "90e77854-0652-4f62-9c0b-89d3fda456c6",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"if predictions:\n",
|
|
" fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(11, 3), dpi=150)\n",
|
|
" openbb.stocks.pred.mc(ticker_data[\"Close\"], 30, 100, external_axes=[ax1, ax2])\n",
|
|
" fig.tight_layout()\n",
|
|
" f = io.BytesIO()\n",
|
|
" fig.savefig(f, format=\"svg\")\n",
|
|
" mc = f.getvalue().decode(\"utf-8\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "bb97c78c-4c4e-4e24-a2a1-29cdf47839c5",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"if predictions:\n",
|
|
" fig, ax = plt.subplots(figsize=(11, 3), dpi=150)\n",
|
|
" openbb.stocks.pred.regression(\n",
|
|
" ticker, ticker_data_all[\"Close\"], 1, 80, 20, 1, external_axes=[ax]\n",
|
|
" )\n",
|
|
" fig.tight_layout()\n",
|
|
" f = io.BytesIO()\n",
|
|
" fig.savefig(f, format=\"svg\")\n",
|
|
" regression = f.getvalue().decode(\"utf-8\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "ac501a32-124d-4d21-aae1-a8d147bb1071",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Render the report template to a file"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "abfe37e4-ea38-42c3-8fb5-7cceb233fb12",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"body = \"\"\n",
|
|
"\n",
|
|
"img = f'<img src=\"data:image/png;base64,{openbb_image_encoded.decode()}\" alt=\"OpenBB\" style=\"width:144px;\">'\n",
|
|
"body += openbb.widgets.header(\n",
|
|
" img,\n",
|
|
" author,\n",
|
|
" report_date,\n",
|
|
" report_time,\n",
|
|
" report_timezone,\n",
|
|
" f\"<b>INVESTMENT RESEARCH REPORT:</b> {ticker}\",\n",
|
|
")\n",
|
|
"\n",
|
|
"body += openbb.widgets.tablinks(\n",
|
|
" [\n",
|
|
" \"SUMMARY\",\n",
|
|
" \"Overview\",\n",
|
|
" \"Analyst Opinions\",\n",
|
|
" \"Fundamental Analysis\",\n",
|
|
" \"Dark Pool and Shorts\",\n",
|
|
" \"Technical Analysis\",\n",
|
|
" \"Insider Trading\",\n",
|
|
" \"Behavioural Analysis\",\n",
|
|
" \"Quantitative Analysis\",\n",
|
|
" \"Prediction Techniques\",\n",
|
|
" ]\n",
|
|
")\n",
|
|
"\n",
|
|
"htmlcode = openbb.widgets.h(3, \"KPIs\")\n",
|
|
"htmlcode += openbb.widgets.kpi(\n",
|
|
" [last_price],\n",
|
|
" [\n",
|
|
" \"Last closing price is above the average price ratings of last 30 days\",\n",
|
|
" \"Average price ratings of last 30 day is above last closing price\",\n",
|
|
" ],\n",
|
|
" avg_ratings_last_30_days,\n",
|
|
")\n",
|
|
"if predictions:\n",
|
|
" htmlcode += openbb.widgets.kpi(\n",
|
|
" [0],\n",
|
|
" [\n",
|
|
" \"Regression (dollars per market day) on last 30 market days is negative\",\n",
|
|
" \"Regression (dollars per market day) on last 30 market days is positive\",\n",
|
|
" ],\n",
|
|
" regression_slope,\n",
|
|
" )\n",
|
|
"htmlcode += openbb.widgets.kpi(\n",
|
|
" [30, 70],\n",
|
|
" [\"RSI level is oversold\", \"RSI level is normal\", \"RSI level is overbought\"],\n",
|
|
" rsi_value,\n",
|
|
")\n",
|
|
"htmlcode += openbb.widgets.kpi(\n",
|
|
" [0],\n",
|
|
" [\n",
|
|
" \"The sum of last 10 insider trading (in millions) was negative\",\n",
|
|
" \"The sum of last 10 insider trading (in millions) was positive\",\n",
|
|
" ],\n",
|
|
" last_10_insider_trading,\n",
|
|
")\n",
|
|
"htmlcode += openbb.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",
|
|
"if predictions:\n",
|
|
" htmlcode += openbb.widgets.kpi(\n",
|
|
" [0],\n",
|
|
" [\n",
|
|
" \"The regression for the next 20th market price is below closing price\",\n",
|
|
" \"The regression for the next 20th market price is above closing price\",\n",
|
|
" ],\n",
|
|
" round(regression_val - last_price, 2),\n",
|
|
" )\n",
|
|
"body += openbb.widgets.add_tab(\"SUMMARY\", htmlcode)\n",
|
|
"\n",
|
|
"htmlcode = openbb.widgets.row([price_chart])\n",
|
|
"htmlcode += openbb.widgets.row(\n",
|
|
" [openbb.widgets.h(3, \"Description\") + openbb.widgets.p(overview)]\n",
|
|
")\n",
|
|
"body += openbb.widgets.add_tab(\"Overview\", htmlcode)\n",
|
|
"\n",
|
|
"htmlcode = openbb.widgets.row([price_target_chart])\n",
|
|
"htmlcode += openbb.widgets.row([ratings_over_time_chart])\n",
|
|
"htmlcode += openbb.widgets.row([df_analyst.to_html()])\n",
|
|
"body += openbb.widgets.add_tab(\"Analyst Opinions\", htmlcode)\n",
|
|
"\n",
|
|
"htmlcode = openbb.widgets.row(\n",
|
|
" [openbb.widgets.h(3, \"Estimates\") + df_year_estimates.head().to_html()]\n",
|
|
")\n",
|
|
"htmlcode += openbb.widgets.row(\n",
|
|
" [openbb.widgets.h(3, \"Earnings\") + df_quarter_earnings.head().to_html()]\n",
|
|
")\n",
|
|
"htmlcode += openbb.widgets.row(\n",
|
|
" [openbb.widgets.h(3, \"Revenues\") + df_quarter_revenues.head().to_html()]\n",
|
|
")\n",
|
|
"htmlcode += openbb.widgets.row(\n",
|
|
" [openbb.widgets.h(3, \"SEC filings\") + df_sec_filings.head().to_html()]\n",
|
|
")\n",
|
|
"body += openbb.widgets.add_tab(\"Fundamental Analysis\", htmlcode)\n",
|
|
"\n",
|
|
"htmlcode = openbb.widgets.row([net_short_position])\n",
|
|
"htmlcode += openbb.widgets.row([price_vs_short_interest])\n",
|
|
"htmlcode += openbb.widgets.row([dark_pools])\n",
|
|
"htmlcode += openbb.widgets.row([volexch])\n",
|
|
"body += openbb.widgets.add_tab(\"Dark Pool and Shorts\", htmlcode)\n",
|
|
"\n",
|
|
"body += openbb.widgets.add_tab(\"Technical Analysis\", openbb.widgets.row([ta_rsi]))\n",
|
|
"\n",
|
|
"htmlcode = openbb.widgets.row(\n",
|
|
" [\n",
|
|
" openbb.widgets.h(3, \"Last Activity\")\n",
|
|
" + df_insider.head(10).to_html(col_space=\"75px\")\n",
|
|
" ]\n",
|
|
")\n",
|
|
"body += openbb.widgets.add_tab(\"Insider Trading\", htmlcode)\n",
|
|
"\n",
|
|
"htmlcode = openbb.widgets.row([finbrain_sentiment])\n",
|
|
"htmlcode += openbb.widgets.row([snews])\n",
|
|
"htmlcode += openbb.widgets.row(\n",
|
|
" [openbb.widgets.h(3, \"Stocktwits\") + stocktwits_sentiment]\n",
|
|
")\n",
|
|
"body += openbb.widgets.add_tab(\"Behavioural Analysis\", htmlcode)\n",
|
|
"\n",
|
|
"htmlcode = openbb.widgets.row([bw_month])\n",
|
|
"htmlcode += openbb.widgets.row([bw_year])\n",
|
|
"body += openbb.widgets.add_tab(\"Quantitative Analysis\", htmlcode)\n",
|
|
"\n",
|
|
"if predictions:\n",
|
|
" htmlcode = openbb.widgets.row([regression])\n",
|
|
" htmlcode += openbb.widgets.row([mc])\n",
|
|
"else:\n",
|
|
" htmlcode = openbb.widgets.row([\"Prediction features not enabled.\"])\n",
|
|
"body += openbb.widgets.add_tab(\"Prediction Techniques\", htmlcode)\n",
|
|
"\n",
|
|
"body += openbb.widgets.tab_clickable_evt()\n",
|
|
"\n",
|
|
"report = openbb.widgets.html_report(title=report_name, stylesheet=stylesheet, body=body)\n",
|
|
"\n",
|
|
"# to save the results\n",
|
|
"with open(report_name + \".html\", \"w\", encoding=\"utf-8\") as fh:\n",
|
|
" fh.write(report)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "e15cef06-0d10-4153-b6d3-9762be0ed1dd",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"celltoolbar": "Tags",
|
|
"interpreter": {
|
|
"hash": "81794d4967e6c3204c66dcd87b604927b115b27c00565d3d43f05ba2f3a2cb0d"
|
|
},
|
|
"kernelspec": {
|
|
"display_name": "Python 3.9.1 64-bit",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.9.1"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|