mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-01 23:12:21 +00:00
* Update portfolio_view.py * mypy 1.0 test * Update helpers.py * black * ruff * Update thought_of_the_day.py * isort * Update portfolio_view.py * Update business_insider_view.py * funds,bt,ca,fa view updates * economy,etf,futures view updates * econometrics regression * mypy * reports notebooks, PlotlyTA class adjustments, crypto finbrain view * crypto views updates * crypto views done?, ba, econometrics, funds, reports * update docstrings * Update sec_view.py * portfolio reports * Update equity.ipynb * ruff * mypy + equity reports * Update yahoo_finance_view.py * Update economy_controller.py * clean up returns * mypy * finished dashboards/reports templates * update some tests * Update common.py * Update account_controller.py * Update banner.txt * update tests * tests * Update helpers_denomination.py * tests * tests * finished tests, refactor add_histplot/add_corr_plot * ruff * Update backend.py * mypy * Update backend.py * pywry linux libs for tests * pywry version bump * OpenBBFIgure import changes * Update business_insider_view.py * Update backend.py * tests * bump pywry version * forecast plot_explainability converted to plotly * Update helpers.py * tests * Update helpers.py * tests * Update helpers.py * Update helpers.py * default plotly annotation `showarrow` to false * Update backend.py * fixes * Update poetry.lock * docker * Update openbb.dockerfile * up * Update style.css * bump pywry version * Update unit-test.yml * Update unit-test.yml * figure to image/pdf export * requirements txt files, pywry version bump * mypy, pylint * cleanup * Update covid_view.py * Update helper_funcs.py * Update backend.py * updates * Update backend.py * Update backend.py * bump pywry version * Update poetry.lock * Update trailmap.py * update reports * Update custom_indicators_plugin.py * Update momentum_plugin.py * equity report * reqs files * Update fred_view.py * ruff * Update po_view.py * bump pywry version * reqs txt files * fix installer icons for mac * test updated torch/darts/pyinstaller on mac * Update dashboards_controller.py * Update terminal.py * Update terminal.spec * Update terminal.spec * test * Update poetry.lock * Report adjustments, improved dashboard subprocesses termination * pylint * Update plotly_helper.py * Update plotly_helper.py * pylint * revert darts * test * test * fix * improve shap scatter plot * Update helpers.py * Update helpers.py * cleanup * Update runa_view.py * more cleanupp * fixes * update tests * Update intrinio_view.py * Update intrinio_view.py * Update intrinio_view.py * reqs files, poetry lock * Update backend.py * test for new icon * Update fmp_view.py * updates * Update plotly_helper.py * Update businessinsider_view.py * ruff * pylint * fix previous merge * Update plotly_helper.py * update reqs files * Update directories.py * fix alt covid * fix display_candle data is None load being unreachable, get covid views ready for sdk server * Update covid_view.py * refactor cleanup * plotly_ta adjustments * terminal wide ignore print_table if export * Update plotly_helper.py * forgot to save a few * added edge case fallback if figures are in queue before backend fail * Update ta_class.py * Rename env variable name required to return plotly json * Resolve pydocstyle warnings * Resolve linting errors * revert forecasting/pyinstaller versions * Update terminal.spec * finished incoming fixedincome menu, improve get_ecb_yield_curve speed with multiprocessing * update deps * Update backend.py * fix fred model/view from switch to DataFrame, improve ecb_model * Update config_terminal.py * Update backend.py * black * clean up * Update fred_view.py * Update ta_class.py * Update ta_class.py * Update plotly_helper.py * sync fixedincome * Update ecb_model.py * convert excel to csv for faster processing * cleanup * remove excel files * Update terminal_controller.py * update tests * adjustments/missed figs in export_data * Update cryptocurrency_helpers.py * fixes * account for volume column with no volume when plotting indicators , images autogen POC * Update plotly_helper.py * Update etf_controller.py * Update etf_controller.py * margin arg for export_data func figures, some plot adjustments * logic for numpy array for plotly helper `get_dateindex` function * cleanup * update * req file updates * views * Update backend.py * update tests * Update test_load_none[btc-usd].yaml * convert merged cpi chart * linting * updates * clean * tests * Update openbb.dockerfile * remove test docker in root * Update CONTRIBUTING.md --------- Co-authored-by: Theodore Aptekarev <aptekarev@gmail.com> Co-authored-by: Chavithra <chavithra@gmail.com>
270 lines
9.2 KiB
Plaintext
Vendored
270 lines
9.2 KiB
Plaintext
Vendored
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"jupyter": {
|
|
"outputs_hidden": true
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import io\n",
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"import requests\n",
|
|
"from datetime import datetime, timedelta\n",
|
|
"import ipywidgets as widgets\n",
|
|
"from IPython.display import display\n",
|
|
"\n",
|
|
"from openbb_terminal import OpenBBFigure, theme"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"jupyter": {
|
|
"outputs_hidden": false
|
|
},
|
|
"pycharm": {
|
|
"name": "#%%\n"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"class ShortDataDash:\n",
|
|
" def __init__(self):\n",
|
|
" self.df = pd.DataFrame()\n",
|
|
" self.days_slider = widgets.IntSlider(\n",
|
|
" value=5,\n",
|
|
" min=5,\n",
|
|
" max=252,\n",
|
|
" step=1,\n",
|
|
" description=\"Days Back\",\n",
|
|
" style={\"description_width\": \"initial\"},\n",
|
|
" )\n",
|
|
" self.count_slider = widgets.IntSlider(\n",
|
|
" value=10,\n",
|
|
" min=1,\n",
|
|
" max=25,\n",
|
|
" step=1,\n",
|
|
" description=\"Number to show.\",\n",
|
|
" style={\"description_width\": \"initial\"},\n",
|
|
" )\n",
|
|
" self.output1 = widgets.Output()\n",
|
|
" self.output2 = widgets.Output()\n",
|
|
" self.load_button = widgets.Button(\n",
|
|
" description=\"Load Data\", layout=widgets.Layout(width=\"200px\", height=\"40px\")\n",
|
|
" )\n",
|
|
" self.load_button.on_click(self.load_button_click)\n",
|
|
" self.show_button = widgets.Button(\n",
|
|
" description=\"Change Number Shown\", layout=self.load_button.layout\n",
|
|
" )\n",
|
|
" self.show_button.on_click(self.show_button_click)\n",
|
|
"\n",
|
|
" self.slider_box = widgets.HBox([self.days_slider, self.count_slider])\n",
|
|
" self.button_box = widgets.VBox([self.load_button, self.show_button])\n",
|
|
"\n",
|
|
" self.stock_input = widgets.Text(\n",
|
|
" value=\"GME\",\n",
|
|
" placeholder=\"GME\",\n",
|
|
" description=\"Ticker:\",\n",
|
|
" )\n",
|
|
" self.ticker_button = widgets.Button(description=\"Plot Ticker\")\n",
|
|
" self.ticker_button.on_click(self.ticker_button_click)\n",
|
|
"\n",
|
|
" def show_button_click(self, b):\n",
|
|
" self.output1.clear_output()\n",
|
|
" with self.output1:\n",
|
|
" self.update()\n",
|
|
"\n",
|
|
" def load_button_click(self, b):\n",
|
|
" self.output1.clear_output()\n",
|
|
" self.output2.clear_output()\n",
|
|
" with self.output1:\n",
|
|
" print(f\"Data Loading for {self.days_slider.value} days\")\n",
|
|
" self.fetch_new_data()\n",
|
|
" self.update()\n",
|
|
"\n",
|
|
" def ticker_button_click(self, b):\n",
|
|
" self.output2.clear_output()\n",
|
|
" with self.output2:\n",
|
|
" self.ticker_plot()\n",
|
|
"\n",
|
|
" def fetch_new_data(self):\n",
|
|
" self.df = pd.DataFrame()\n",
|
|
" today = datetime.now().date()\n",
|
|
" idx = 0\n",
|
|
" len_df = 0\n",
|
|
" while len_df < self.days_slider.value:\n",
|
|
" date = today - timedelta(days=idx)\n",
|
|
" r = requests.get(\n",
|
|
" f\"https://cdn.finra.org/equity/regsho/daily/CNMSshvol{date.strftime('%Y%m%d')}.txt\"\n",
|
|
" )\n",
|
|
" if r.status_code == 200:\n",
|
|
" self.df = pd.concat(\n",
|
|
" [self.df, pd.read_csv(io.StringIO(r.text), sep=\"|\")], axis=0\n",
|
|
" )\n",
|
|
" len_df += 1\n",
|
|
" idx += 1\n",
|
|
" self.df = self.df[self.df.Date > 20100101]\n",
|
|
" self.df.Date = self.df[\"Date\"].apply(\n",
|
|
" lambda x: datetime.strptime(str(x), \"%Y%m%d\")\n",
|
|
" )\n",
|
|
"\n",
|
|
" def update(self):\n",
|
|
" if not self.df.empty:\n",
|
|
" temp = (\n",
|
|
" self.df.groupby(\"Symbol\")[[\"ShortVolume\", \"TotalVolume\"]]\n",
|
|
" .agg(\"sum\")\n",
|
|
" .sort_values(by=\"ShortVolume\", ascending=False)\n",
|
|
" .head(self.count_slider.value)[::-1]\n",
|
|
" )\n",
|
|
" self.fig = OpenBBFigure()\n",
|
|
" self.fig.add_bar(\n",
|
|
" x=temp.TotalVolume,\n",
|
|
" y=temp.index,\n",
|
|
" orientation=\"h\",\n",
|
|
" name=\"Total Volume\",\n",
|
|
" marker_color=theme.up_color,\n",
|
|
" )\n",
|
|
" self.fig.add_bar(\n",
|
|
" x=temp.ShortVolume,\n",
|
|
" y=temp.index,\n",
|
|
" orientation=\"h\",\n",
|
|
" name=\"Short Volume\",\n",
|
|
" marker_color=theme.down_color,\n",
|
|
" )\n",
|
|
" self.fig.update_layout(\n",
|
|
" title=f\"Top {self.count_slider.value} Short Volume in Last {self.days_slider.value} Days\",\n",
|
|
" xaxis_title=\"Volume\",\n",
|
|
" yaxis_title=\"Ticker\",\n",
|
|
" barmode=\"stack\",\n",
|
|
" bargap=0.1,\n",
|
|
" legend=dict(\n",
|
|
" orientation=\"h\",\n",
|
|
" yanchor=\"bottom\",\n",
|
|
" y=1.02,\n",
|
|
" xanchor=\"right\",\n",
|
|
" x=1,\n",
|
|
" ),\n",
|
|
" )\n",
|
|
" self.fig.show()\n",
|
|
"\n",
|
|
" def ticker_plot(self):\n",
|
|
" stock_data = self.df.copy().loc[\n",
|
|
" self.df.Symbol == self.stock_input.value,\n",
|
|
" [\"Date\", \"ShortVolume\", \"TotalVolume\"],\n",
|
|
" ]\n",
|
|
" self.fig2 = OpenBBFigure()\n",
|
|
" self.fig2.add_scatter(\n",
|
|
" x=stock_data.Date,\n",
|
|
" y=stock_data.TotalVolume,\n",
|
|
" name=\"Total Volume\",\n",
|
|
" marker_color=theme.up_color,\n",
|
|
" )\n",
|
|
" self.fig2.add_scatter(\n",
|
|
" x=stock_data.Date,\n",
|
|
" y=stock_data.ShortVolume,\n",
|
|
" name=\"Short Volume\",\n",
|
|
" marker_color=theme.down_color,\n",
|
|
" )\n",
|
|
" self.fig2.update_layout(\n",
|
|
" title=f\"Stock Volume and Short Volume for {self.stock_input.value.upper()}\",\n",
|
|
" xaxis_title=\"Date\",\n",
|
|
" yaxis_title=\"Volume\",\n",
|
|
" )\n",
|
|
" self.fig2.show()\n",
|
|
"\n",
|
|
" def build_app(self):\n",
|
|
" title_html = \"\"\"\n",
|
|
"<h2>Finra Short Data</h2>\n",
|
|
"<p>This widget downloads the consolidated NMS short data from FINRA and aggregates the data by summing over the entire time period.</p>\n",
|
|
"<p>Note that clicking the 'Load Data' button will reload all data. This can get time consuming, so if you pick a few hundred days, expect a few minutes for loading time.</p>\n",
|
|
"\"\"\"\n",
|
|
" middle_html = \"\"\"\n",
|
|
"Here we allow the user to query for a single stock. This will work with the loaded data. Note that if you want to reload the data, this will once again take some time.\n",
|
|
" \"\"\"\n",
|
|
" return [\n",
|
|
" widgets.HTML(\n",
|
|
" title_html, layout=widgets.Layout(margin=\"0 0 3em 0\", max_width=\"800px\")\n",
|
|
" ),\n",
|
|
" self.slider_box,\n",
|
|
" self.button_box,\n",
|
|
" self.output1,\n",
|
|
" widgets.HTML(\n",
|
|
" middle_html,\n",
|
|
" layout=widgets.Layout(margin=\"0 0 3em 0\", max_width=\"800px\"),\n",
|
|
" ),\n",
|
|
" self.stock_input,\n",
|
|
" self.ticker_button,\n",
|
|
" self.output2,\n",
|
|
" ]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"jupyter": {
|
|
"outputs_hidden": false
|
|
},
|
|
"pycharm": {
|
|
"name": "#%%\n"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"dash = ShortDataDash()\n",
|
|
"app = widgets.VBox(\n",
|
|
" dash.build_app(), layout=widgets.Layout(max_width=\"1024px\", margin=\"0 auto 0 auto\")\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"jupyter": {
|
|
"outputs_hidden": false
|
|
},
|
|
"pycharm": {
|
|
"name": "#%%\n"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"display(app)"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "venv",
|
|
"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.10.8"
|
|
},
|
|
"vscode": {
|
|
"interpreter": {
|
|
"hash": "381a209f752e9104bff95ec5e80679ea2e476866b80e4326f1ee6b7658af6049"
|
|
}
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 4
|
|
}
|