{ "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": { "1c14db4b3fa04b67a7265adda2672f58": { "model_module": "@jupyter-widgets/controls", "model_name": "DropdownModel", "model_module_version": "2.0.0", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "2.0.0", "_model_name": "DropdownModel", "_options_labels": [ "Cash and cash equivalents", "Other short-term investments", "Total cash", "Net receivables", "Inventory", "Other current assets", "Total current assets", "Gross property plant and equipment", "Accumulated depreciation", "Net property plant and equipment", "Equity and other investments", "Other long-term assets", "Total non-current assets", "Total assets", "Current debt", "Accounts payable", "Deferred revenues", "Other current liabilities", "Total current liabilities", "Long-term debt", "Other long-term liabilities", "Total non-current liabilities", "Total liabilities", "Common stock", "Retained earnings", "Accumulated other comprehensive income", "Total stockholders' equity", "Total liabilities and stockholders' equity" ], "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "2.0.0", "_view_name": "DropdownView", "description": "", "description_allow_html": false, "disabled": false, "index": 2, "layout": "IPY_MODEL_5038c42252f245e4906d27a68f23d7cd", "style": "IPY_MODEL_ce2de0778cf24736b3ed515792072c94", "tabbable": null, "tooltip": null } }, "5038c42252f245e4906d27a68f23d7cd": { "model_module": "@jupyter-widgets/base", "model_name": "LayoutModel", "model_module_version": "2.0.0", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "2.0.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border_bottom": null, "border_left": null, "border_right": null, "border_top": 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, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "ce2de0778cf24736b3ed515792072c94": { "model_module": "@jupyter-widgets/controls", "model_name": "DescriptionStyleModel", "model_module_version": "2.0.0", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "2.0.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "StyleView", "description_width": "" } } } } }, "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "id": "LNE5BHdkQ6cY" }, "outputs": [], "source": [ "# You can ignore the red warning messages.\n", "# The nightly distribution is built from the develop branch on GitHub every night, and will contain bug fixes not available on PyPI.\n", "# To not use the nightly distribution, run `!pip install openbb`\n", "# To install locally, follow the instructions here: https://docs.openbb.co/terminal/installation/source\n", "\n", "!pip install openbb-nightly" ] }, { "cell_type": "code", "source": [ "# First, restart the runtime by clicking the button.\n", "\n", "# Import statements - for many scenarios, the only import needed will be `from openbb_terminal.sdk import openbb`\n", "\n", "from IPython.display import display\n", "from IPython.display import clear_output\n", "import ipywidgets as widgets\n", "import numpy as np\n", "import pandas as pd\n", "import pandas_ta as ta\n", "from datetime import datetime\n", "\n", "from openbb_terminal.sdk import openbb\n", "from openbb_terminal import OpenBBFigure\n", "\n", "pd.options.plotting.backend = \"plotly\"\n", "\n", "# The output of this block can be ignored. The forecast components are not currently compatible with CoLabs.\n", "# Documentation is found here: https://docs.openbb.co/sdk/usage/basics\n", "# For additional example notebooks, see: https://my.openbb.co/app/sdk/examples\n", "# Enter API credentials and generate a personal access token to login remotely: https://my.openbb.co/app/sdk/api-keys" ], "metadata": { "id": "YqSodJvmQ87R" }, "execution_count": 3, "outputs": [] }, { "cell_type": "code", "source": [ "# Login with:\n", "\n", "#openbb.login(token=\"REPLACE_WITH_PAT\")" ], "metadata": { "id": "KkwFZdBqpmvr" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "symbol= \"AAPL\"" ], "metadata": { "id": "oWTfr457h470" }, "execution_count": 2, "outputs": [] }, { "cell_type": "code", "source": [ "data = openbb.stocks.load(symbol)[\"Close\"].pct_change(21)\n", "data.tail(2)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 107 }, "id": "Kwc9TSwXd8jm", "outputId": "9453751b-5dd1-4961-ab48-8850e89660ef" }, "execution_count": 4, "outputs": [ { "output_type": "display_data", "data": { "text/plain": [ "Loading Daily data for AAPL with starting period 2020-08-04.\n" ], "text/html": [ "
Loading Daily data for AAPL with starting period 2020-08-04.\n",
              "
\n" ] }, "metadata": {} }, { "output_type": "execute_result", "data": { "text/plain": [ "date\n", "2023-08-08 -0.046710\n", "2023-08-09 -0.045613\n", "Name: Close, dtype: float64" ] }, "metadata": {}, "execution_count": 4 } ] }, { "cell_type": "code", "source": [ "# Generate output without loading to a variable.\n", "\n", "openbb.stocks.load(symbol)[\"Close\"].pct_change(21).plot()" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 559 }, "id": "BgmixSVBYd_N", "outputId": "bdcb310f-027f-43f9-9fa2-d63114326ebd" }, "execution_count": 5, "outputs": [ { "output_type": "display_data", "data": { "text/plain": [ "Loading Daily data for AAPL with starting period 2020-08-04.\n" ], "text/html": [ "
Loading Daily data for AAPL with starting period 2020-08-04.\n",
              "
\n" ] }, "metadata": {} }, { "output_type": "display_data", "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {} } ] }, { "cell_type": "code", "source": [ "# This loads the complete options chain for a symbol, and binds class methods to the response object.\n", "\n", "options = openbb.stocks.options.load_options_chains(symbol)\n", "\n", "options.get_strategies()" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "id": "Qrv_m3gTh0XE", "outputId": "1aaf4a3c-d0a3-4268-f134-33c5e5141415" }, "execution_count": 6, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " Expiration DTE Strategy Underlying Price Strike 1 Strike 2 \\\n", "0 2023-08-11 2 Long Straddle 179.42 180.0 180.0 \n", "1 2023-08-18 9 Long Straddle 179.42 180.0 180.0 \n", "2 2023-08-25 16 Long Straddle 179.42 180.0 180.0 \n", "3 2023-09-01 23 Long Straddle 179.42 180.0 180.0 \n", "4 2023-09-08 30 Long Straddle 179.42 180.0 180.0 \n", "5 2023-09-15 37 Long Straddle 179.42 180.0 180.0 \n", "6 2023-09-22 44 Long Straddle 179.42 180.0 180.0 \n", "7 2023-10-20 72 Long Straddle 179.42 180.0 180.0 \n", "8 2023-11-17 100 Long Straddle 179.42 180.0 180.0 \n", "9 2023-12-15 128 Long Straddle 179.42 180.0 180.0 \n", "10 2024-01-19 163 Long Straddle 179.42 180.0 180.0 \n", "11 2024-03-15 219 Long Straddle 179.42 180.0 180.0 \n", "12 2024-06-21 317 Long Straddle 179.42 180.0 180.0 \n", "13 2024-09-20 408 Long Straddle 179.42 180.0 180.0 \n", "14 2024-12-20 499 Long Straddle 179.42 180.0 180.0 \n", "15 2025-01-17 527 Long Straddle 179.42 180.0 180.0 \n", "16 2025-06-20 681 Long Straddle 179.42 180.0 180.0 \n", "17 2025-12-19 863 Long Straddle 179.42 180.0 180.0 \n", "\n", " Strike 1 Premium Strike 2 Premium Cost Cost Percent Breakeven Upper \\\n", "0 1.02 1.77 2.79 1.555 182.79 \n", "1 2.08 2.67 4.75 2.6474 184.75 \n", "2 2.97 3.4 6.37 3.5503 186.37 \n", "3 3.7 3.9 7.6 4.2359 187.6 \n", "4 4.25 4.25 8.5 4.7375 188.5 \n", "5 4.95 4.75 9.7 5.4063 189.7 \n", "6 5.55 5.15 10.7 5.9637 190.7 \n", "7 7.45 6.35 13.8 7.6915 193.8 \n", "8 9.55 7.85 17.4 9.6979 197.4 \n", "9 11.0 8.65 19.65 10.952 199.65 \n", "10 12.8 9.55 22.35 12.4568 202.35 \n", "11 15.85 11.3 27.15 15.1321 207.15 \n", "12 20.15 13.55 33.7 18.7827 213.7 \n", "13 23.7 15.35 39.05 21.7646 219.05 \n", "14 27.05 17.1 44.15 24.6071 224.15 \n", "15 27.95 17.45 45.4 25.3038 225.4 \n", "16 32.55 19.9 52.45 29.2331 232.45 \n", "17 37.3 22.3 59.6 33.2181 239.6 \n", "\n", " Breakeven Upper Percent Breakeven Lower Breakeven Lower Percent Max Profit \\\n", "0 1.8783 177.21 -1.2317 inf \n", "1 2.9707 175.25 -2.3242 inf \n", "2 3.8736 173.63 -3.2271 inf \n", "3 4.5591 172.4 -3.9126 inf \n", "4 5.0608 171.5 -4.4142 inf \n", "5 5.7296 170.3 -5.083 inf \n", "6 6.2869 169.3 -5.6404 inf \n", "7 8.0147 166.2 -7.3682 inf \n", "8 10.0212 162.6 -9.3747 inf \n", "9 11.2752 160.35 -10.6287 inf \n", "10 12.7801 157.65 -12.1335 inf \n", "11 15.4554 152.85 -14.8088 inf \n", "12 19.106 146.3 -18.4595 inf \n", "13 22.0878 140.95 -21.4413 inf \n", "14 24.9303 135.85 -24.2838 inf \n", "15 25.627 134.6 -24.9805 inf \n", "16 29.5563 127.55 -28.9098 inf \n", "17 33.5414 120.4 -32.8949 inf \n", "\n", " Max Loss Payoff Ratio \n", "0 -2.79 inf \n", "1 -4.75 inf \n", "2 -6.37 inf \n", "3 -7.6 inf \n", "4 -8.5 inf \n", "5 -9.7 inf \n", "6 -10.7 inf \n", "7 -13.8 inf \n", "8 -17.4 inf \n", "9 -19.65 inf \n", "10 -22.35 inf \n", "11 -27.15 inf \n", "12 -33.7 inf \n", "13 -39.05 inf \n", "14 -44.15 inf \n", "15 -45.4 inf \n", "16 -52.45 inf \n", "17 -59.6 inf " ], "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ExpirationDTEStrategyUnderlying PriceStrike 1Strike 2Strike 1 PremiumStrike 2 PremiumCostCost PercentBreakeven UpperBreakeven Upper PercentBreakeven LowerBreakeven Lower PercentMax ProfitMax LossPayoff Ratio
02023-08-112Long Straddle179.42180.0180.01.021.772.791.555182.791.8783177.21-1.2317inf-2.79inf
12023-08-189Long Straddle179.42180.0180.02.082.674.752.6474184.752.9707175.25-2.3242inf-4.75inf
22023-08-2516Long Straddle179.42180.0180.02.973.46.373.5503186.373.8736173.63-3.2271inf-6.37inf
32023-09-0123Long Straddle179.42180.0180.03.73.97.64.2359187.64.5591172.4-3.9126inf-7.6inf
42023-09-0830Long Straddle179.42180.0180.04.254.258.54.7375188.55.0608171.5-4.4142inf-8.5inf
52023-09-1537Long Straddle179.42180.0180.04.954.759.75.4063189.75.7296170.3-5.083inf-9.7inf
62023-09-2244Long Straddle179.42180.0180.05.555.1510.75.9637190.76.2869169.3-5.6404inf-10.7inf
72023-10-2072Long Straddle179.42180.0180.07.456.3513.87.6915193.88.0147166.2-7.3682inf-13.8inf
82023-11-17100Long Straddle179.42180.0180.09.557.8517.49.6979197.410.0212162.6-9.3747inf-17.4inf
92023-12-15128Long Straddle179.42180.0180.011.08.6519.6510.952199.6511.2752160.35-10.6287inf-19.65inf
102024-01-19163Long Straddle179.42180.0180.012.89.5522.3512.4568202.3512.7801157.65-12.1335inf-22.35inf
112024-03-15219Long Straddle179.42180.0180.015.8511.327.1515.1321207.1515.4554152.85-14.8088inf-27.15inf
122024-06-21317Long Straddle179.42180.0180.020.1513.5533.718.7827213.719.106146.3-18.4595inf-33.7inf
132024-09-20408Long Straddle179.42180.0180.023.715.3539.0521.7646219.0522.0878140.95-21.4413inf-39.05inf
142024-12-20499Long Straddle179.42180.0180.027.0517.144.1524.6071224.1524.9303135.85-24.2838inf-44.15inf
152025-01-17527Long Straddle179.42180.0180.027.9517.4545.425.3038225.425.627134.6-24.9805inf-45.4inf
162025-06-20681Long Straddle179.42180.0180.032.5519.952.4529.2331232.4529.5563127.55-28.9098inf-52.45inf
172025-12-19863Long Straddle179.42180.0180.037.322.359.633.2181239.633.5414120.4-32.8949inf-59.6inf
\n", "
\n", " \n", "\n", "\n", "\n", "
\n", " \n", "
\n", "\n", "\n", "\n", " \n", "\n", " \n", " \n", "\n", " \n", "
\n", "
\n" ] }, "metadata": {}, "execution_count": 6 } ] }, { "cell_type": "code", "source": [ "print(f\"Last Price of Underlying: {options.last_price}\")\n", "options.get_skew()" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 442 }, "id": "qKxdTqbKienM", "outputId": "e50cf906-5904-4bf1-af82-6cd3867cd7b9" }, "execution_count": 7, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Last Price of Underlying: 179.42\n" ] }, { "output_type": "execute_result", "data": { "text/plain": [ " Expiration Strike Option Type IV ATM IV Skew\n", "0 2023-08-11 50.0 put 5.1895 0.2470 4.9425\n", "1 2023-08-11 60.0 put 4.4677 0.2470 4.2207\n", "2 2023-08-11 65.0 put 4.1514 0.2470 3.9044\n", "3 2023-08-11 70.0 put 3.8588 0.2470 3.6118\n", "4 2023-08-11 75.0 put 3.5865 0.2470 3.3395\n", "... ... ... ... ... ... ...\n", "1508 2025-12-19 290.0 put 0.3132 0.2666 0.0466\n", "1509 2025-12-19 300.0 call 0.2225 0.2708 -0.0483\n", "1510 2025-12-19 300.0 put 0.3366 0.2666 0.0700\n", "1511 2025-12-19 310.0 call 0.2211 0.2708 -0.0497\n", "1512 2025-12-19 310.0 put 0.3460 0.2666 0.0794\n", "\n", "[1513 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", "
ExpirationStrikeOption TypeIVATM IVSkew
02023-08-1150.0put5.18950.24704.9425
12023-08-1160.0put4.46770.24704.2207
22023-08-1165.0put4.15140.24703.9044
32023-08-1170.0put3.85880.24703.6118
42023-08-1175.0put3.58650.24703.3395
.....................
15082025-12-19290.0put0.31320.26660.0466
15092025-12-19300.0call0.22250.2708-0.0483
15102025-12-19300.0put0.33660.26660.0700
15112025-12-19310.0call0.22110.2708-0.0497
15122025-12-19310.0put0.34600.26660.0794
\n", "

1513 rows × 6 columns

\n", "
\n", " \n", "\n", "\n", "\n", "
\n", " \n", "
\n", "\n", "\n", "\n", " \n", "\n", " \n", " \n", "\n", " \n", "
\n", "
\n" ] }, "metadata": {}, "execution_count": 7 } ] }, { "cell_type": "code", "source": [ "# The data for the chains is stored as a class property, `chains`.\n", "\n", "options.chains" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 487 }, "id": "CBJeBoq-nurT", "outputId": "e1c52a4b-f69f-4071-b3cb-9d77b7cbc171" }, "execution_count": 8, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " expiration strike optionType contractSymbol bid bidSize \\\n", "0 2023-08-11 50.0 call AAPL230811C00050000 129.30 1 \n", "1 2023-08-11 50.0 put AAPL230811P00050000 0.00 0 \n", "2 2023-08-11 60.0 call AAPL230811C00060000 119.30 1 \n", "3 2023-08-11 60.0 put AAPL230811P00060000 0.00 0 \n", "4 2023-08-11 65.0 call AAPL230811C00065000 114.30 1 \n", "... ... ... ... ... ... ... \n", "1797 2025-12-19 290.0 put AAPL251219P00290000 109.10 90 \n", "1798 2025-12-19 300.0 call AAPL251219C00300000 4.05 107 \n", "1799 2025-12-19 300.0 put AAPL251219P00300000 119.30 2 \n", "1800 2025-12-19 310.0 call AAPL251219C00310000 3.25 130 \n", "1801 2025-12-19 310.0 put AAPL251219P00310000 129.05 59 \n", "\n", " ask askSize impliedVolatility openInterest ... change open \\\n", "0 129.45 1 0.0000 4 ... 0.000 0.0 \n", "1 0.01 624 5.1895 1 ... 0.000 0.0 \n", "2 119.45 1 0.0000 1 ... 0.000 0.0 \n", "3 0.01 624 4.4677 0 ... 0.000 0.0 \n", "4 114.45 1 0.0000 0 ... 0.000 0.0 \n", "... ... ... ... ... ... ... ... \n", "1797 112.50 102 0.3132 0 ... 0.000 0.0 \n", "1798 4.20 340 0.2225 5130 ... -0.150 4.1 \n", "1799 122.40 102 0.3366 1 ... 2.000 121.0 \n", "1800 3.45 150 0.2211 3419 ... -0.075 3.3 \n", "1801 132.45 100 0.3460 0 ... 0.000 0.0 \n", "\n", " high low tick lastTradePrice lastTradeTimestamp \\\n", "0 0.00 0.00 up 129.30 2023-08-08T14:18:27 \n", "1 0.00 0.00 up 0.01 2023-08-08T10:36:09 \n", "2 0.00 0.00 down 118.85 2023-08-07T10:50:09 \n", "3 0.00 0.00 no_change 0.00 None \n", "4 0.00 0.00 no_change 0.00 None \n", "... ... ... ... ... ... \n", "1797 0.00 0.00 down 101.00 2023-06-28T10:34:27 \n", "1798 4.10 3.90 no_change 4.05 2023-08-09T13:49:34 \n", "1799 122.00 121.00 up 122.00 2023-08-09T11:06:30 \n", "1800 3.35 3.15 up 3.35 2023-08-09T14:24:11 \n", "1801 0.00 0.00 up 125.50 2023-08-04T14:01:04 \n", "\n", " changePercent previousClose dte \n", "0 0.00 130.03 2 \n", "1 0.00 0.00 2 \n", "2 0.00 120.02 2 \n", "3 0.00 0.00 2 \n", "4 0.00 115.02 2 \n", "... ... ... ... \n", "1797 0.00 110.05 863 \n", "1798 -3.57 4.20 863 \n", "1799 1.67 120.00 863 \n", "1800 -2.19 3.42 863 \n", "1801 0.00 130.05 863 \n", "\n", "[1802 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", " \n", " \n", "
expirationstrikeoptionTypecontractSymbolbidbidSizeaskaskSizeimpliedVolatilityopenInterest...changeopenhighlowticklastTradePricelastTradeTimestampchangePercentpreviousClosedte
02023-08-1150.0callAAPL230811C00050000129.301129.4510.00004...0.0000.00.000.00up129.302023-08-08T14:18:270.00130.032
12023-08-1150.0putAAPL230811P000500000.0000.016245.18951...0.0000.00.000.00up0.012023-08-08T10:36:090.000.002
22023-08-1160.0callAAPL230811C00060000119.301119.4510.00001...0.0000.00.000.00down118.852023-08-07T10:50:090.00120.022
32023-08-1160.0putAAPL230811P000600000.0000.016244.46770...0.0000.00.000.00no_change0.00None0.000.002
42023-08-1165.0callAAPL230811C00065000114.301114.4510.00000...0.0000.00.000.00no_change0.00None0.00115.022
..................................................................
17972025-12-19290.0putAAPL251219P00290000109.1090112.501020.31320...0.0000.00.000.00down101.002023-06-28T10:34:270.00110.05863
17982025-12-19300.0callAAPL251219C003000004.051074.203400.22255130...-0.1504.14.103.90no_change4.052023-08-09T13:49:34-3.574.20863
17992025-12-19300.0putAAPL251219P00300000119.302122.401020.33661...2.000121.0122.00121.00up122.002023-08-09T11:06:301.67120.00863
18002025-12-19310.0callAAPL251219C003100003.251303.451500.22113419...-0.0753.33.353.15up3.352023-08-09T14:24:11-2.193.42863
18012025-12-19310.0putAAPL251219P00310000129.0559132.451000.34600...0.0000.00.000.00up125.502023-08-04T14:01:040.00130.05863
\n", "

1802 rows × 27 columns

\n", "
\n", " \n", "\n", "\n", "\n", "
\n", " \n", "
\n", "\n", "\n", "\n", " \n", "\n", " \n", " \n", "\n", " \n", "
\n", "
\n" ] }, "metadata": {}, "execution_count": 8 } ] }, { "cell_type": "code", "source": [ "# The source for the data can be defined by using the `source` argument.\n", "# Instructions for obtaining and entering API keys are found here: https://docs.openbb.co/sdk/usage/api-keys\n", "\n", "balance_sheet_growth = openbb.stocks.fa.balance(symbol, ratios = True).transpose()\n", "\n", "balance_sheet_growth" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 337 }, "id": "nC2Iy_kTYqnf", "outputId": "d01644ab-fe22-4d48-ded9-8d3f298810a9" }, "execution_count": 9, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "Breakdown Cash and cash equivalents Other short-term investments \\\n", "2022-09-30 -0.323240 -0.109787 \n", "2021-09-30 -0.080913 -0.476657 \n", "2020-09-30 -0.221685 0.023476 \n", "2019-09-30 0.000000 0.000000 \n", "\n", "Breakdown Total cash Net receivables Inventory Other current assets \\\n", "2022-09-30 -0.228851 0.072532 -0.248328 0.504004 \n", "2021-09-30 -0.311228 0.630149 0.620291 0.252752 \n", "2020-09-30 -0.095607 -0.296868 -0.010960 -0.088083 \n", "2019-09-30 0.000000 0.000000 0.000000 0.000000 \n", "\n", "Breakdown Total current assets Gross property plant and equipment \\\n", "2022-09-30 0.004220 0.043145 \n", "2021-09-30 -0.061769 0.059859 \n", "2020-09-30 -0.117345 0.078879 \n", "2019-09-30 0.000000 0.000000 \n", "\n", "Breakdown Accumulated depreciation Net property plant and equipment ... \\\n", "2022-09-30 0.029267 0.067875 ... \n", "2021-09-30 0.052771 0.072730 ... \n", "2020-09-30 0.139658 -0.016373 ... \n", "2019-09-30 0.000000 0.000000 ... \n", "\n", "Breakdown Total current liabilities Long-term debt \\\n", "2022-09-30 0.227134 -0.093001 \n", "2021-09-30 0.190612 0.105800 \n", "2020-09-30 -0.003084 0.074722 \n", "2019-09-30 0.000000 0.000000 \n", "\n", "Breakdown Other long-term liabilities Total non-current liabilities \\\n", "2022-09-30 -0.078444 -0.088222 \n", "2021-09-30 -0.021380 0.060552 \n", "2020-09-30 0.078946 0.076221 \n", "2019-09-30 0.000000 0.000000 \n", "\n", "Breakdown Total liabilities Common stock Retained earnings \\\n", "2022-09-30 0.049220 0.130463 -1.551600 \n", "2021-09-30 0.113568 0.129699 -0.628358 \n", "2020-09-30 0.042419 0.124076 -0.673929 \n", "2019-09-30 0.000000 0.000000 0.000000 \n", "\n", "Breakdown Accumulated other comprehensive income \\\n", "2022-09-30 -69.153374 \n", "2021-09-30 -1.401478 \n", "2020-09-30 -0.304795 \n", "2019-09-30 0.000000 \n", "\n", "Breakdown Total stockholders' equity \\\n", "2022-09-30 -0.196830 \n", "2021-09-30 -0.034420 \n", "2020-09-30 -0.277926 \n", "2019-09-30 0.000000 \n", "\n", "Breakdown Total liabilities and stockholders' equity \n", "2022-09-30 0.004994 \n", "2021-09-30 0.083714 \n", "2020-09-30 -0.043212 \n", "2019-09-30 0.000000 \n", "\n", "[4 rows x 28 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", "
BreakdownCash and cash equivalentsOther short-term investmentsTotal cashNet receivablesInventoryOther current assetsTotal current assetsGross property plant and equipmentAccumulated depreciationNet property plant and equipment...Total current liabilitiesLong-term debtOther long-term liabilitiesTotal non-current liabilitiesTotal liabilitiesCommon stockRetained earningsAccumulated other comprehensive incomeTotal stockholders' equityTotal liabilities and stockholders' equity
2022-09-30-0.323240-0.109787-0.2288510.072532-0.2483280.5040040.0042200.0431450.0292670.067875...0.227134-0.093001-0.078444-0.0882220.0492200.130463-1.551600-69.153374-0.1968300.004994
2021-09-30-0.080913-0.476657-0.3112280.6301490.6202910.252752-0.0617690.0598590.0527710.072730...0.1906120.105800-0.0213800.0605520.1135680.129699-0.628358-1.401478-0.0344200.083714
2020-09-30-0.2216850.023476-0.095607-0.296868-0.010960-0.088083-0.1173450.0788790.139658-0.016373...-0.0030840.0747220.0789460.0762210.0424190.124076-0.673929-0.304795-0.277926-0.043212
2019-09-300.0000000.0000000.0000000.0000000.0000000.0000000.0000000.0000000.0000000.000000...0.0000000.0000000.0000000.0000000.0000000.0000000.0000000.0000000.0000000.000000
\n", "

4 rows × 28 columns

\n", "
\n", " \n", "\n", "\n", "\n", "
\n", " \n", "
\n", "\n", "\n", "\n", " \n", "\n", " \n", " \n", "\n", " \n", "
\n", "
\n" ] }, "metadata": {}, "execution_count": 9 } ] }, { "cell_type": "code", "source": [ "# Select a metric to display (note that YahooFinance has limited financial statement history)\n", "\n", "clear_output(wait = False)\n", "\n", "growth_choices = balance_sheet_growth.columns.tolist()\n", "growth_selection = widgets.Dropdown(\n", " options = growth_choices,\n", " value = None,\n", ")\n", "output = widgets.Output()\n", "\n", "def generate_growth_figure(growth_choice):\n", " growth_fig = OpenBBFigure()\n", " growth_fig.add_bar(\n", " y = balance_sheet_growth[growth_choice][balance_sheet_growth[growth_choice] > 0].values,\n", " x = balance_sheet_growth[growth_choice][balance_sheet_growth[growth_choice] > 0].index,\n", " name = growth_choice + \" Growth\",\n", " marker = dict(color = \"blue\"),\n", " )\n", " growth_fig.add_bar(\n", " y = balance_sheet_growth[growth_choice][balance_sheet_growth[growth_choice] < 0].values,\n", " x = balance_sheet_growth[growth_choice][balance_sheet_growth[growth_choice] < 0].index,\n", " name = growth_choice + \" Growth\",\n", " marker = dict(color = \"red\")\n", " )\n", " growth_fig.update_layout(\n", " showlegend=False,\n", " width=600,\n", " height=200,\n", " title = dict(\n", " text=f\"{symbol} {growth_choice} Growth\",\n", " xanchor = \"center\",\n", " x = 0.5,\n", " font = dict(size = 12)\n", " ),\n", " barmode=\"overlay\",\n", " bargap=0,\n", " bargroupgap=0,\n", " yaxis = dict(\n", " title = \"% Growth\",\n", " title_font = dict(size = 12),\n", " ),\n", " xaxis = dict(\n", " showgrid = False,\n", " title_font = dict(size = 9)\n", " )\n", " )\n", " growth_fig.update_xaxes(type=\"category\")\n", " return growth_fig\n", "\n", "def on_value_change(change):\n", " clear_output(wait = True)\n", " display(growth_selection)\n", " with output:\n", " growth_selection.value\n", "\n", "growth_selection.observe(on_value_change, names=\"value\")\n", "display(growth_selection)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 49, "referenced_widgets": [ "1c14db4b3fa04b67a7265adda2672f58", "5038c42252f245e4906d27a68f23d7cd", "ce2de0778cf24736b3ed515792072c94" ] }, "id": "lx9Tglgqackd", "outputId": "55757848-ee92-4f56-ad2c-dc4dd2499a3f" }, "execution_count": 12, "outputs": [ { "output_type": "display_data", "data": { "text/plain": [ "Dropdown(index=2, options=('Cash and cash equivalents', 'Other short-term investments', 'Total cash', 'Net rec…" ], "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, "model_id": "1c14db4b3fa04b67a7265adda2672f58" } }, "metadata": {} } ] }, { "cell_type": "code", "source": [ "# Play the cell to update to the selection.\n", "\n", "if not growth_selection.value is None:\n", "\n", " generate_growth_figure(growth_selection.value).show()" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 217 }, "id": "oWmne07cb6-Z", "outputId": "c4b48906-187f-4d5c-ad11-4f1ef0b55986" }, "execution_count": 14, "outputs": [ { "output_type": "display_data", "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {} } ] }, { "cell_type": "code", "source": [ "# Momentum Score\n", "\n", "def get_momentum(symbol) -> pd.DataFrame:\n", " \"\"\"\n", " Momentum Factor Exposure is calculated as the log trailing 12-month return minus trailing one-month return. Higher values indicate larger, positive momentum exposure.\n", "\n", " Momentum = ln(1 + r12) - ln(1 + r1)\n", "\n", " Parameters\n", " ----------\n", " symbol: Ticker\n", " The Ticker object\n", "\n", " Returns\n", " -------\n", " pd.DataFrame\n", " Pandas DataFrame with the calculated historical momentum factor exposure score.\n", " \"\"\"\n", " monthly = openbb.stocks.load(symbol, monthly=True, start_date = \"1900-01-01\")[[\"Close\"]]\n", " monthly[\"12 Month Log Return\"] = np.log( 1 + monthly[[\"Close\"]].pct_change(12))\n", " monthly[\"1 Month Log Return\"] = np.log(1 + monthly[[\"Close\"]].pct_change(1))\n", " monthly = monthly.dropna()\n", " monthly[\"Momentum\"] = monthly[\"12 Month Log Return\"] - monthly[\"1 Month Log Return\"]\n", "\n", " return monthly\n", "\n", "momentum = get_momentum(symbol)\n", "print(f\"Momentum Score: {momentum.Momentum.iloc[-1]}\")\n", "momentum[\"Momentum\"].plot()" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 577 }, "id": "STTnGHZTcOfP", "outputId": "72861dee-6522-40d1-b733-841c49184c18" }, "execution_count": 15, "outputs": [ { "output_type": "display_data", "data": { "text/plain": [ "Loading Monthly data for AAPL with starting period 1985-01-01.\n" ], "text/html": [ "
Loading Monthly data for AAPL with starting period 1985-01-01.\n",
              "
\n" ] }, "metadata": {} }, { "output_type": "stream", "name": "stdout", "text": [ "Momentum Score: 0.22871522034849812\n" ] }, { "output_type": "display_data", "data": { "text/html": [ "\n", "\n", "\n", "
\n", "
\n", "\n", "" ] }, "metadata": {} } ] } ] }