From 1d505577c48f9fd61cf767ba5d2f34ae98e12fd3 Mon Sep 17 00:00:00 2001 From: Danglewood <85772166+deeleeramone@users.noreply.github.com> Date: Fri, 1 Dec 2023 12:27:07 -0800 Subject: [PATCH] Google Colab Install Notebook (#5841) * Google Colab Install Notebook Adds example notebook for Google Colab install. * Update README.md * Update README.md Add badge -- won't work until merged into develop * point to develop for nb --------- Co-authored-by: James Maslek --- README.md | 3 + examples/README.md | 10 +- examples/googleColab.ipynb | 2125 ++++++++++++++++++++++++++++++++++++ 3 files changed, 2137 insertions(+), 1 deletion(-) create mode 100644 examples/googleColab.ipynb diff --git a/README.md b/README.md index 598a545fd634..021f5014a428 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,9 @@ + + Open In Colab + The first financial terminal that is free and fully open source. With over 600 commands, the terminal has access to equity, options, crypto, forex, macro economy, fixed income, alternative datasets, and more. diff --git a/examples/README.md b/examples/README.md index 7b40940b06ec..9c3be4b32834 100644 --- a/examples/README.md +++ b/examples/README.md @@ -4,6 +4,15 @@ This folder is a collection of example notebooks that demonstrate some of the wa ## Table of Contents +### googleColab + +This notebook installs the OpenBB Platform in a Google Colab environment with examples for: + +- Logging into OpenBB Hub +- Setting the output preference +- Fetching options and company fundamentals data +- Creating bar chart visualizations + ### findSymbols This notebook provides an introduction to discovering, finding, and searching ticker symbols. @@ -30,7 +39,6 @@ This set of examples introduces financial statements in the OpenBB Platform and - Financial attributes - Ratios and other metrics - ### copperToGoldRatio This notebook explains how to calculate and plot the Copper-to-Gold ratio. diff --git a/examples/googleColab.ipynb b/examples/googleColab.ipynb new file mode 100644 index 000000000000..8bc0c17f6d40 --- /dev/null +++ b/examples/googleColab.ipynb @@ -0,0 +1,2125 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "fc6a4747cea243f4bac6a19c43264fec": { + "model_module": "@jupyter-widgets/controls", + "model_name": "DropdownModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "DropdownModel", + "_options_labels": [ + "Total Open Interest", + "Call Open Interest", + "Put Open Interest", + "Total Volume", + "Call Volume", + "Put Volume" + ], + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "DropdownView", + "description": "", + "description_tooltip": null, + "disabled": false, + "index": 0, + "layout": "IPY_MODEL_bf10b4a3831f4e6595398f2d62a0f7b2", + "style": "IPY_MODEL_6095af63918f4075a891fc950c9790d3" + } + }, + "bf10b4a3831f4e6595398f2d62a0f7b2": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "6095af63918f4075a891fc950c9790d3": { + "model_module": "@jupyter-widgets/controls", + "model_name": "DescriptionStyleModel", + "model_module_version": "1.5.0", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "DescriptionStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "description_width": "" + } + } + } + } + }, + "cells": [ + { + "cell_type": "markdown", + "source": [ + "# Installing the OpenBB Platform in Google Colab\n", + "\n", + "This notebook will install the OpenBB Platform, fetch some data and prepare it for display as a bar chart.\n", + "\n", + "Sign up for a free account here: https://my.openbb.co" + ], + "metadata": { + "id": "xIOXTKkqBReO" + } + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "xvU65bhqKNns" + }, + "outputs": [], + "source": [ + "# Install the OpenBB Platform with all available extensions.\n", + "# Messages indicating package version conflicts at the end of installation can be safely ignored.\n", + "\n", + "!pip install openbb[all]\n", + "\n", + "# There is also a nightly distribution available, openbb-nightly" + ] + }, + { + "cell_type": "code", + "source": [ + "# Before running this cell, restart the runtime by selecting, \"Restart runtime\", from the \"Runtime\" menu.\n", + "\n", + "# Import statements - for many scenarios, the only import needed will be `from openbb import obb`\n", + "from typing import Literal\n", + "from IPython.display import display\n", + "from IPython.display import clear_output\n", + "import ipywidgets as widgets\n", + "import pandas as pd\n", + "import pandas_ta as ta\n", + "from datetime import datetime\n", + "from plotly import graph_objects as go\n", + "\n", + "from openbb import obb" + ], + "metadata": { + "id": "_69FIu9YKRhI" + }, + "execution_count": 98, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "# Login to OpenBB Hub to retrieve stored API keys.\n", + "# https://my.openbb.co/app/platform/pat\n", + "# https://my.openbb.co/app/platform/api-keys\n", + "\n", + "obb.account.login(pat=\"replace with your PAT\")\n", + "\n", + "# This is not required" + ], + "metadata": { + "id": "1OLsZHDYMBSS" + }, + "execution_count": 3, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "# Verify that the credentials from Hub were loaded successfully.\n", + "\n", + "obb.user.credentials" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "gJ7FwTC6MTzv", + "outputId": "b9d4e888-7f3f-4756-b1a4-ae438e61c2b5" + }, + "execution_count": 4, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "Credentials\n", + "\n", + "alpha_vantage_api_key: **********\n", + "benzinga_api_key: None\n", + "biztoc_api_key: None\n", + "fmp_api_key: **********\n", + "fred_api_key: **********\n", + "intrinio_api_key: **********\n", + "nasdaq_api_key: **********\n", + "polygon_api_key: **********\n", + "tiingo_token: None\n", + "tradingeconomics_api_key: None" + ] + }, + "metadata": {}, + "execution_count": 4 + } + ] + }, + { + "cell_type": "code", + "source": [ + "# Set the output preference, if desired. The examples below use Pandas DataFrames.\n", + "\n", + "obb.user.preferences.output_type = \"dataframe\"" + ], + "metadata": { + "id": "27JtqRAQ2HTb" + }, + "execution_count": 67, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "# Get Some Data\n", + "symbol = \"SPY\"\n", + "\n", + "options = obb.derivatives.options.chains(symbol, provider=\"cboe\")\n", + "\n", + "options" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 444 + }, + "id": "GWI_60zD3M3l", + "outputId": "47338fab-8ab5-467f-c26e-44148c848c63" + }, + "execution_count": 88, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + " contract_symbol expiration strike option_type volume open \\\n", + "0 SPY231130C00387000 2023-11-30 387.0 call 7.0 67.60 \n", + "1 SPY231130P00387000 2023-11-30 387.0 put 2.0 0.01 \n", + "2 SPY231130C00388000 2023-11-30 388.0 call 1.0 66.47 \n", + "3 SPY231130P00388000 2023-11-30 388.0 put 1.0 0.01 \n", + "4 SPY231130C00389000 2023-11-30 389.0 call 0.0 0.00 \n", + "... ... ... ... ... ... ... \n", + "8215 SPY260116P00670000 2026-01-16 670.0 put 0.0 0.00 \n", + "8216 SPY260116C00675000 2026-01-16 675.0 call 0.0 0.00 \n", + "8217 SPY260116P00675000 2026-01-16 675.0 put 0.0 0.00 \n", + "8218 SPY260116C00680000 2026-01-16 680.0 call 0.0 0.00 \n", + "8219 SPY260116P00680000 2026-01-16 680.0 put 0.0 0.00 \n", + "\n", + " open_interest high low implied_volatility ... last_trade_price \\\n", + "0 5.0 67.60 66.55 0.0000 ... 66.55 \n", + "1 290.0 0.01 0.01 0.0000 ... 0.01 \n", + "2 0.0 66.47 66.47 0.0000 ... 66.47 \n", + "3 1.0 0.01 0.01 0.0000 ... 0.01 \n", + "4 0.0 0.00 0.00 0.0000 ... 0.00 \n", + "... ... ... ... ... ... ... \n", + "8215 0.0 0.00 0.00 0.2367 ... 216.04 \n", + "8216 0.0 0.00 0.00 0.1387 ... 0.00 \n", + "8217 0.0 0.00 0.00 0.2385 ... 0.00 \n", + "8218 0.0 0.00 0.00 0.1411 ... 0.00 \n", + "8219 0.0 0.00 0.00 0.2432 ... 223.91 \n", + "\n", + " tick prev_close change change_percent rho \\\n", + "0 down 67.69 -1.135 -1.68 0.0003 \n", + "1 no_change 0.00 0.005 100.00 0.0000 \n", + "2 down 66.68 -0.210 -0.31 0.0003 \n", + "3 no_change 0.00 0.005 100.00 0.0000 \n", + "4 no_change 65.69 0.000 0.00 0.0003 \n", + "... ... ... ... ... ... \n", + "8215 down 215.44 0.000 0.00 -0.3427 \n", + "8216 no_change 2.50 0.000 0.00 0.4385 \n", + "8217 no_change 220.50 0.000 0.00 -0.3453 \n", + "8218 no_change 2.50 0.000 0.00 0.4078 \n", + "8219 down 225.50 0.000 0.00 -0.3478 \n", + "\n", + " last_trade_timestamp dte bid ask \n", + "0 2023-11-30 12:27:59 -1 67.77 70.67 \n", + "1 2023-11-30 09:30:12 -1 0.00 0.01 \n", + "2 2023-11-30 09:42:00 -1 67.56 68.77 \n", + "3 2023-11-30 10:16:04 -1 0.00 0.01 \n", + "4 NaT -1 65.77 68.67 \n", + "... ... ... ... ... \n", + "8215 2023-11-20 12:31:47 777 211.56 216.50 \n", + "8216 NaT 777 0.00 5.00 \n", + "8217 NaT 777 216.50 221.50 \n", + "8218 NaT 777 0.00 5.00 \n", + "8219 2023-11-27 14:07:53 777 221.50 226.50 \n", + "\n", + "[8220 rows x 27 columns]" + ], + "text/html": [ + "\n", + "
\n", + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
contract_symbolexpirationstrikeoption_typevolumeopenopen_interesthighlowimplied_volatility...last_trade_pricetickprev_closechangechange_percentrholast_trade_timestampdtebidask
0SPY231130C003870002023-11-30387.0call7.067.605.067.6066.550.0000...66.55down67.69-1.135-1.680.00032023-11-30 12:27:59-167.7770.67
1SPY231130P003870002023-11-30387.0put2.00.01290.00.010.010.0000...0.01no_change0.000.005100.000.00002023-11-30 09:30:12-10.000.01
2SPY231130C003880002023-11-30388.0call1.066.470.066.4766.470.0000...66.47down66.68-0.210-0.310.00032023-11-30 09:42:00-167.5668.77
3SPY231130P003880002023-11-30388.0put1.00.011.00.010.010.0000...0.01no_change0.000.005100.000.00002023-11-30 10:16:04-10.000.01
4SPY231130C003890002023-11-30389.0call0.00.000.00.000.000.0000...0.00no_change65.690.0000.000.0003NaT-165.7768.67
..................................................................
8215SPY260116P006700002026-01-16670.0put0.00.000.00.000.000.2367...216.04down215.440.0000.00-0.34272023-11-20 12:31:47777211.56216.50
8216SPY260116C006750002026-01-16675.0call0.00.000.00.000.000.1387...0.00no_change2.500.0000.000.4385NaT7770.005.00
8217SPY260116P006750002026-01-16675.0put0.00.000.00.000.000.2385...0.00no_change220.500.0000.00-0.3453NaT777216.50221.50
8218SPY260116C006800002026-01-16680.0call0.00.000.00.000.000.1411...0.00no_change2.500.0000.000.4078NaT7770.005.00
8219SPY260116P006800002026-01-16680.0put0.00.000.00.000.000.2432...223.91down225.500.0000.00-0.34782023-11-27 14:07:53777221.50226.50
\n", + "

8220 rows × 27 columns

\n", + "
\n", + "
\n", + "\n", + "
\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "
\n", + "\n", + "\n", + "
\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "
\n", + "
\n", + "
\n" + ] + }, + "metadata": {}, + "execution_count": 88 + } + ] + }, + { + "cell_type": "code", + "source": [ + "# Prepare A View - Volume and Open Interest by Expiration or Strike\n", + "\n", + "def filter_options_data(options, by: Literal[\"expiration\", \"strike\"] = \"expiration\"):\n", + " data = pd.DataFrame()\n", + " data[\"Total Open Interest\"] = options.groupby(by)[\"open_interest\"].sum()\n", + " data[\"Call Open Interest\"] = options[options[\"option_type\"] == \"call\"].groupby(by)[\"open_interest\"].sum()\n", + " data[\"Put Open Interest\"] = options[options[\"option_type\"] == \"put\"].groupby(by)[\"open_interest\"].sum()\n", + " data[\"Total Volume\"] = options.groupby(by)[\"volume\"].sum()\n", + " data[\"Call Volume\"] = options[options[\"option_type\"] == \"call\"].groupby(by)[\"volume\"].sum()\n", + " data[\"Put Volume\"] = options[options[\"option_type\"] == \"put\"].groupby(by)[\"volume\"].sum()\n", + "\n", + " return data\n", + "\n", + "data = filter_options_data(options, \"strike\")\n", + "\n", + "data" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 455 + }, + "id": "F-SpeJUi3l1k", + "outputId": "ee703998-297f-4831-8aad-422e16a5b3eb" + }, + "execution_count": 101, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + " Total Open Interest Call Open Interest Put Open Interest \\\n", + "strike \n", + "120.0 22821.0 74.0 22747.0 \n", + "130.0 1506.0 19.0 1487.0 \n", + "140.0 488.0 2.0 486.0 \n", + "150.0 72684.0 2072.0 70612.0 \n", + "155.0 12298.0 18.0 12280.0 \n", + "... ... ... ... \n", + "700.0 24945.0 24835.0 110.0 \n", + "705.0 478.0 478.0 0.0 \n", + "710.0 1511.0 1511.0 0.0 \n", + "715.0 981.0 981.0 0.0 \n", + "720.0 102823.0 102821.0 2.0 \n", + "\n", + " Total Volume Call Volume Put Volume \n", + "strike \n", + "120.0 78.0 0.0 78.0 \n", + "130.0 61.0 0.0 61.0 \n", + "140.0 1.0 0.0 1.0 \n", + "150.0 65.0 4.0 61.0 \n", + "155.0 21.0 1.0 20.0 \n", + "... ... ... ... \n", + "700.0 2.0 2.0 0.0 \n", + "705.0 0.0 0.0 0.0 \n", + "710.0 3.0 1.0 2.0 \n", + "715.0 0.0 0.0 0.0 \n", + "720.0 36.0 36.0 0.0 \n", + "\n", + "[272 rows x 6 columns]" + ], + "text/html": [ + "\n", + "
\n", + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Total Open InterestCall Open InterestPut Open InterestTotal VolumeCall VolumePut Volume
strike
120.022821.074.022747.078.00.078.0
130.01506.019.01487.061.00.061.0
140.0488.02.0486.01.00.01.0
150.072684.02072.070612.065.04.061.0
155.012298.018.012280.021.01.020.0
.....................
700.024945.024835.0110.02.02.00.0
705.0478.0478.00.00.00.00.0
710.01511.01511.00.03.01.02.0
715.0981.0981.00.00.00.00.0
720.0102823.0102821.02.036.036.00.0
\n", + "

272 rows × 6 columns

\n", + "
\n", + "
\n", + "\n", + "
\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "
\n", + "\n", + "\n", + "
\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "
\n", + "
\n", + "
\n" + ] + }, + "metadata": {}, + "execution_count": 101 + } + ] + }, + { + "cell_type": "code", + "source": [ + "# Do not run this cell if you are following the example above.\n", + "\n", + "# In this scenario, \"data\" could be anything that would be displayed as a bar chart. Alternatively, it could be company fundamentals data.\n", + "\n", + "# Note: This requires a valid FMP API key\n", + "\n", + "\n", + "symbol=\"AAPL\"\n", + "\n", + "data = obb.equity.fundamental.ratios(symbol, limit = 100, period=\"quarter\", provider=\"fmp\")\n", + "\n", + "data.index = data.index.strftime(\"%Y-%m-%d\")\n", + "\n", + "data" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 649 + }, + "id": "2fAclYaEMVz5", + "outputId": "10413c8a-253d-4aae-c837-644f8880923b" + }, + "execution_count": 93, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + " symbol period current_ratio quick_ratio cash_ratio \\\n", + "date \n", + "1998-12-26 AAPL Q1 2.605795 2.352426 0.822776 \n", + "1999-03-27 AAPL Q2 2.650259 2.413212 0.879534 \n", + "1999-06-26 AAPL Q3 2.792723 2.600390 1.152047 \n", + "1999-09-25 AAPL Q4 2.766301 2.522272 0.856036 \n", + "2000-01-01 AAPL Q1 2.498219 2.316539 0.807125 \n", + "... ... ... ... ... ... \n", + "2022-09-24 AAPL Q4 0.879356 0.709408 0.153563 \n", + "2022-12-31 AAPL Q1 0.938020 0.768724 0.149578 \n", + "2023-04-01 AAPL Q2 0.940354 0.764281 0.205597 \n", + "2023-07-01 AAPL Q3 0.981563 0.813585 0.227331 \n", + "2023-09-30 AAPL Q4 0.988012 0.843312 0.206217 \n", + "\n", + " days_of_sales_outstanding days_of_inventory_outstanding \\\n", + "date \n", + "1998-12-26 48.052632 1.832248 \n", + "1999-03-27 47.294118 1.437445 \n", + "1999-06-26 51.758665 0.557029 \n", + "1999-09-25 45.875749 1.890756 \n", + "2000-01-01 34.263764 0.777650 \n", + "... ... ... \n", + "2022-09-24 60.833315 8.551997 \n", + "2022-12-31 41.622138 9.185598 \n", + "2023-04-01 34.068392 12.738933 \n", + "2023-07-01 43.115762 14.577604 \n", + "2023-09-30 61.327069 11.611542 \n", + "\n", + " operating_cycle days_of_payables_outstanding \\\n", + "date \n", + "1998-12-26 49.884879 48.004886 \n", + "1999-03-27 48.731562 63.167702 \n", + "1999-06-26 52.315694 63.023873 \n", + "1999-09-25 47.766505 76.764706 \n", + "2000-01-01 35.041414 60.864055 \n", + "... ... ... \n", + "2022-09-24 69.385312 110.859542 \n", + "2022-12-31 50.807736 78.007542 \n", + "2023-04-01 46.807325 73.118615 \n", + "2023-07-01 57.693367 92.607747 \n", + "2023-09-30 72.938611 114.833405 \n", + "\n", + " cash_conversion_cycle ... price_earnings_ratio \\\n", + "date ... \n", + "1998-12-26 1.879993 ... 8.732568 \n", + "1999-03-27 -14.436140 ... 8.397059 \n", + "1999-06-26 -10.708179 ... 7.484225 \n", + "1999-09-25 -28.998201 ... 23.552897 \n", + "2000-01-01 -25.822641 ... 22.618570 \n", + "... ... ... ... \n", + "2022-09-24 -41.474230 ... 29.094281 \n", + "2022-12-31 -27.199806 ... 17.208993 \n", + "2023-04-01 -26.311290 ... 26.938138 \n", + "2023-07-01 -34.914381 ... 38.288645 \n", + "2023-09-30 -41.894793 ... 29.085850 \n", + "\n", + " price_to_free_cash_flows_ratio \\\n", + "date \n", + "1998-12-26 24.355053 \n", + "1999-03-27 18.137648 \n", + "1999-06-26 75.027047 \n", + "1999-09-25 51.769733 \n", + "2000-01-01 49.423264 \n", + "... ... \n", + "2022-09-24 115.723695 \n", + "2022-12-31 68.334817 \n", + "2023-04-01 101.516990 \n", + "2023-07-01 125.370206 \n", + "2023-09-30 137.421101 \n", + "\n", + " price_to_operating_cash_flows_ratio price_cash_flow_ratio \\\n", + "date \n", + "1998-12-26 23.808976 23.808976 \n", + "1999-03-27 16.856551 16.856551 \n", + "1999-06-26 69.058986 69.058986 \n", + "1999-09-25 47.970120 47.970120 \n", + "2000-01-01 44.388186 44.388186 \n", + "... ... ... \n", + "2022-09-24 99.948206 99.948206 \n", + "2022-12-31 60.724643 60.724643 \n", + "2023-04-01 91.152020 91.152020 \n", + "2023-07-01 115.423282 115.423282 \n", + "2023-09-30 123.658630 123.658630 \n", + "\n", + " price_earnings_to_growth_ratio price_sales_ratio dividend_yield \\\n", + "date \n", + "1998-12-26 0.203760 3.104913 0.000000 \n", + "1999-03-27 -0.699755 2.963668 0.000000 \n", + "1999-06-26 0.178003 3.900636 0.000000 \n", + "1999-09-25 -0.467319 7.827460 0.000000 \n", + "2000-01-01 0.350588 7.066493 0.000000 \n", + "... ... ... ... \n", + "2022-09-24 3.879237 26.750498 0.001536 \n", + "2022-12-31 0.369993 17.625873 0.001825 \n", + "2023-04-01 -1.414252 27.450564 0.001402 \n", + "2023-07-01 -2.253139 37.224668 0.001264 \n", + "2023-09-30 1.846951 29.841774 0.001407 \n", + "\n", + " enterprise_value_multiple price_fair_value calendarYear \n", + "date \n", + "1998-12-26 28.650009 2.760999 1999 \n", + "1999-03-27 62.597153 2.084787 1999 \n", + "1999-06-26 209.281398 2.046192 1999 \n", + "1999-09-25 70.913430 3.369035 1999 \n", + "2000-01-01 58.063853 3.750973 2000 \n", + "... ... ... ... \n", + "2022-09-24 90.344514 47.589406 2022 \n", + "2022-12-31 55.366190 36.401387 2023 \n", + "2023-04-01 86.117046 41.882005 2023 \n", + "2023-07-01 135.913479 50.517075 2023 \n", + "2023-09-30 92.900618 42.975881 2023 \n", + "\n", + "[100 rows x 57 columns]" + ], + "text/html": [ + "\n", + "
\n", + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
symbolperiodcurrent_ratioquick_ratiocash_ratiodays_of_sales_outstandingdays_of_inventory_outstandingoperating_cycledays_of_payables_outstandingcash_conversion_cycle...price_earnings_ratioprice_to_free_cash_flows_ratioprice_to_operating_cash_flows_ratioprice_cash_flow_ratioprice_earnings_to_growth_ratioprice_sales_ratiodividend_yieldenterprise_value_multipleprice_fair_valuecalendarYear
date
1998-12-26AAPLQ12.6057952.3524260.82277648.0526321.83224849.88487948.0048861.879993...8.73256824.35505323.80897623.8089760.2037603.1049130.00000028.6500092.7609991999
1999-03-27AAPLQ22.6502592.4132120.87953447.2941181.43744548.73156263.167702-14.436140...8.39705918.13764816.85655116.856551-0.6997552.9636680.00000062.5971532.0847871999
1999-06-26AAPLQ32.7927232.6003901.15204751.7586650.55702952.31569463.023873-10.708179...7.48422575.02704769.05898669.0589860.1780033.9006360.000000209.2813982.0461921999
1999-09-25AAPLQ42.7663012.5222720.85603645.8757491.89075647.76650576.764706-28.998201...23.55289751.76973347.97012047.970120-0.4673197.8274600.00000070.9134303.3690351999
2000-01-01AAPLQ12.4982192.3165390.80712534.2637640.77765035.04141460.864055-25.822641...22.61857049.42326444.38818644.3881860.3505887.0664930.00000058.0638533.7509732000
..................................................................
2022-09-24AAPLQ40.8793560.7094080.15356360.8333158.55199769.385312110.859542-41.474230...29.094281115.72369599.94820699.9482063.87923726.7504980.00153690.34451447.5894062022
2022-12-31AAPLQ10.9380200.7687240.14957841.6221389.18559850.80773678.007542-27.199806...17.20899368.33481760.72464360.7246430.36999317.6258730.00182555.36619036.4013872023
2023-04-01AAPLQ20.9403540.7642810.20559734.06839212.73893346.80732573.118615-26.311290...26.938138101.51699091.15202091.152020-1.41425227.4505640.00140286.11704641.8820052023
2023-07-01AAPLQ30.9815630.8135850.22733143.11576214.57760457.69336792.607747-34.914381...38.288645125.370206115.423282115.423282-2.25313937.2246680.001264135.91347950.5170752023
2023-09-30AAPLQ40.9880120.8433120.20621761.32706911.61154272.938611114.833405-41.894793...29.085850137.421101123.658630123.6586301.84695129.8417740.00140792.90061842.9758812023
\n", + "

100 rows × 57 columns

\n", + "
\n", + "
\n", + "\n", + "
\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "
\n", + "\n", + "\n", + "
\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "
\n", + "
\n", + "
\n" + ] + }, + "metadata": {}, + "execution_count": 93 + } + ] + }, + { + "cell_type": "code", + "source": [ + "# Create a widget for selecting the data to display.\n", + "\n", + "clear_output(wait = False)\n", + "\n", + "data_choices = data.columns.tolist()\n", + "data_selection = widgets.Dropdown(\n", + " options = data_choices,\n", + " value = None,\n", + ")\n", + "output = widgets.Output()\n", + "\n", + "\n", + "def generate_figure(data, data_choice):\n", + " data = data[data[data_choice].notnull()]\n", + " fig = go.Figure()\n", + " fig.add_bar(\n", + " y = data[data_choice][data[data_choice] > 0].values,\n", + " x = data[data_choice][data[data_choice] > 0].index,\n", + " name = data_choice,\n", + " marker = dict(color = \"blue\"),\n", + " )\n", + " fig.add_bar(\n", + " y = data[data_choice][data[data_choice] < 0].values,\n", + " x = data[data_choice][data[data_choice] < 0].index,\n", + " name = data_choice,\n", + " marker = dict(color = \"red\")\n", + " )\n", + " fig.update_xaxes(type=\"category\")\n", + " fig.update_traces(width=0.98, selector=dict(type=\"bar\"))\n", + " fig.update_layout(\n", + " showlegend=False,\n", + " width=1400,\n", + " height=600,\n", + " title = dict(\n", + " text=f\"{symbol} {data_choice.replace('_', ' ').title()}\",\n", + " xanchor = \"center\",\n", + " x = 0.5,\n", + " font = dict(size = 20)\n", + " ),\n", + " barmode=\"overlay\",\n", + " bargap=0,\n", + " bargroupgap=0,\n", + " yaxis=dict(\n", + " ticklen=0,\n", + " showgrid=True,\n", + " tickfont=dict(size=14),\n", + " ),\n", + " xaxis=dict(\n", + " showgrid=False,\n", + " autorange=True,\n", + " tickangle=90,\n", + " tickfont=dict(size=11),\n", + " ),\n", + " )\n", + " return fig\n", + "\n", + "def on_value_change(change):\n", + " clear_output(wait = True)\n", + " display(data_selection)\n", + " with output:\n", + " data_selection.value\n", + "\n", + "data_selection.observe(on_value_change, names=\"value\")\n", + "display(data_selection)\n", + "\n", + "# Select from the drop-down menu below." + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 49, + "referenced_widgets": [ + "fc6a4747cea243f4bac6a19c43264fec", + "bf10b4a3831f4e6595398f2d62a0f7b2", + "6095af63918f4075a891fc950c9790d3" + ] + }, + "id": "jvvAtHfvMkXB", + "outputId": "6155ecd8-5bec-4fb7-ef77-52b3bb325af7" + }, + "execution_count": 102, + "outputs": [ + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Dropdown(options=('Total Open Interest', 'Call Open Interest', 'Put Open Interest', 'Total Volume', 'Call Volu…" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "fc6a4747cea243f4bac6a19c43264fec" + } + }, + "metadata": {} + } + ] + }, + { + "cell_type": "code", + "source": [ + "# Play this cell to display the choice\n", + "\n", + "if data_selection.value is not None:\n", + "\n", + " generate_figure(data, data_selection.value).show()" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 617 + }, + "id": "J9D5Qq0sQOwH", + "outputId": "91092fb7-c313-4305-eed2-00d6b5750a8b" + }, + "execution_count": 106, + "outputs": [ + { + "output_type": "display_data", + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "
\n", + "
\n", + "\n", + "" + ] + }, + "metadata": {} + } + ] + } + ] +} \ No newline at end of file