hotfix/ Include plotly.js in reports html + Improve Charts in Reports (#5126)

* include plotly.js in reports html, implement new plotly multi-legends feature

* use `ensure_backend` to `check_backend`, improve charts in reports

* requirements files

* fix files with `CRLF` line endings

* Update widget_helpers.py

* Update widget_helpers.py

* handle unsupported plotly multiple legends version error
This commit is contained in:
teh_coderer
2023-06-12 10:10:13 -04:00
committed by GitHub
parent a9da2a8216
commit 73e59804fc
24 changed files with 2379 additions and 2779 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -660,7 +660,7 @@ def display_seasonal(
y=plot_data[target],
name="Values",
line_color=next(colors),
legendgroup="Values",
legend="legend",
row=1,
col=1,
)
@@ -679,7 +679,7 @@ def display_seasonal(
y=plot_data[column[j]],
name=name[j],
line_color=next(colors) if i != 0 else theme.down_color,
legendgroup=f"{i}",
legend=f"legend{i + 2}",
row=i + 2,
col=1,
)
@@ -689,17 +689,31 @@ def display_seasonal(
y=plot_data["resid"],
name="Residuals",
line_color=next(colors),
legendgroup="Residuals",
legend="legend4",
row=4,
col=1,
)
legend_defaults = dict(
xanchor="left",
yanchor="top",
xref="paper",
yref="paper",
font=dict(size=13),
bgcolor="rgba(0, 0, 0, 0.4)",
)
fig.update_traces(selector=dict(name="Cyclic-Trend"), line_color=theme.down_color)
fig.update_traces(
selector=dict(name="Cycle component"),
line=dict(color=theme.up_color, dash="dash"),
)
fig.update_yaxes(nticks=5)
fig.update_layout(legend=dict(tracegroupgap=120, groupclick="toggleitem"))
fig.update_layout(
legend=dict(**legend_defaults),
legend2=dict(x=0.01, y=0.73, **legend_defaults),
legend3=dict(x=0.01, y=0.46, **legend_defaults),
legend4=dict(x=0.01, y=0.20, **legend_defaults),
)
# From #https: // otexts.com/fpp2/seasonal-strength.html
console.print("Time-Series Level is " + str(round(data.mean(), 2)))

View File

@@ -76,6 +76,7 @@ def display_mean_std(
x=plot_data.index,
y=plot_data[target].values,
name="Real Values",
legend="legend",
row=1,
col=1,
)
@@ -83,6 +84,7 @@ def display_mean_std(
x=plot_data.index,
y=plot_data[target + "_mean"].values,
name="Rolling Mean",
legend="legend",
row=1,
col=1,
)
@@ -90,10 +92,20 @@ def display_mean_std(
x=plot_data.index,
y=plot_data[target + "_std"].values,
name="Rolling Std",
legend="legend2",
row=2,
col=1,
)
fig.update_layout(
legend=dict(xref="paper", yref="paper"),
legend2=dict(
xanchor="left",
yanchor="top",
xref="paper",
yref="paper",
x=0.01,
y=0.44,
),
yaxis=dict(title="Values"),
yaxis2=dict(title=f"{target} Std Deviation"),
)

View File

@@ -50,7 +50,7 @@ else:
JUPYTER_NOTEBOOK = True
PLOTS_CORE_PATH = Path(__file__).parent.resolve()
PLOTLYJS_PATH = PLOTS_CORE_PATH / "assets" / "plotly-2.21.0.min.js"
PLOTLYJS_PATH = PLOTS_CORE_PATH / "assets" / "plotly-2.24.2.min.js"
BACKEND = None
@@ -183,7 +183,7 @@ class Backend(PyWry):
export_image : str, optional
Path to export image to, by default ""
"""
self.loop.run_until_complete(self.check_backend())
self.ensure_backend()
# pylint: disable=C0415
from openbb_terminal.helper_funcs import command_location
@@ -261,7 +261,7 @@ class Backend(PyWry):
theme : light or dark, optional
Theme of the table, by default "light"
"""
self.loop.run_until_complete(self.check_backend())
self.ensure_backend()
if title:
# We remove any html tags and markdown from the title
@@ -328,7 +328,7 @@ class Backend(PyWry):
height : int, optional
Height of the window, by default 800
"""
self.loop.run_until_complete(self.check_backend())
self.ensure_backend()
script = f"""
<script>
window.location.replace("{url}");
@@ -355,6 +355,13 @@ class Backend(PyWry):
if self.isatty:
super().start(debug)
def ensure_backend(self):
"""Ensure the backend is running. Ignores was never awaited errors."""
try:
self.loop.run_until_complete(self.check_backend())
except Exception: # pylint: disable=W0703
pass
async def check_backend(self):
"""Override to check if isatty."""
if self.isatty:

View File

@@ -6,7 +6,7 @@ import dotenv
from openbb_terminal.base_helpers import console
from openbb_terminal.core.config.paths import SETTINGS_ENV_FILE
from openbb_terminal.core.session.current_system import get_current_system
from openbb_terminal.core.session.current_user import get_current_user
from openbb_terminal.core.session.current_user import get_current_user, set_current_user
pywry_missing = """
[red]PyWry is not installed or missing required linux dependencies.[/]
@@ -77,6 +77,7 @@ class DummyBackend:
dotenv.set_key(SETTINGS_ENV_FILE, "PLOT_ENABLE_PYWRY", "0")
current_user.preferences.USE_INTERACTIVE_DF = False
set_current_user(current_user)
def close(self, reset: bool = False): # pylint: disable=W0613
pass

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,7 @@
"""Chart and style helpers for Plotly."""
# pylint: disable=C0302,R0902,W3301
import json
import sys
import textwrap
from datetime import datetime
from math import floor
@@ -139,8 +140,18 @@ class TerminalStyle:
if "tables" in self.plt_styles_available:
tables = self.load_json_style(self.plt_styles_available["tables"])
pio.templates["openbb_tables"] = go.layout.Template(tables)
try:
pio.templates["openbb"] = go.layout.Template(self.plotly_template)
except ValueError as err:
if "plotly.graph_objs.Layout: 'legend2'" in str(err):
console.print(
"[red]Warning: Plotly multiple legends are "
"not supported in currently installed version.[/]\n\n"
"[yellow]Please update plotly to version >= 5.15.0[/]\n"
"[green]pip install plotly --upgrade[/]"
)
sys.exit(1)
pio.templates["openbb"] = go.layout.Template(self.plotly_template)
if style in ["dark", "white"]:
pio.templates.default = f"plotly_{style}+openbb"
return
@@ -1064,17 +1075,20 @@ class OpenBBFigure(go.Figure):
)
# Set modebar style
self.update_layout( # type: ignore
newshape_line_color="gold" if theme.mapbox_style == "dark" else "#0d0887",
modebar=dict(
orientation="v",
bgcolor="#2A2A2A" if theme.mapbox_style == "dark" else "gray",
color="#FFFFFF" if theme.mapbox_style == "dark" else "black",
activecolor="#d1030d" if theme.mapbox_style == "dark" else "blue",
),
spikedistance=2,
hoverdistance=2,
)
if plots_backend().isatty:
self.update_layout( # type: ignore
newshape_line_color="gold"
if theme.mapbox_style == "dark"
else "#0d0887",
modebar=dict(
orientation="v",
bgcolor="#2A2A2A" if theme.mapbox_style == "dark" else "gray",
color="#FFFFFF" if theme.mapbox_style == "dark" else "black",
activecolor="#d1030d" if theme.mapbox_style == "dark" else "blue",
),
spikedistance=2,
hoverdistance=2,
)
if external or self._exported:
return self # type: ignore
@@ -1108,11 +1122,8 @@ class OpenBBFigure(go.Figure):
continue
pio.show(fig, *args, **kwargs)
height = 600 if not self.layout.height else self.layout.height
self.update_layout(
legend=dict(
tracegroupgap=height / 4.5,
groupclick="toggleitem",
orientation="v"
if not self.layout.legend.orientation
else self.layout.legend.orientation,
@@ -1139,7 +1150,10 @@ class OpenBBFigure(go.Figure):
# We check if daily data if the first and second time are the same
# since daily data will have the same time (2021-01-01 00:00:00)
if dateindex[-1].time() == dateindex[-2].time():
if (
not hasattr(dateindex[-1], "time")
or dateindex[-1].time() == dateindex[-2].time()
):
xhoverformat = "%Y-%m-%d"
tickformatstops = [dict(dtickrange=[None, 604_800_000], value="%Y-%m-%d")]
@@ -1365,7 +1379,6 @@ class OpenBBFigure(go.Figure):
The subplot with the figure added
"""
for trace in self.data:
trace.legendgroup = f"{row}"
if kwargs:
trace.update(**kwargs)
@@ -1389,23 +1402,30 @@ class OpenBBFigure(go.Figure):
self._xaxis_tickformatstops()
if not plots_backend().isatty and self.data[0].type != "table":
margin = self.layout.margin
L, R, B, T = margin["l"], margin["r"], margin["b"], margin["t"]
for var, max_val in zip([L, R, B, T], [60, 50, 80, 40]):
if var is not None and var > max_val:
var = max_val
for key, max_val in zip(["l", "r", "b", "t"], [60, 60, 80, 40]):
if key in self.layout.margin and (
self.layout.margin[key] is None
or (self.layout.margin[key] > max_val)
):
self.layout.margin[key] = max_val
self.layout.margin = dict(l=L, r=R, b=B, t=T, pad=0)
orientation = "v" if self.layout.legend.orientation is None else "h"
if self._multi_rows:
height = 600 if not self.layout.height else self.layout.height
self.update_layout(
legend=dict(tracegroupgap=height / 4.5, groupclick="toggleitem")
for annotation in self.select_annotations(
selector=dict(x=0, xanchor="right")
):
annotation.font.size = (
annotation.font.size - 1.8 if annotation.font.size else 10
)
for trace in self.select_traces(
lambda trace: hasattr(trace, "legend") and trace.legend is not None
):
if trace.legend in self.layout:
self.layout[trace.legend].font.size = 12
self.update_layout(
legend=dict(orientation=orientation, x=1.10, font=dict(size=12)),
legend=dict(orientation=orientation, font=dict(size=12)),
font=dict(size=14),
)
self.update_xaxes(tickfont=dict(size=13))

View File

@@ -1,108 +1,132 @@
{
"line": {
"up_color": "#00ACFF",
"down_color": "#e4003a",
"color": "#ffed00",
"width": 1.5
},
"data": {
"candlestick": [
{
"decreasing": {
"fillcolor": "#e4003a",
"line": {
"color": "#e4003a"
}
},
"increasing": {
"fillcolor": "#00ACFF",
"line": {
"color": "#00ACFF"
}
},
"type": "candlestick"
}
]
},
"layout": {
"annotationdefaults": {
"showarrow": false
},
"autotypenumbers": "strict",
"colorway": [
"#ffed00",
"#ef7d00",
"#e4003a",
"#c13246",
"#822661",
"#48277c",
"#005ca9",
"#00aaff",
"#9b30d9",
"#af005f",
"#5f00af",
"#af87ff"
],
"dragmode": "pan",
"font": {
"family": "Fira Code",
"size": 18
},
"hoverlabel": {
"align": "left"
},
"mapbox": {
"style": "dark"
},
"hovermode": "x",
"legend": {
"bgcolor": "rgba(0, 0, 0, 0)",
"x": 0.01,
"xanchor": "left",
"y": 0.99,
"yanchor": "top",
"font": {
"size": 15
}
},
"paper_bgcolor": "#000000",
"plot_bgcolor": "#000000",
"xaxis": {
"automargin": true,
"autorange": true,
"rangeslider": {
"visible": false
},
"showgrid": true,
"showline": true,
"tickfont": {
"size": 14
},
"zeroline": false,
"tick0": 1,
"title": {
"standoff": 20
},
"linecolor": "#F5EFF3",
"mirror": true,
"ticks": "outside"
},
"yaxis": {
"anchor": "x",
"automargin": true,
"fixedrange": false,
"zeroline": false,
"showgrid": true,
"showline": true,
"side": "right",
"tick0": 0.5,
"title": {
"standoff": 20
},
"gridcolor": "#283442",
"linecolor": "#F5EFF3",
"mirror": true,
"ticks": "outside"
}
}
}
{
"line": {
"up_color": "#00ACFF",
"down_color": "#e4003a",
"color": "#ffed00",
"width": 1.5
},
"data": {
"candlestick": [
{
"decreasing": {
"fillcolor": "#e4003a",
"line": {
"color": "#e4003a"
}
},
"increasing": {
"fillcolor": "#00ACFF",
"line": {
"color": "#00ACFF"
}
},
"type": "candlestick"
}
]
},
"layout": {
"annotationdefaults": {
"showarrow": false
},
"autotypenumbers": "strict",
"colorway": [
"#ffed00",
"#ef7d00",
"#e4003a",
"#c13246",
"#822661",
"#48277c",
"#005ca9",
"#00aaff",
"#9b30d9",
"#af005f",
"#5f00af",
"#af87ff"
],
"dragmode": "pan",
"font": {
"family": "Fira Code",
"size": 18
},
"hoverlabel": {
"align": "left"
},
"mapbox": {
"style": "dark"
},
"hovermode": "x",
"legend": {
"bgcolor": "rgba(0, 0, 0, 0.5)",
"x": 0.01,
"xanchor": "left",
"y": 0.99,
"yanchor": "top",
"font": {
"size": 15
}
},
"legend2": {
"bgcolor": "rgba(0, 0, 0, 0.5)",
"font": {
"size": 15
}
},
"legend3": {
"bgcolor": "rgba(0, 0, 0, 0.5)",
"font": {
"size": 15
}
},
"legend4": {
"bgcolor": "rgba(0, 0, 0, 0.5)",
"font": {
"size": 15
}
},
"legend5": {
"bgcolor": "rgba(0, 0, 0, 0.5)",
"font": {
"size": 15
}
},
"paper_bgcolor": "#000000",
"plot_bgcolor": "#000000",
"xaxis": {
"automargin": true,
"autorange": true,
"rangeslider": {
"visible": false
},
"showgrid": true,
"showline": true,
"tickfont": {
"size": 14
},
"zeroline": false,
"tick0": 1,
"title": {
"standoff": 20
},
"linecolor": "#F5EFF3",
"mirror": true,
"ticks": "outside"
},
"yaxis": {
"anchor": "x",
"automargin": true,
"fixedrange": false,
"zeroline": false,
"showgrid": true,
"showline": true,
"side": "right",
"tick0": 0.5,
"title": {
"standoff": 20
},
"gridcolor": "#283442",
"linecolor": "#F5EFF3",
"mirror": true,
"ticks": "outside"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,102 +1,102 @@
{
"data": {
"candlestick": [
{
"decreasing": {
"fillcolor": "#e4003a",
"line": {
"color": "#e4003a"
}
},
"increasing": {
"fillcolor": "#00ACFF",
"line": {
"color": "#00ACFF"
}
},
"type": "candlestick"
}
]
},
"layout": {
"annotationdefaults": {
"showarrow": false
},
"autotypenumbers": "strict",
"colorway": [
"#ffed00",
"#ef7d00",
"#e4003a",
"#c13246",
"#822661",
"#48277c",
"#005ca9",
"#00aaff",
"#9b30d9",
"#af005f",
"#5f00af",
"#af87ff"
],
"dragmode": "pan",
"font": {
"family": "Fira Code",
"size": 18
},
"hoverlabel": {
"align": "left"
},
"mapbox": {
"style": "light"
},
"hovermode": "x",
"legend": {
"bgcolor": "rgba(0, 0, 0, 0)",
"x": 0.01,
"xanchor": "left",
"y": 0.99,
"yanchor": "top",
"font": {
"size": 15
}
},
"paper_bgcolor": "white",
"plot_bgcolor": "white",
"xaxis": {
"automargin": true,
"autorange": true,
"rangeslider": {
"visible": false
},
"showgrid": true,
"showline": true,
"tickfont": {
"size": 14
},
"zeroline": false,
"tick0": 1,
"title": {
"standoff": 20
},
"linecolor": "#F5EFF3",
"mirror": true,
"ticks": "outside"
},
"yaxis": {
"anchor": "x",
"automargin": true,
"fixedrange": false,
"zeroline": false,
"showgrid": true,
"showline": true,
"side": "right",
"tick0": 0.5,
"title": {
"standoff": 20
},
"gridcolor": "#283442",
"linecolor": "#F5EFF3",
"mirror": true,
"ticks": "outside"
}
}
}
{
"data": {
"candlestick": [
{
"decreasing": {
"fillcolor": "#e4003a",
"line": {
"color": "#e4003a"
}
},
"increasing": {
"fillcolor": "#00ACFF",
"line": {
"color": "#00ACFF"
}
},
"type": "candlestick"
}
]
},
"layout": {
"annotationdefaults": {
"showarrow": false
},
"autotypenumbers": "strict",
"colorway": [
"#ffed00",
"#ef7d00",
"#e4003a",
"#c13246",
"#822661",
"#48277c",
"#005ca9",
"#00aaff",
"#9b30d9",
"#af005f",
"#5f00af",
"#af87ff"
],
"dragmode": "pan",
"font": {
"family": "Fira Code",
"size": 18
},
"hoverlabel": {
"align": "left"
},
"mapbox": {
"style": "light"
},
"hovermode": "x",
"legend": {
"bgcolor": "rgba(0, 0, 0, 0)",
"x": 0.01,
"xanchor": "left",
"y": 0.99,
"yanchor": "top",
"font": {
"size": 15
}
},
"paper_bgcolor": "white",
"plot_bgcolor": "white",
"xaxis": {
"automargin": true,
"autorange": true,
"rangeslider": {
"visible": false
},
"showgrid": true,
"showline": true,
"tickfont": {
"size": 14
},
"zeroline": false,
"tick0": 1,
"title": {
"standoff": 20
},
"linecolor": "#F5EFF3",
"mirror": true,
"ticks": "outside"
},
"yaxis": {
"anchor": "x",
"automargin": true,
"fixedrange": false,
"zeroline": false,
"showgrid": true,
"showline": true,
"side": "right",
"tick0": 0.5,
"title": {
"standoff": 20
},
"gridcolor": "#283442",
"linecolor": "#F5EFF3",
"mirror": true,
"ticks": "outside"
}
}
}

View File

@@ -213,11 +213,16 @@ def render_report(input_path: str, args_dict: Dict[str, str]):
output_path = create_output_path(input_path, parameters_dict)
parameters_dict["report_name"] = output_path
if parameters_dict:
t = Thread(
target=execute_notebook, args=(input_path, parameters_dict, output_path)
)
t.start()
t.join()
try:
t = Thread(
target=execute_notebook,
args=(input_path, parameters_dict, output_path),
daemon=True,
)
t.start()
t.join()
except KeyboardInterrupt:
console.print("[red]Execution interrupted by user.[/red]")
except Exception as e:
console.print(f"[red]Cannot execute notebook - {e}")

View File

@@ -1,6 +1,7 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"id": "70ba2c8a",
"metadata": {},
@@ -28,8 +29,7 @@
"\n",
"import openbb_terminal.config_terminal as cfg\n",
"from openbb_terminal.helper_classes import TerminalStyle\n",
"from openbb_terminal.core.config.paths import REPOSITORY_DIRECTORY\n",
"from openbb_terminal import OpenBBFigure\n",
"from openbb_terminal import OpenBBFigure, theme\n",
"\n",
"\n",
"warnings.filterwarnings(\"ignore\")\n",
@@ -68,7 +68,8 @@
" user.preferences.MPL_STYLE,\n",
" user.preferences.PMF_STYLE,\n",
" user.preferences.RICH_STYLE,\n",
")"
")\n",
"theme.apply_style(\"light\")"
]
},
{
@@ -82,6 +83,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "807fda4e",
"metadata": {},
@@ -326,6 +328,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "7f83daae",
"metadata": {},
@@ -644,6 +647,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "fcaa973d",
"metadata": {},
@@ -836,6 +840,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "48847a7f",
"metadata": {},
@@ -914,6 +919,18 @@
")\n",
"\n",
"if rolling:\n",
" rolling.update_layout(\n",
" legend=dict(\n",
" x=0.01,\n",
" y=0.99,\n",
" xanchor=\"left\",\n",
" yanchor=\"top\",\n",
" xref=\"paper\",\n",
" yref=\"paper\",\n",
" bgcolor=\"rgba(0, 0, 0, 0)\",\n",
" ),\n",
" legend2=dict(bgcolor=\"rgba(0, 0, 0, 0)\"),\n",
" )\n",
" rolling = rolling.to_html()"
]
},
@@ -938,6 +955,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "ac501a32-124d-4d21-aae1-a8d147bb1071",
"metadata": {},
@@ -952,34 +970,16 @@
"metadata": {},
"outputs": [],
"source": [
"body = f\"\"\"\n",
"<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",
" font-weight: 400 700;\n",
" font-stretch: 50%;\n",
"}}\n",
"</style>\n",
"<script src=\"/{OpenBBFigure.plotlyjs_path.as_uri()}\"></script>\n",
"\"\"\"\n",
"body = \"\"\n",
"\n",
"\n",
"img = (\n",
" str(REPOSITORY_DIRECTORY)\n",
" + \"/openbb_terminal/reports/templates/OpenBB_reports_logo.png\"\n",
")\n",
"floppy_disk_img = (\n",
" str(REPOSITORY_DIRECTORY) + \"/openbb_terminal/reports/templates/floppy-disc.png\"\n",
")\n",
"body += widgets.header(\n",
" img,\n",
" floppy_disk_img,\n",
" author,\n",
" report_date,\n",
" report_time,\n",
" report_timezone,\n",
" f\"<b>INVESTMENT RESEARCH REPORT:</b> {ticker}\",\n",
" plotly_js=True,\n",
")\n",
"\n",
"body += widgets.tablinks(\n",

View File

@@ -29,12 +29,11 @@
"\n",
"import openbb_terminal.config_terminal as cfg\n",
"from openbb_terminal.helper_funcs import get_user_timezone\n",
"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",
"\n",
"\n",
"warnings.filterwarnings(\"ignore\")"
"warnings.filterwarnings(\"ignore\")\n"
]
},
{
@@ -50,7 +49,7 @@
"set_system_variable(\"LOGGING_SUPPRESS\", True)\n",
"\n",
"# Import the OpenBB SDK\n",
"from openbb_terminal.sdk import openbb, widgets"
"from openbb_terminal.sdk import openbb, widgets\n"
]
},
{
@@ -68,7 +67,8 @@
" user.preferences.MPL_STYLE,\n",
" user.preferences.PMF_STYLE,\n",
" user.preferences.RICH_STYLE,\n",
")"
")\n",
"theme.apply_style(\"light\")\n"
]
},
{
@@ -78,7 +78,7 @@
"metadata": {},
"outputs": [],
"source": [
"stylesheet = widgets.html_report_stylesheet()"
"stylesheet = widgets.html_report_stylesheet()\n"
]
},
{
@@ -94,7 +94,7 @@
"source": [
"# Parameters that will be replaced when calling this notebook\n",
"# Do not leave parameters blank as notebook will not run otherwise\n",
"report_name = \"economy_report\""
"report_name = \"economy_report\"\n"
]
},
{
@@ -110,7 +110,7 @@
"report_date = pd.Timestamp.now(tz=user_time_zone).strftime(\"%d %B, %Y\")\n",
"report_time = pd.Timestamp.now(tz=user_time_zone).strftime(\"%H:%M\")\n",
"report_timezone = pd.Timestamp.now(tz=user_time_zone).tzinfo\n",
"report_title, report_date, report_time, report_timezone"
"report_title, report_date, report_time, report_timezone\n"
]
},
{
@@ -145,7 +145,7 @@
"futures = openbb.economy.futures()\n",
"futures.set_index(list(futures.columns[0]), inplace=True)\n",
"futures[\"%Chg\"] = futures[\"%Chg\"].apply(lambda x: float(f\"{x:.2f}\"))\n",
"futures_fig = OpenBBFigure.to_table(futures, print_index=True)"
"futures_fig = OpenBBFigure.to_table(futures, print_index=True)\n"
]
},
{
@@ -168,7 +168,7 @@
" news[\"Published\"] = pd.to_datetime(news[\"Published\"]).dt.strftime(\"%Y-%m-%d %H:%M\")\n",
" news = news.set_index(\"Published\")\n",
"except:\n",
" news = pd.DataFrame()"
" news = pd.DataFrame()\n"
]
},
{
@@ -195,8 +195,8 @@
")\n",
"subplots.update_xaxes(title_text=\"Performance (%)\", row=1, col=1)\n",
"subplots.update_xaxes(title_text=\"Change %\", row=1, col=2)\n",
"subplots.update_layout(margin=dict(l=0, r=0, t=0, b=0), yaxis=dict(side=\"left\"))\n",
"chart_0 = subplots.to_html()"
"subplots.update_layout(margin=dict(l=0, r=0, t=0, b=0), yaxis=dict(side=\"left\", nticks=15), yaxis2=dict(nticks=15))\n",
"chart_0 = subplots.to_html()\n"
]
},
{
@@ -244,7 +244,7 @@
" start_date=datetime.datetime.now().strftime(\"%Y-%m-%d\"),\n",
")\n",
"if not events_3.empty:\n",
" events_3 = OpenBBFigure.to_table(events_3.set_index(\"Date\"), print_index=True)"
" events_3 = OpenBBFigure.to_table(events_3.set_index(\"Date\"), print_index=True)\n"
]
},
{
@@ -292,7 +292,7 @@
" \"30Y\",\n",
" ]\n",
"else:\n",
" ycrv = None"
" ycrv = None\n"
]
},
{
@@ -302,7 +302,7 @@
"metadata": {},
"outputs": [],
"source": [
"openbb.economy.treasury_maturities()"
"openbb.economy.treasury_maturities()\n"
]
},
{
@@ -316,8 +316,9 @@
" 2,\n",
" 2,\n",
" vertical_spacing=0.15,\n",
" row_heights=[0.5, 0.5],\n",
" subplot_titles=(\"UST 2y-10y\", \"UST 10y-30y\", \"Nominal vs TIPS\"),\n",
" specs=[[{}, {}], [{\"colspan\": 2}, None]],\n",
" specs=[[{\"type\": \"xy\"}, {\"type\": \"xy\"}], [{\"colspan\": 2}, None]],\n",
")\n",
"openbb.economy.treasury_chart(\n",
" instruments=[\"nominal\"],\n",
@@ -343,7 +344,24 @@
" external_axes=True,\n",
").to_subplot(subplots, 2, 1)\n",
"\n",
"ust = subplots.to_html()"
"subplots.update_traces(legend=\"legend\", row=1, col=1)\n",
"subplots.update_traces(legend=\"legend2\", row=1, col=2)\n",
"subplots.update_traces(legend=\"legend3\", row=2, col=1)\n",
"defaults = dict(\n",
" xanchor=\"left\",\n",
" yanchor=\"top\",\n",
" xref=\"paper\",\n",
" yref=\"paper\",\n",
" bgcolor=\"rgba(0, 0, 0, 0)\",\n",
")\n",
"subplots.update_layout(\n",
" legend=dict(x=0.01, y=0.99, **defaults),\n",
" legend2=dict(x=0.562, y=0.99, **defaults),\n",
" legend3=dict(x=0.01, y=0.41, **defaults),\n",
")\n",
"\n",
"\n",
"ust = subplots.to_html()\n"
]
},
{
@@ -363,7 +381,7 @@
"outputs": [],
"source": [
"valuation = OpenBBFigure.to_table(openbb.economy.valuation(), print_index=False)\n",
"performance = OpenBBFigure.to_table(openbb.economy.performance(), print_index=False)"
"performance = OpenBBFigure.to_table(openbb.economy.performance(), print_index=False)\n"
]
},
{
@@ -388,7 +406,7 @@
" name=col,\n",
" )\n",
"\n",
"eqty_0 = fig.to_html()"
"eqty_0 = fig.update_layout(margin=dict(l=20, r=60), legend=dict(x=1.1)).to_html()\n"
]
},
{
@@ -413,7 +431,7 @@
" name=col,\n",
" )\n",
"\n",
"eqty_1 = fig.to_html()"
"eqty_1 = fig.update_layout(margin=dict(l=20, r=60), legend=dict(x=1.1)).to_html()\n"
]
},
{
@@ -437,7 +455,7 @@
" name=col,\n",
" )\n",
"\n",
"eqty_2 = fig.to_html()"
"eqty_2 = fig.update_layout(margin=dict(l=0, r=60), legend=dict(x=1.1)).to_html()\n"
]
},
{
@@ -462,7 +480,7 @@
" name=col,\n",
" )\n",
"\n",
"eqty_3 = fig.to_html()"
"eqty_3 = fig.update_layout(margin=dict(l=20, r=60), legend=dict(x=1.1)).to_html()\n"
]
},
{
@@ -484,7 +502,7 @@
" name=col,\n",
" )\n",
"\n",
"eqty_4 = fig.to_html()"
"eqty_4 = fig.update_layout(margin=dict(l=20, r=60), legend=dict(x=1.1)).to_html()\n"
]
},
{
@@ -518,10 +536,10 @@
" )\n",
" if bigmac:\n",
" bigmac.set_title(\"\")\n",
" bigmac = bigmac.to_html()\n",
" bigmac = bigmac.update_layout(margin=dict(l=0, r=60), legend=dict(x=1.1)).to_html()\n",
"\n",
"else:\n",
" bigmac_res = pd.DataFrame()"
" bigmac_res = pd.DataFrame()\n"
]
},
{
@@ -559,7 +577,7 @@
")\n",
"subplots.horizontal_legend()\n",
"\n",
"macro_0 = subplots.to_html()"
"macro_0 = subplots.to_html()\n"
]
},
{
@@ -595,7 +613,7 @@
"\n",
" fred_0 = fig.to_html()\n",
"else:\n",
" fred = None"
" fred = None\n"
]
},
{
@@ -614,34 +632,16 @@
"metadata": {},
"outputs": [],
"source": [
"body = f\"\"\"\n",
"<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",
" font-weight: 400 700;\n",
" font-stretch: 50%;\n",
"}}\n",
"</style>\n",
"<script src=\"/{OpenBBFigure.plotlyjs_path.as_uri()}\"></script>\n",
"\"\"\"\n",
"body = \"\"\n",
"\n",
"\n",
"img = (\n",
" str(REPOSITORY_DIRECTORY)\n",
" + \"/openbb_terminal/reports/templates/OpenBB_reports_logo.png\"\n",
")\n",
"floppy_disk_img = (\n",
" str(REPOSITORY_DIRECTORY) + \"/openbb_terminal/reports/templates/floppy-disc.png\"\n",
")\n",
"body += widgets.header(\n",
" img,\n",
" floppy_disk_img,\n",
" author,\n",
" report_date,\n",
" report_time,\n",
" report_timezone,\n",
" f\"<b>ECONOMY REPORT: Leverage multiple sources to create custom reports.</b>\",\n",
" plotly_js=True,\n",
")\n",
"\n",
"body += widgets.tablinks(\n",
@@ -737,7 +737,7 @@
"\n",
"# to save the results\n",
"with open(report_name + \".html\", \"w\", encoding=\"utf-8\") as fh:\n",
" fh.write(report)"
" fh.write(report)\n"
]
}
],
@@ -758,7 +758,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.10.11"
},
"vscode": {
"interpreter": {

View File

@@ -25,11 +25,10 @@
"\n",
"from openbb_terminal import config_terminal as cfg\n",
"from openbb_terminal.helper_classes import TerminalStyle\n",
"from openbb_terminal.core.config.paths import REPOSITORY_DIRECTORY\n",
"from openbb_terminal import OpenBBFigure\n",
"from openbb_terminal.core.plots.plotly_ta.ta_class import PlotlyTA\n",
"\n",
"warnings.filterwarnings(\"ignore\")"
"warnings.filterwarnings(\"ignore\")\n"
]
},
{
@@ -45,7 +44,7 @@
"set_system_variable(\"LOGGING_SUPPRESS\", True)\n",
"\n",
"# Import the OpenBB SDK\n",
"from openbb_terminal.sdk import openbb, widgets"
"from openbb_terminal.sdk import openbb, widgets\n"
]
},
{
@@ -61,11 +60,12 @@
"\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",
"# )"
"cfg.theme = TerminalStyle(\n",
" user.preferences.MPL_STYLE,\n",
" user.preferences.PMF_STYLE,\n",
" user.preferences.RICH_STYLE,\n",
")\n",
"theme.apply_style(\"light\")\n"
]
},
{
@@ -75,7 +75,7 @@
"metadata": {},
"outputs": [],
"source": [
"stylesheet = widgets.html_report_stylesheet()"
"stylesheet = widgets.html_report_stylesheet()\n"
]
},
{
@@ -101,7 +101,7 @@
"# 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",
"report_name = f\"Equity report for {symbol}\""
"report_name = f\"Equity report for {symbol}\"\n"
]
},
{
@@ -115,7 +115,7 @@
" import sys\n",
"\n",
" sys.exit(0)\n",
"symbol = symbol.upper()"
"symbol = symbol.upper()\n"
]
},
{
@@ -135,7 +135,7 @@
"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"
"report_title, report_date, report_time, report_timezone\n"
]
},
{
@@ -163,7 +163,7 @@
" company_industry = \"N/A\"\n",
"\n",
"\n",
"overview = [company_name, company_sector, company_industry]"
"overview = [company_name, company_sector, company_industry]\n"
]
},
{
@@ -187,7 +187,7 @@
" df_quarter_earnings,\n",
" df_quarter_revenues,\n",
") = openbb.stocks.fa.est(symbol=symbol)\n",
"df_quarter_revenues.transpose()"
"df_quarter_revenues.transpose()\n"
]
},
{
@@ -198,7 +198,7 @@
"outputs": [],
"source": [
"display_year = sorted(df_year_estimates.columns.tolist())[:3]\n",
"df_year_estimates = df_year_estimates[display_year].head(5)"
"df_year_estimates = df_year_estimates[display_year].head(5)\n"
]
},
{
@@ -214,7 +214,7 @@
" if not isinstance(table, pd.DataFrame):\n",
" continue\n",
"\n",
" table[0].loc[\"URL\"] = table[0].loc[\"URL\"].apply(lambda x: f'<a href=\"{x}\">{x}</a>')"
" table[0].loc[\"URL\"] = table[0].loc[\"URL\"].apply(lambda x: f'<a href=\"{x}\">{x}</a>')\n"
]
},
{
@@ -225,7 +225,7 @@
"outputs": [],
"source": [
"quote_data = info[[\"Price\", \"Prev Close\", \"Change\", \"Volume\", \"52W Range\", \"Perf YTD\"]]\n",
"quote_data"
"quote_data\n"
]
},
{
@@ -237,7 +237,7 @@
"source": [
"df_institutional_shareholders = openbb.stocks.fa.shrs(symbol, holder=\"institutional\")\n",
"df_institutional_shareholders.index += 1\n",
"df_institutional_shareholders"
"df_institutional_shareholders\n"
]
},
{
@@ -254,7 +254,7 @@
" ].head(5)\n",
" df_sec_filings\n",
"except:\n",
" df_sec_filings = \"Error with Nasdaq API\""
" df_sec_filings = \"Error with Nasdaq API\"\n"
]
},
{
@@ -282,7 +282,7 @@
"# \"target\": \"Price Target\",\n",
"# }\n",
"# )\n",
"df_analyst.head(10)"
"df_analyst.head(10)\n"
]
},
{
@@ -293,7 +293,7 @@
"outputs": [],
"source": [
"df_rating = openbb.stocks.fa.rating(symbol)\n",
"df_rating"
"df_rating\n"
]
},
{
@@ -306,7 +306,7 @@
"pcr_chart = openbb.stocks.options.pcr_chart(symbol, window=30, external_axes=True)\n",
"\n",
"if pcr_chart:\n",
" pcr_chart = pcr_chart.to_html()"
" pcr_chart = pcr_chart.to_html()\n"
]
},
{
@@ -321,7 +321,7 @@
"if expiry_dates:\n",
" exp = expiry_dates[0]\n",
" option_chain = openbb.stocks.options.chains(symbol, expiration=exp)\n",
" current_price = float(ticker_data[\"Adj Close\"][-1])"
" current_price = float(ticker_data[\"Adj Close\"][-1])\n"
]
},
{
@@ -344,7 +344,7 @@
" )\n",
"\n",
" if voi_chart:\n",
" voi_chart = voi_chart.to_html()"
" voi_chart = voi_chart.to_html()\n"
]
},
{
@@ -363,7 +363,7 @@
")\n",
"\n",
"if net_short_position:\n",
" net_short_position = net_short_position.to_html()"
" net_short_position = net_short_position.to_html()\n"
]
},
{
@@ -376,7 +376,7 @@
"dark_pools = openbb.stocks.dps.dpotc_chart(symbol=symbol, external_axes=True)\n",
"\n",
"if dark_pools:\n",
" dark_pools = dark_pools.to_html()"
" dark_pools = dark_pools.to_html()\n"
]
},
{
@@ -393,7 +393,7 @@
")\n",
"\n",
"if gtrades_chart:\n",
" gtrades_chart = gtrades_chart.to_html()"
" gtrades_chart = gtrades_chart.to_html()\n"
]
},
{
@@ -410,7 +410,7 @@
")\n",
"\n",
"if gov_contracts_chart:\n",
" gov_contracts_chart = gov_contracts_chart.to_html()"
" gov_contracts_chart = gov_contracts_chart.to_html()\n"
]
},
{
@@ -426,7 +426,7 @@
")\n",
"\n",
"if google_mentions_chart:\n",
" google_mentions_chart = google_mentions_chart.to_html()"
" google_mentions_chart = google_mentions_chart.to_html()\n"
]
},
{
@@ -443,7 +443,7 @@
")\n",
"\n",
"if google_regions_chart:\n",
" google_regions_chart = google_regions_chart.to_html()"
" google_regions_chart = google_regions_chart.to_html()\n"
]
},
{
@@ -455,7 +455,7 @@
"source": [
"similar_companies = openbb.stocks.ca.similar(symbol, source=\"Finviz\")[0:5]\n",
"if similar_companies:\n",
" similar_companies.append(symbol)"
" similar_companies.append(symbol)\n"
]
},
{
@@ -472,7 +472,7 @@
")\n",
"\n",
"if historical_similar:\n",
" historical_similar = historical_similar.to_html()"
" historical_similar = historical_similar.to_html()\n"
]
},
{
@@ -488,7 +488,7 @@
")\n",
"\n",
"if hcorr_similar:\n",
" hcorr_similar = hcorr_similar.to_html()"
" hcorr_similar = hcorr_similar.to_html()\n"
]
},
{
@@ -504,7 +504,7 @@
")\n",
"\n",
"if vol_similar:\n",
" vol_similar = vol_similar.to_html()"
" vol_similar = vol_similar.to_html()\n"
]
},
{
@@ -520,7 +520,7 @@
")\n",
"\n",
"if scorr_similar:\n",
" scorr_similar = scorr_similar.to_html()"
" scorr_similar = scorr_similar.to_html()\n"
]
},
{
@@ -531,7 +531,7 @@
"outputs": [],
"source": [
"income_comparison = openbb.stocks.ca.income(similar_companies)\n",
"income_comparison"
"income_comparison\n"
]
},
{
@@ -546,7 +546,7 @@
" df_related_queries.index += 1\n",
" df_related_queries.index\n",
"except:\n",
" pass"
" pass\n"
]
},
{
@@ -561,7 +561,7 @@
" df_rising_queries.index += 1\n",
" df_rising_queries\n",
"except:\n",
" pass"
" pass\n"
]
},
{
@@ -577,7 +577,7 @@
")\n",
"\n",
"if gov_histcont_chart:\n",
" gov_histcont_chart = gov_histcont_chart.to_html()"
" gov_histcont_chart = gov_histcont_chart.to_html()\n"
]
},
{
@@ -588,7 +588,7 @@
"outputs": [],
"source": [
"df_lobbying = openbb.stocks.gov.lobbying(symbol, limit=5)\n",
"df_lobbying"
"df_lobbying\n"
]
},
{
@@ -603,7 +603,7 @@
")\n",
"\n",
"if price_vs_short_interest:\n",
" price_vs_short_interest = price_vs_short_interest.to_html()"
" price_vs_short_interest = price_vs_short_interest.to_html()\n"
]
},
{
@@ -620,7 +620,7 @@
")\n",
"\n",
"if price_chart:\n",
" price_chart = price_chart.to_html()"
" price_chart = price_chart.to_html()\n"
]
},
{
@@ -630,17 +630,20 @@
"metadata": {},
"outputs": [],
"source": [
"price_target_chart = openbb.stocks.fa.pt_chart(\n",
" symbol=symbol,\n",
" start_date=\"2022-01-01\",\n",
" data=ticker_data,\n",
" limit=10,\n",
" raw=False,\n",
" external_axes=True,\n",
")\n",
"try:\n",
" price_target_chart = openbb.stocks.fa.pt_chart(\n",
" symbol=symbol,\n",
" start_date=\"2022-01-01\",\n",
" data=ticker_data,\n",
" limit=10,\n",
" raw=False,\n",
" external_axes=True,\n",
" )\n",
"\n",
"if price_target_chart:\n",
" price_target_chart = price_target_chart.to_html()"
" if price_target_chart:\n",
" price_target_chart = price_target_chart.to_html()\n",
"except Exception:\n",
" price_target_chart = OpenBBFigure()\n"
]
},
{
@@ -667,7 +670,7 @@
" else:\n",
" avg_ratings = 0\n",
"\n",
"last_price = round(ticker_data[\"Close\"][-1], 2)"
"last_price = round(ticker_data[\"Close\"][-1], 2)\n"
]
},
{
@@ -686,7 +689,7 @@
")\n",
"\n",
"if ratings_over_time_chart:\n",
" ratings_over_time_chart = ratings_over_time_chart.to_html()"
" ratings_over_time_chart = ratings_over_time_chart.to_html()\n"
]
},
{
@@ -699,7 +702,7 @@
"ta_rsi = openbb.ta.rsi_chart(ticker_data[\"Close\"], external_axes=True)\n",
"\n",
"if ta_rsi:\n",
" ta_rsi = ta_rsi.to_html()"
" ta_rsi = ta_rsi.to_html()\n"
]
},
{
@@ -711,7 +714,7 @@
"source": [
"df = openbb.ta.rsi(ticker_data[\"Close\"])\n",
"rsi_value = round(df.values[-1][0], 2)\n",
"rsi_value"
"rsi_value\n"
]
},
{
@@ -727,7 +730,7 @@
" 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)"
"regression_slope = round(model.coef_[0], 2)\n"
]
},
{
@@ -748,7 +751,7 @@
" )\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"
" df_insider\n"
]
},
{
@@ -761,7 +764,7 @@
"finbrain_sentiment = openbb.stocks.ba.headlines_chart(symbol=symbol, external_axes=True)\n",
"\n",
"if finbrain_sentiment:\n",
" finbrain_sentiment = finbrain_sentiment.to_html()"
" finbrain_sentiment = finbrain_sentiment.to_html()\n"
]
},
{
@@ -775,7 +778,7 @@
" 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\""
" finbrain_sentiment_val = \"N/A\"\n"
]
},
{
@@ -798,7 +801,7 @@
" stocktwits_sentiment += f\"Bearish {round(100*n_bear/n_cases, 2)}%\"\n",
"else:\n",
" stocktwits_sentiment += \"No messages found\"\n",
"stocktwits_sentiment"
"stocktwits_sentiment\n"
]
},
{
@@ -811,7 +814,7 @@
"snews = openbb.stocks.ba.snews_chart(symbol, external_axes=True)\n",
"\n",
"if snews:\n",
" snews = snews.to_html()"
" snews = snews.to_html()\n"
]
},
{
@@ -826,7 +829,7 @@
" 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()"
"ticker_data_all[\"Returns\"] = ticker_data_all[\"Adj Close\"].pct_change()\n"
]
},
{
@@ -845,7 +848,7 @@
")\n",
"\n",
"if bw_month:\n",
" bw_month = bw_month.to_html()"
" bw_month = bw_month.to_html()\n"
]
},
{
@@ -864,7 +867,7 @@
")\n",
"\n",
"if bw_year:\n",
" bw_year = bw_year.to_html()"
" bw_year = bw_year.to_html()\n"
]
},
{
@@ -891,7 +894,7 @@
" 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"
]
},
{
@@ -911,7 +914,7 @@
"\n",
"if ma_chart:\n",
" ma_chart = ma_chart.show(external=True)\n",
" ma_chart = ma_chart.to_html()"
" ma_chart = ma_chart.to_html()\n"
]
},
{
@@ -926,7 +929,7 @@
")\n",
"\n",
"if macd_chart:\n",
" macd_chart = macd_chart.to_html()"
" macd_chart = macd_chart.to_html()\n"
]
},
{
@@ -939,7 +942,7 @@
"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()"
" cci_chart = cci_chart.to_html()\n"
]
},
{
@@ -952,7 +955,7 @@
"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()"
" stoch_chart = stoch_chart.to_html()\n"
]
},
{
@@ -965,7 +968,7 @@
"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()"
" adx_chart = adx_chart.to_html()\n"
]
},
{
@@ -978,7 +981,7 @@
"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()"
" bbands_chart = bbands_chart.to_html()\n"
]
},
{
@@ -991,7 +994,7 @@
"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()"
" ad_chart = ad_chart.to_html()\n"
]
},
{
@@ -1010,34 +1013,16 @@
"metadata": {},
"outputs": [],
"source": [
"body = f\"\"\"\n",
"<style>\n",
"@font-face {{\n",
" font-family: \"Fira Code\";\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",
"</style>\n",
"<script src=\"/{OpenBBFigure.plotlyjs_path.as_uri()}\"></script>\n",
"\"\"\"\n",
"body = \"\"\n",
"\n",
"\n",
"img = (\n",
" str(REPOSITORY_DIRECTORY)\n",
" + \"/openbb_terminal/reports/templates/OpenBB_reports_logo.png\"\n",
")\n",
"floppy_disk_img = (\n",
" str(REPOSITORY_DIRECTORY) + \"/openbb_terminal/reports/templates/floppy-disc.png\"\n",
")\n",
"body += widgets.header(\n",
" img,\n",
" floppy_disk_img,\n",
" author,\n",
" report_date,\n",
" report_time,\n",
" report_timezone,\n",
" report_title,\n",
" plotly_js=True,\n",
")\n",
"\n",
"body += widgets.tablinks(\n",
@@ -1369,7 +1354,7 @@
"\n",
"# to save the results\n",
"with open(report_name + \".html\", \"w\", encoding=\"utf-8\") as fh:\n",
" fh.write(report)"
" fh.write(report)\n"
]
}
],
@@ -1390,7 +1375,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
"version": "3.10.11"
},
"vscode": {
"interpreter": {

View File

@@ -1,6 +1,7 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"id": "70ba2c8a",
"metadata": {},
@@ -22,7 +23,6 @@
"from IPython.display import HTML\n",
"\n",
"import openbb_terminal.config_terminal as cfg\n",
"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",
@@ -61,7 +61,8 @@
" user.preferences.MPL_STYLE,\n",
" user.preferences.PMF_STYLE,\n",
" user.preferences.RICH_STYLE,\n",
")"
")\n",
"theme.apply_style(\"light\")"
]
},
{
@@ -75,6 +76,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "807fda4e",
"metadata": {},
@@ -154,6 +156,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "f8a0d747",
"metadata": {},
@@ -396,6 +399,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "ac501a32-124d-4d21-aae1-a8d147bb1071",
"metadata": {},
@@ -410,33 +414,16 @@
"metadata": {},
"outputs": [],
"source": [
"body = f\"\"\"\n",
"<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",
" font-weight: 400 700;\n",
" font-stretch: 50%;\n",
"}}\n",
"</style>\n",
"<script src=\"/{OpenBBFigure.plotlyjs_path.as_uri()}\"></script>\n",
"\"\"\"\n",
"body = \"\"\n",
"\n",
"\n",
"img = (\n",
" str(REPOSITORY_DIRECTORY)\n",
" + \"/openbb_terminal/reports/templates/OpenBB_reports_logo.png\"\n",
")\n",
"floppy_disk_img = (\n",
" str(REPOSITORY_DIRECTORY) + \"/openbb_terminal/reports/templates/floppy-disc.png\"\n",
")\n",
"body += widgets.header(\n",
" img,\n",
" floppy_disk_img,\n",
" author,\n",
" report_date,\n",
" report_time,\n",
" report_timezone,\n",
" f\"<b>ETF RESEARCH REPORT:</b> {ticker.upper()}\",\n",
" plotly_js=True,\n",
")\n",
"\n",
"body += widgets.tablinks(\n",

View File

@@ -1,6 +1,7 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"id": "70ba2c8a",
"metadata": {},
@@ -26,10 +27,9 @@
"\n",
"import openbb_terminal.config_terminal as cfg\n",
"from openbb_terminal.helper_classes import TerminalStyle\n",
"from openbb_terminal.core.config.paths import REPOSITORY_DIRECTORY\n",
"from openbb_terminal import OpenBBFigure\n",
"from openbb_terminal import OpenBBFigure, theme\n",
"\n",
"warnings.filterwarnings(\"ignore\")"
"warnings.filterwarnings(\"ignore\")\n"
]
},
{
@@ -45,7 +45,7 @@
"set_system_variable(\"LOGGING_SUPPRESS\", True)\n",
"\n",
"# Import the OpenBB SDK\n",
"from openbb_terminal.sdk import openbb, widgets"
"from openbb_terminal.sdk import openbb, widgets\n"
]
},
{
@@ -63,7 +63,8 @@
" user.preferences.MPL_STYLE,\n",
" user.preferences.PMF_STYLE,\n",
" user.preferences.RICH_STYLE,\n",
")"
")\n",
"theme.apply_style(\"light\")\n"
]
},
{
@@ -73,7 +74,7 @@
"metadata": {},
"outputs": [],
"source": [
"stylesheet = widgets.html_report_stylesheet()"
"stylesheet = widgets.html_report_stylesheet()\n"
]
},
{
@@ -83,7 +84,7 @@
"metadata": {},
"outputs": [],
"source": [
"def get_html(func, title, *args, **kwargs):\n",
"def get_html(func, title, *args, legend=False, **kwargs):\n",
" kwargs[\"external_axes\"] = True\n",
" local_fig = func(*args, **kwargs)\n",
" # kwargs[\"chart\"] = True\n",
@@ -91,11 +92,22 @@
" local_fig.set_title(title)\n",
" local_fig.set_xaxis_title(\"Lag\")\n",
" local_fig.set_yaxis_title(\"Autocorrelation\")\n",
"\n",
" if legend:\n",
" local_fig.update_layout(\n",
" legend=dict(\n",
" x=0.01,\n",
" y=0.99,\n",
" xanchor=\"left\",\n",
" yanchor=\"top\",\n",
" xref=\"paper\",\n",
" yref=\"paper\",\n",
" )\n",
" )\n",
" return local_fig.to_html()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "807fda4e",
"metadata": {},
@@ -117,7 +129,7 @@
"# 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",
"report_name = \"Forecast Report for VTI\""
"report_name = \"Forecast Report for VTI\"\n"
]
},
{
@@ -127,7 +139,7 @@
"metadata": {},
"outputs": [],
"source": [
"ticker = symbol"
"ticker = symbol\n"
]
},
{
@@ -140,7 +152,7 @@
"if \".\" in ticker:\n",
" import sys\n",
"\n",
" sys.exit(0)"
" sys.exit(0)\n"
]
},
{
@@ -159,10 +171,11 @@
"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"
"report_title, report_date, report_time, report_timezone\n"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "f8a0d747",
"metadata": {},
@@ -182,7 +195,7 @@
"\n",
"# Prepare date for forecast\n",
"ticker_data = ticker_data.reset_index()\n",
"ticker_data.columns = [x.lower() for x in ticker_data.columns]"
"ticker_data.columns = [x.lower() for x in ticker_data.columns]\n"
]
},
{
@@ -212,7 +225,7 @@
"metadata": {},
"outputs": [],
"source": [
"expo_chart = get_html(openbb.forecast.expo_chart, None, ticker_data)"
"expo_chart = get_html(openbb.forecast.expo_chart, None, ticker_data, legend=True)"
]
},
{
@@ -222,10 +235,11 @@
"metadata": {},
"outputs": [],
"source": [
"rnn_chart = get_html(openbb.forecast.rnn_chart, None, ticker_data)"
"rnn_chart = get_html(openbb.forecast.rnn_chart, None, ticker_data, legend=True)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "ac501a32-124d-4d21-aae1-a8d147bb1071",
"metadata": {},
@@ -240,34 +254,16 @@
"metadata": {},
"outputs": [],
"source": [
"body = f\"\"\"\n",
"<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",
" font-weight: 400 700;\n",
" font-stretch: 50%;\n",
"}}\n",
"</style>\n",
"<script src=\"/{OpenBBFigure.plotlyjs_path.as_uri()}\"></script>\n",
"\"\"\"\n",
"body = \"\"\n",
"\n",
"\n",
"img = (\n",
" str(REPOSITORY_DIRECTORY)\n",
" + \"/openbb_terminal/reports/templates/OpenBB_reports_logo.png\"\n",
")\n",
"floppy_disk_img = (\n",
" str(REPOSITORY_DIRECTORY) + \"/openbb_terminal/reports/templates/floppy-disc.png\"\n",
")\n",
"body += widgets.header(\n",
" img,\n",
" floppy_disk_img,\n",
" author,\n",
" report_date,\n",
" report_time,\n",
" report_timezone,\n",
" f\"<b>FORECAST REPORT ON:</b> {ticker.upper()}\",\n",
" plotly_js=True,\n",
")\n",
"\n",
"body += widgets.tablinks([\"SUMMARY\"])\n",
@@ -289,7 +285,7 @@
"\n",
"# to save the results\n",
"with open(report_name + \".html\", \"w\", encoding=\"utf-8\") as fh:\n",
" fh.write(report)"
" fh.write(report)\n"
]
}
],

View File

@@ -1,6 +1,7 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"id": "70ba2c8a",
"metadata": {},
@@ -27,8 +28,7 @@
"\n",
"import openbb_terminal.config_terminal as cfg\n",
"from openbb_terminal.helper_classes import TerminalStyle\n",
"from openbb_terminal.core.config.paths import REPOSITORY_DIRECTORY\n",
"from openbb_terminal import OpenBBFigure\n",
"from openbb_terminal import OpenBBFigure, theme\n",
"\n",
"warnings.filterwarnings(\"ignore\")"
]
@@ -64,7 +64,9 @@
" user.preferences.MPL_STYLE,\n",
" user.preferences.PMF_STYLE,\n",
" user.preferences.RICH_STYLE,\n",
")"
")\n",
"\n",
"theme.apply_style(\"light\")"
]
},
{
@@ -78,6 +80,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "807fda4e",
"metadata": {},
@@ -171,6 +174,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "f8a0d747",
"metadata": {},
@@ -237,6 +241,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "6c852082",
"metadata": {},
@@ -392,6 +397,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "e6f6ce8a",
"metadata": {},
@@ -436,12 +442,27 @@
"source": [
"# rolling mean and std deviation of prices\n",
"\n",
"rolling = openbb.qa.rolling_chart(\n",
" symbol=ticker,\n",
" data=ticker_data,\n",
" target=\"Close\",\n",
" external_axes=True,\n",
").to_html()"
"rolling = (\n",
" openbb.qa.rolling_chart(\n",
" symbol=ticker,\n",
" data=ticker_data,\n",
" target=\"Close\",\n",
" external_axes=True,\n",
" )\n",
" .update_layout(\n",
" legend=dict(\n",
" x=0.01,\n",
" y=0.99,\n",
" xanchor=\"left\",\n",
" yanchor=\"top\",\n",
" xref=\"paper\",\n",
" yref=\"paper\",\n",
" bgcolor=\"rgba(0, 0, 0, 0)\",\n",
" ),\n",
" legend2=dict(bgcolor=\"rgba(0, 0, 0, 0)\"),\n",
" )\n",
" .to_html()\n",
")"
]
},
{
@@ -489,6 +510,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "ac501a32-124d-4d21-aae1-a8d147bb1071",
"metadata": {},
@@ -503,34 +525,16 @@
"metadata": {},
"outputs": [],
"source": [
"body = f\"\"\"\n",
"<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",
" font-weight: 400 700;\n",
" font-stretch: 50%;\n",
"}}\n",
"</style>\n",
"<script src=\"/{OpenBBFigure.plotlyjs_path.as_uri()}\"></script>\n",
"\"\"\"\n",
"body = \"\"\n",
"\n",
"\n",
"img = (\n",
" str(REPOSITORY_DIRECTORY)\n",
" + \"/openbb_terminal/reports/templates/OpenBB_reports_logo.png\"\n",
")\n",
"floppy_disk_img = (\n",
" str(REPOSITORY_DIRECTORY) + \"/openbb_terminal/reports/templates/floppy-disc.png\"\n",
")\n",
"body += widgets.header(\n",
" img,\n",
" floppy_disk_img,\n",
" author,\n",
" report_date,\n",
" report_time,\n",
" report_timezone,\n",
" f\"<b>INVESTMENT RESEARCH REPORT:</b> {ticker}\",\n",
" plotly_js=True,\n",
")\n",
"\n",
"body += widgets.tablinks(\n",

View File

@@ -1,6 +1,7 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"id": "70ba2c8a",
"metadata": {},
@@ -29,9 +30,9 @@
"import openbb_terminal.config_terminal as cfg\n",
"from openbb_terminal.helper_classes import TerminalStyle\n",
"from openbb_terminal.core.config.paths import REPOSITORY_DIRECTORY\n",
"from openbb_terminal import OpenBBFigure\n",
"from openbb_terminal import OpenBBFigure, theme\n",
"\n",
"warnings.filterwarnings(\"ignore\")"
"warnings.filterwarnings(\"ignore\")\n"
]
},
{
@@ -47,7 +48,7 @@
"set_system_variable(\"LOGGING_SUPPRESS\", True)\n",
"\n",
"# Import the OpenBB SDK\n",
"from openbb_terminal.sdk import openbb, widgets, helper"
"from openbb_terminal.sdk import openbb, widgets, helper\n"
]
},
{
@@ -66,8 +67,9 @@
" user.preferences.PMF_STYLE,\n",
" user.preferences.RICH_STYLE,\n",
")\n",
"theme.apply_style(\"light\")\n",
"\n",
"USER_PORTFOLIO_DATA_DIRECTORY = user.preferences.USER_PORTFOLIO_DATA_DIRECTORY"
"USER_PORTFOLIO_DATA_DIRECTORY = user.preferences.USER_PORTFOLIO_DATA_DIRECTORY\n"
]
},
{
@@ -77,10 +79,11 @@
"metadata": {},
"outputs": [],
"source": [
"stylesheet = widgets.html_report_stylesheet()"
"stylesheet = widgets.html_report_stylesheet()\n"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "8136bf90",
"metadata": {},
@@ -95,9 +98,8 @@
"metadata": {},
"outputs": [],
"source": [
"theme = TerminalStyle(\"light\", \"light\", \"light\")\n",
"stylesheet = widgets.html_report_stylesheet()\n",
"user_time_zone = pytz.timezone(helper.get_user_timezone())"
"user_time_zone = pytz.timezone(helper.get_user_timezone())\n"
]
},
{
@@ -114,7 +116,7 @@
"# Parameters that will be replaced when calling this notebook\n",
"# Do not leave parameters blank as notebook will not run otherwise\n",
"transactions = \"holdings_example.xlsx\"\n",
"report_name = \"Portfolio Report\""
"report_name = \"Portfolio Report\"\n"
]
},
{
@@ -136,7 +138,7 @@
"elif os.path.isfile(file_1):\n",
" transactions_path = file_1\n",
"else:\n",
" raise FileNotFoundError(\"File not found: \" + transactions)"
" raise FileNotFoundError(\"File not found: \" + transactions)\n"
]
},
{
@@ -151,10 +153,11 @@
"report_date = pd.Timestamp.now(tz=user_time_zone).strftime(\"%d %B, %Y\")\n",
"report_time = pd.Timestamp.now(tz=user_time_zone).strftime(\"%H:%M\")\n",
"report_timezone = pd.Timestamp.now(tz=user_time_zone).tzinfo\n",
"report_title, report_date, report_time, report_timezone"
"report_title, report_date, report_time, report_timezone\n"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "9363f19a",
"metadata": {},
@@ -163,6 +166,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "eb3dbd48",
"metadata": {},
@@ -181,7 +185,7 @@
" P = openbb.portfolio.load(transactions_path)\n",
" openbb.portfolio.show(P)\n",
"except Exception as e:\n",
" raise Exception(\"Failed to load the transactions.\")"
" raise Exception(\"Failed to load the transactions.\")\n"
]
},
{
@@ -194,7 +198,7 @@
"beta_chart = openbb.portfolio.rbeta_chart(P, external_axes=True)\n",
"\n",
"if beta_chart:\n",
" beta_chart = beta_chart.to_html()"
" beta_chart = beta_chart.to_html()\n"
]
},
{
@@ -207,7 +211,7 @@
"sharpe_chart = openbb.portfolio.rsharpe_chart(P, external_axes=True)\n",
"\n",
"if sharpe_chart:\n",
" sharpe_chart = sharpe_chart.to_html()"
" sharpe_chart = sharpe_chart.to_html()\n"
]
},
{
@@ -220,7 +224,7 @@
"volatility_chart = openbb.portfolio.rvol_chart(P, external_axes=True)\n",
"\n",
"if volatility_chart:\n",
" volatility_chart = volatility_chart.to_html()"
" volatility_chart = volatility_chart.to_html()\n"
]
},
{
@@ -233,7 +237,7 @@
"sortino_chart = openbb.portfolio.rsort_chart(P, external_axes=True)\n",
"\n",
"if sortino_chart:\n",
" sortino_chart = sortino_chart.to_html()"
" sortino_chart = sortino_chart.to_html()\n"
]
},
{
@@ -246,7 +250,7 @@
"maxdd_chart = openbb.portfolio.maxdd_chart(P, external_axes=True)\n",
"\n",
"if maxdd_chart:\n",
" maxdd_chart = maxdd_chart.to_html()"
" maxdd_chart = maxdd_chart.to_html()\n"
]
},
{
@@ -268,7 +272,7 @@
" \"{:.3}pp\".format\n",
")\n",
"\n",
"country_allocation"
"country_allocation\n"
]
},
{
@@ -290,7 +294,7 @@
" \"{:.3}pp\".format\n",
")\n",
"\n",
"sector_allocation"
"sector_allocation\n"
]
},
{
@@ -303,7 +307,7 @@
"distr_chart = openbb.portfolio.distr_chart(P, external_axes=True)\n",
"\n",
"if distr_chart:\n",
" distr_chart = distr_chart.to_html()"
" distr_chart = distr_chart.to_html()\n"
]
},
{
@@ -316,7 +320,7 @@
"dret_chart = openbb.portfolio.dret_chart(P, external_axes=True)\n",
"\n",
"if dret_chart:\n",
" dret_chart = dret_chart.to_html()"
" dret_chart = dret_chart.to_html()\n"
]
},
{
@@ -329,10 +333,11 @@
"yret_chart = openbb.portfolio.yret_chart(P, external_axes=True)\n",
"\n",
"if yret_chart:\n",
" yret_chart = yret_chart.to_html()"
" yret_chart = yret_chart.to_html()\n"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "ac795b8e",
"metadata": {},
@@ -347,34 +352,16 @@
"metadata": {},
"outputs": [],
"source": [
"body = f\"\"\"\n",
"<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",
" font-weight: 400 700;\n",
" font-stretch: 50%;\n",
"}}\n",
"</style>\n",
"<script src=\"/{OpenBBFigure.plotlyjs_path.as_uri()}\"></script>\n",
"\"\"\"\n",
"body = \"\"\n",
"\n",
"\n",
"img = (\n",
" str(REPOSITORY_DIRECTORY)\n",
" + \"/openbb_terminal/reports/templates/OpenBB_reports_logo.png\"\n",
")\n",
"floppy_disk_img = (\n",
" str(REPOSITORY_DIRECTORY) + \"/openbb_terminal/reports/templates/floppy-disc.png\"\n",
")\n",
"body += widgets.header(\n",
" img,\n",
" floppy_disk_img,\n",
" \"OpenBB\",\n",
" report_date,\n",
" report_time,\n",
" report_timezone,\n",
" report_title,\n",
" plotly_js=True,\n",
")\n",
"\n",
"body += widgets.tablinks([\"SUMMARY\", \"In-Depth Analysis\", \"Statistics\"])\n",
@@ -490,7 +477,7 @@
"\n",
"# to save the results\n",
"with open(report_name + \".html\", \"w\", encoding=\"utf-8\") as fh:\n",
" fh.write(report)"
" fh.write(report)\n"
]
}
],

View File

@@ -10,6 +10,9 @@ from typing import List
from jinja2 import Template
from openbb_terminal.core.config.paths import PACKAGE_DIRECTORY
from openbb_terminal.core.plots.backend import PLOTLYJS_PATH
def price_card_stylesheet():
"""Load a default CSS stylesheet from file."""
@@ -122,7 +125,7 @@ def row(elements: List) -> str:
Parameters
----------
elements : List
List of HTML code elements to add in a row
List of HTML code elements to add in a row
Returns
-------
@@ -287,16 +290,17 @@ def tablinks(tabs: List[str]) -> str:
def header(
openbb_img, floppy_disk_img, author, report_date, report_time, report_tz, title
author: str,
report_date: str,
report_time: str,
report_tz: str,
title: str,
plotly_js: bool = False,
) -> str:
"""Creates reports header
Parameters
----------
openbb_img : str
Image of OpenBB logo
floppy_disk_img : str
Image of floppy disk containing the save button
author : str
Name of author responsible by report
report_date : str
@@ -307,15 +311,19 @@ def header(
Timezone associated with datetime of report being run
title : str
Title of the report
plotly_js : bool
If True, then we add plotly.js to the report
Returns
-------
str
HTML code for interactive tabs
"""
openbb_img_path = PACKAGE_DIRECTORY / "reports/templates/OpenBB_reports_logo.png"
floppy_disk_path = PACKAGE_DIRECTORY / "reports/templates/floppy-disc.png"
try:
with open(openbb_img, "rb") as image_file:
openbb_image_encoded = base64.b64encode(image_file.read())
openbb_image_encoded = base64.b64encode(openbb_img_path.read_bytes())
openbb_img = f"""
<img src="data:image/png;base64,{openbb_image_encoded.decode()}"
alt="OpenBB" style="width:144px;">"""
@@ -323,14 +331,33 @@ def header(
openbb_img = ""
try:
with open(floppy_disk_img, "rb") as image_file:
floppy_disk_encoded = base64.b64encode(image_file.read())
floppy_disk_encoded = base64.b64encode(floppy_disk_path.read_bytes())
flask_disk_save = f"""
<center><img src="data:image/png;base64,{floppy_disk_encoded.decode()}"
alt="OpenBB" style="width:40px;"></center>"""
except Exception:
flask_disk_save = ""
plotly_script = ""
if plotly_js:
plotly_script = """
<style>
@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;700&display=swap');
body {
font-family: 'Fira Code', monospace;
font-weight: 400 700;
font-stretch: 50%;
}
</style>
"""
try:
plotly_script += f"""<script>{PLOTLYJS_PATH.read_text()}</script>"""
except Exception:
plotly_script += (
"<script src='https://cdn.plot.ly/plotly-2.24.2.min.js'></script>"
)
return f"""
<html lang="en" class="" data-lt-installed="true">
<head>
@@ -338,6 +365,7 @@ def header(
<title>OpenBB Terminal Report</title>
<meta name="robots" content="noindex">
</head>
{plotly_script}
<div style="display:flex; margin-bottom:1cm;">
{openbb_img}
<div style="margin-left:2em">

View File

@@ -366,9 +366,9 @@ def reset(queue: Optional[List[str]] = None):
console.print("resetting...")
logger.info("resetting")
plt.close("all")
plots_backend().close()
debug = get_current_system().DEBUG_MODE
plots_backend().close(reset=True)
load_env_files()
debug = get_current_system().DEBUG_MODE
try:
# save the current user

439
poetry.lock generated vendored

File diff suppressed because it is too large Load Diff

2
pyproject.toml vendored
View File

@@ -31,7 +31,7 @@ praw = "^7.1.4"
Quandl = "^3.6.0"
pytrends = "4.9.2"
matplotlib = "^3.3.3"
plotly = "^5.14.1"
plotly = "^5.15.0"
prompt-toolkit = "^3.0.16"
jupyterlab = "^3.2.4"
mplfinance = "^0.12.7-alpha.7"

View File

@@ -9,7 +9,7 @@ altgraph==0.17.3 ; python_full_version >= "3.8.1" and python_version < "3.11" an
ansiwrap==0.8.4 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
anyio==3.6.2 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
appdirs==1.4.4 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
appnope==0.1.3 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and sys_platform == "darwin" or python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and platform_system == "Darwin"
appnope==0.1.3 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and (sys_platform == "darwin" or platform_system == "Darwin")
arch==5.5.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
argon2-cffi-bindings==21.2.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
argon2-cffi==21.3.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
@@ -104,7 +104,7 @@ gitpython==3.1.31 ; python_full_version >= "3.8.1" and python_full_version != "3
google-auth-oauthlib==0.4.6 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
google-auth==2.16.2 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
graphviz==0.20.1 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
greenlet==2.0.2 ; python_full_version >= "3.8.1" and platform_machine == "aarch64" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "ppc64le" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "x86_64" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "amd64" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "AMD64" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "win32" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "WIN32" and python_full_version != "3.9.7" and python_version < "3.11"
greenlet==2.0.2 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and (platform_machine == "win32" or platform_machine == "WIN32" or platform_machine == "AMD64" or platform_machine == "amd64" or platform_machine == "x86_64" or platform_machine == "ppc64le" or platform_machine == "aarch64")
grpcio==1.51.3 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
hijri-converter==2.2.4 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
holidays==0.14.2 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
@@ -211,7 +211,7 @@ pickleshare==0.7.5 ; python_full_version >= "3.8.1" and python_full_version != "
pillow==9.4.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
pkgutil-resolve-name==1.3.10 ; python_full_version >= "3.8.1" and python_version < "3.9"
platformdirs==3.1.1 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
plotly==5.14.1 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
plotly==5.15.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
pluggy==1.0.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
pmaw==3.0.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
pmdarima==2.0.3 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
@@ -225,7 +225,7 @@ property-cached==1.6.4 ; python_full_version >= "3.8.1" and python_full_version
prophet==1.1.2 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
protobuf==3.20.1 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
psutil==5.9.3 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
ptyprocess==0.7.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and sys_platform != "win32" or python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and os_name != "nt"
ptyprocess==0.7.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and (sys_platform != "win32" or os_name != "nt")
pure-eval==0.2.2 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
py==1.11.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
pyarrow==11.0.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"

8
requirements.txt vendored
View File

@@ -6,7 +6,7 @@ altair==4.2.2 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7
ansiwrap==0.8.4 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
anyio==3.6.2 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
appdirs==1.4.4 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
appnope==0.1.3 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and sys_platform == "darwin" or python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and platform_system == "Darwin"
appnope==0.1.3 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and (sys_platform == "darwin" or platform_system == "Darwin")
arch==5.5.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
argon2-cffi-bindings==21.2.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
argon2-cffi==21.3.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
@@ -73,7 +73,7 @@ fundamentalanalysis==0.2.14 ; python_full_version >= "3.8.1" and python_full_ver
future==0.18.3 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
gitdb==4.0.10 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
gitpython==3.1.31 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
greenlet==2.0.2 ; python_full_version >= "3.8.1" and platform_machine == "aarch64" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "ppc64le" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "x86_64" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "amd64" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "AMD64" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "win32" and python_full_version != "3.9.7" and python_version < "3.11" or python_full_version >= "3.8.1" and platform_machine == "WIN32" and python_full_version != "3.9.7" and python_version < "3.11"
greenlet==2.0.2 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and (platform_machine == "win32" or platform_machine == "WIN32" or platform_machine == "AMD64" or platform_machine == "amd64" or platform_machine == "x86_64" or platform_machine == "ppc64le" or platform_machine == "aarch64")
grpcio==1.51.3 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
hijri-converter==2.2.4 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
holidays==0.14.2 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
@@ -152,7 +152,7 @@ pickleshare==0.7.5 ; python_full_version >= "3.8.1" and python_full_version != "
pillow==9.4.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
pkgutil-resolve-name==1.3.10 ; python_full_version >= "3.8.1" and python_version < "3.9"
platformdirs==3.1.1 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
plotly==5.14.1 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
plotly==5.15.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
pmaw==3.0.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
posthog==3.0.1 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
praw==7.7.0 ; python_full_version >= "3.8.1" and python_version < "3.11" and python_full_version != "3.9.7"
@@ -162,7 +162,7 @@ prompt-toolkit==3.0.38 ; python_full_version >= "3.8.1" and python_full_version
property-cached==1.6.4 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
protobuf==3.20.1 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
psutil==5.9.3 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
ptyprocess==0.7.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and sys_platform != "win32" or python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and os_name != "nt"
ptyprocess==0.7.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11" and (sys_platform != "win32" or os_name != "nt")
pure-eval==0.2.2 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
pyarrow==11.0.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"
pycares==4.3.0 ; python_full_version >= "3.8.1" and python_full_version != "3.9.7" and python_version < "3.11"