From 4021a5511fcf3c216f8fcdde7681d4e49f47b687 Mon Sep 17 00:00:00 2001 From: Henrique Joaquim Date: Mon, 19 Dec 2022 15:25:45 +0000 Subject: [PATCH] Out of the box forex report (#3799) * dashboards working on installer * passing args as list * fixed for ubuntu * adding args just if necessary * removing the shell arg * out of the box forex report * removing changes * adjusting condition --- .../custom_indicators_view.py | 6 ++ openbb_terminal/forex/forex_helper.py | 9 +- openbb_terminal/reports/templates/forex.ipynb | 96 +++---------------- 3 files changed, 24 insertions(+), 87 deletions(-) diff --git a/openbb_terminal/common/technical_analysis/custom_indicators_view.py b/openbb_terminal/common/technical_analysis/custom_indicators_view.py index ddd815c2556..474a0fa5b99 100644 --- a/openbb_terminal/common/technical_analysis/custom_indicators_view.py +++ b/openbb_terminal/common/technical_analysis/custom_indicators_view.py @@ -53,6 +53,12 @@ def fibonacci_retracement( Format to export data external_axes : Optional[List[plt.Axes]], optional External axes (2 axes are expected in the list), by default None + + Examples + -------- + >>> from openbb_terminal.sdk import openbb + >>> df = openbb.stocks.load(symbol="aapl") + >>> openbb.ta.fib_chart(data=df) """ ( df_fib, diff --git a/openbb_terminal/forex/forex_helper.py b/openbb_terminal/forex/forex_helper.py index b608cbed1b2..68467e4c2eb 100644 --- a/openbb_terminal/forex/forex_helper.py +++ b/openbb_terminal/forex/forex_helper.py @@ -340,11 +340,12 @@ def display_candle( ax[0].ticklabel_format(style="plain", axis="y") cfg.theme.visualize_output(force_tight_layout=False) - elif is_valid_axes_count(external_axes, 2): - ax1, ax2 = external_axes - candle_chart_kwargs["ax"] = ax1 + elif (has_volume and is_valid_axes_count(external_axes, 2)) or ( + not has_volume and is_valid_axes_count(external_axes, 1) + ): + candle_chart_kwargs["ax"] = external_axes[0] if has_volume: - candle_chart_kwargs["volume"] = ax2 + candle_chart_kwargs["volume"] = external_axes[1] mpf.plot(data, **candle_chart_kwargs) if not use_matplotlib: diff --git a/openbb_terminal/reports/templates/forex.ipynb b/openbb_terminal/reports/templates/forex.ipynb index ceac14c6653..f0d556c1f40 100644 --- a/openbb_terminal/reports/templates/forex.ipynb +++ b/openbb_terminal/reports/templates/forex.ipynb @@ -161,12 +161,20 @@ "outputs": [], "source": [ "# candle\n", - "fig, ax = plt.subplots(figsize=(11, 3), dpi=150)\n", + "\n", + "if ticker_data[\"Volume\"].isnull().all() or ticker_data[\"Volume\"].eq(0).all():\n", + " fig, ax1 = plt.subplots(nrows=1, ncols=1, figsize=(11, 5), dpi=150)\n", + " external_axes=[ax1]\n", + "else:\n", + " fig, (ax1, ax2) = plt.subplots(nrows=2, ncols=1, figsize=(11, 5), dpi=150)\n", + " external_axes=[ax1, ax2]\n", + "\n", + " \n", "openbb.forex.candle(\n", " data=ticker_data,\n", " to_symbol=to_symbol,\n", " from_symbol=from_symbol,\n", - " external_axes=[ax],\n", + " external_axes=external_axes,\n", ")\n", "fig.tight_layout()\n", "f = io.BytesIO()\n", @@ -233,14 +241,6 @@ "# Technical analysis" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "39afc6a7", - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "code", "execution_count": null, @@ -465,44 +465,12 @@ "source": [ "# normality statistics and tests\n", "\n", - "# fig, _ = plt.subplots(figsize=(11, 3), dpi=150)\n", - "# openbb.qa.normality_chart(\n", - "# data=ticker_data,\n", - "# target=\"Close\",\n", - "# )\n", - "# fig.tight_layout()\n", - "# f = io.BytesIO()\n", - "# fig.savefig(f, format=\"svg\")\n", - "\n", "normality = openbb.qa.normality(\n", " data=ticker_data[\"Close\"],\n", ")\n", "normality" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "8abe96b0", - "metadata": {}, - "outputs": [], - "source": [ - "# box and whisker plot\n", - "\n", - "fig, ax = plt.subplots(figsize=(11, 3), dpi=150)\n", - "openbb.qa.bw(\n", - " symbol=ticker,\n", - " data=ticker_data,\n", - " target=\"Close\",\n", - " yearly=False,\n", - " external_axes=[ax],\n", - ")\n", - "fig.tight_layout()\n", - "f = io.BytesIO()\n", - "fig.savefig(f, format=\"svg\")\n", - "bw = f.getvalue().decode(\"utf-8\")" - ] - }, { "cell_type": "code", "execution_count": null, @@ -570,26 +538,6 @@ "news" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "077fb111", - "metadata": {}, - "outputs": [], - "source": [ - "news.index" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "fd5136de", - "metadata": {}, - "outputs": [], - "source": [ - "# TODO: add prediction" - ] - }, { "cell_type": "markdown", "id": "ac501a32-124d-4d21-aae1-a8d147bb1071", @@ -716,8 +664,6 @@ "htmlcode += widgets.row(\n", " [widgets.h(3, \"Normality statistics and tests\") + normality.to_html()]\n", ")\n", - "htmlcode += widgets.row([widgets.h(3, \"Box and whisker plot\")])\n", - "htmlcode += widgets.row([bw])\n", "htmlcode += widgets.row([widgets.h(3, \"Rolling mean and std deviation of prices\")])\n", "htmlcode += widgets.row([rolling])\n", "htmlcode += widgets.row([widgets.h(3, \"Rolling kurtosis of distribution of prices\")])\n", @@ -731,28 +677,12 @@ "with open(report_name + \".html\", \"w\", encoding=\"utf-8\") as fh:\n", " fh.write(report)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "7f749ab6-2631-41d9-988b-c0a95765856d", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "30e917a5-e702-44c9-8c0c-7acbb59dc2da", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { "celltoolbar": "Tags", "kernelspec": { - "display_name": "Python 3.9.6 ('obb')", + "display_name": "obb", "language": "python", "name": "python3" }, @@ -766,11 +696,11 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.6" + "version": "3.9.15" }, "vscode": { "interpreter": { - "hash": "cb66ba39c97f15743fbb79e204a841ea03600987d49579cfb0ffc8e8dd934c69" + "hash": "064616a2a61fe0b02b4221b246288b2c948e21735d721c5874485c07e606fcd4" } } },