{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Historical Prices With the OpenBB Platform\n", "\n", "This notebook demonstrates some of the ways to approach loading historical price data using the OpenBB Platform. The action is in the Equity module; but first, we need to initialize the notebook with the import statements block.\n", "\n", "## Import Statements" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from datetime import datetime, timedelta\n", "\n", "import pandas as pd\n", "from openbb import obb\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## The Equity Module\n", "\n", "Historical market prices typically come in the form of OHLC+V - open, high, low, close, volume. There may be additional fields returned by a provider, but those are the expected columns. Granularity and amount of historical data will vary by provider and subscription status. Visit their websites to understand what your entitlements are.\n", "\n", "### openbb.equity.price.historical()\n", "\n", "- This endpoint has the most number of providers out of any function. At the time of writing, choices are:\n", "\n", "['alpha_vantage', 'cboe', 'fmp', 'intrinio', 'polygon', 'tiingo', 'yfinance']\n", "\n", "- Common parameters have been standardized across all souces, `start_date`, `end_date`, `interval`.\n", "\n", "- The default interval will be `1d`.\n", "\n", "- The depth of historical data and choices for granularity will vary by provider and subscription status. Refer to the website and documentation of each source understand your specific entitlements.\n", "\n", "- For demonstration purposes, we will use the `openbb-yfinance` data extension." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "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", "
openhighlowclosevolumedividendsstock splitscapital gains
date
2022-11-22396.63400.07395.15399.9604290000.00.00.0
\n", "
" ], "text/plain": [ " open high low close volume dividends stock splits \\\n", "date \n", "2022-11-22 396.63 400.07 395.15 399.9 60429000 0.0 0.0 \n", "\n", " capital gains \n", "date \n", "2022-11-22 0.0 " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_daily = obb.equity.price.historical(symbol = \"spy\", provider=\"yfinance\")\n", "df_daily.to_df().head(1)\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "To load the entire history available from a source, pick a starting date well beyond what it might be. For example, `1900-01-01`" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "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", "
openhighlowclosevolumedividendsstock splitscapital gains
date
1993-01-2943.9743.9743.7543.9410032000.00.00.0
\n", "
" ], "text/plain": [ " open high low close volume dividends stock splits \\\n", "date \n", "1993-01-29 43.97 43.97 43.75 43.94 1003200 0.0 0.0 \n", "\n", " capital gains \n", "date \n", "1993-01-29 0.0 " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_daily = obb.equity.price.historical(symbol = \"spy\", start_date = \"1990-01-01\", provider=\"yfinance\").to_df()\n", "df_daily.head(1)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Intervals\n", "\n", "The intervals are entered according to this pattern:\n", "\n", "- `1m` = One Minute\n", "- `1h` = One Hour\n", "- `1d` = One Day\n", "- `1W` = One Week\n", "- `1M` = One Month\n", "\n", "The date for monthly value is the first or last, depending on the provider. This can be easily resampled from daily data." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "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", "
openhighlowclosevolumedividendsstock splitscapital gains
date
2023-10-01426.62438.14409.21418.2019991497000.00.00.0
2023-11-01419.20456.38418.65455.0211612395760.00.00.0
\n", "
" ], "text/plain": [ " open high low close volume dividends \\\n", "date \n", "2023-10-01 426.62 438.14 409.21 418.20 1999149700 0.0 \n", "2023-11-01 419.20 456.38 418.65 455.02 1161239576 0.0 \n", "\n", " stock splits capital gains \n", "date \n", "2023-10-01 0.0 0.0 \n", "2023-11-01 0.0 0.0 " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_monthly = obb.equity.price.historical(\"spy\", start_date=\"1990-01-01\", interval=\"1M\", provider=\"yfinance\").to_df()\n", "df_monthly.tail(2)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Resample a Time Series\n", "\n", "`yfinance` returns the monthly data for the first day of each month. Let's resample it to take from the last, using the daily information captured in the previous cells." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "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", "
openhighlowclosevolume
date
1993-01-3143.9743.9743.7543.941003200
1993-02-2843.9745.1242.8144.415417600
1993-03-3144.5645.8444.2245.193019200
1993-04-3045.2545.2543.2844.032697200
1993-05-3144.0945.6643.8445.221808000
..................
2023-07-31442.92459.44437.06457.791374632400
2023-08-31456.27457.25433.01450.351754764700
2023-09-30453.17453.67422.29427.481588673200
2023-10-31426.62438.14409.21418.201999149700
2023-11-30419.20456.38418.65455.021214703500
\n", "

371 rows × 5 columns

\n", "
" ], "text/plain": [ " open high low close volume\n", "date \n", "1993-01-31 43.97 43.97 43.75 43.94 1003200\n", "1993-02-28 43.97 45.12 42.81 44.41 5417600\n", "1993-03-31 44.56 45.84 44.22 45.19 3019200\n", "1993-04-30 45.25 45.25 43.28 44.03 2697200\n", "1993-05-31 44.09 45.66 43.84 45.22 1808000\n", "... ... ... ... ... ...\n", "2023-07-31 442.92 459.44 437.06 457.79 1374632400\n", "2023-08-31 456.27 457.25 433.01 450.35 1754764700\n", "2023-09-30 453.17 453.67 422.29 427.48 1588673200\n", "2023-10-31 426.62 438.14 409.21 418.20 1999149700\n", "2023-11-30 419.20 456.38 418.65 455.02 1214703500\n", "\n", "[371 rows x 5 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(\n", " df_daily[[\"open\", \"high\", \"low\", \"close\", \"volume\"]]\n", " .resample(\"M\")\n", " .agg(\n", " {\"open\": \"first\", \"high\": \"max\", \"low\": \"min\", \"close\": \"last\", \"volume\": \"sum\"}\n", " )\n", ")\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "The block below packs an object with most intervals." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dict_keys(['one', 'five', 'fifteen', 'thirty', 'sixty', 'daily', 'weekly', 'monthly'])" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "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", "
openhighlowclosevolumedividendsstock splitscapital gains
date
2023-11-13439.23451.42438.42450.793765396000.000
2023-11-20450.53456.38450.52455.022337512760.000
\n", "
" ], "text/plain": [ " open high low close volume dividends \\\n", "date \n", "2023-11-13 439.23 451.42 438.42 450.79 376539600 0.0 \n", "2023-11-20 450.53 456.38 450.52 455.02 233751276 0.0 \n", "\n", " stock splits capital gains \n", "date \n", "2023-11-13 0 0 \n", "2023-11-20 0 0 " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "class HistoricalPrices:\n", " def __init__(self, symbol, start_date, end_date, provider, **kwargs) -> None:\n", " self.one: pd.DataFrame = obb.equity.price.historical(\n", " symbol=symbol, start_date=start_date, end_date=end_date, interval = \"1m\", provider=provider, **kwargs\n", " ).to_df().convert_dtypes()\n", " self.five: pd.DataFrame = obb.equity.price.historical(\n", " symbol=symbol, start_date=start_date, end_date=end_date, interval = \"5m\", provider=provider, **kwargs\n", " ).to_df().convert_dtypes()\n", " self.fifteen: pd.DataFrame = obb.equity.price.historical(\n", " symbol=symbol, start_date=start_date, end_date=end_date, interval = \"15m\", provider=provider, **kwargs\n", " ).to_df().convert_dtypes()\n", " self.thirty: pd.DataFrame = obb.equity.price.historical(\n", " symbol=symbol, start_date=start_date, end_date=end_date, interval = \"30m\", provider=provider, **kwargs\n", " ).to_df().convert_dtypes()\n", " self.sixty: pd.DataFrame = obb.equity.price.historical(\n", " symbol=symbol, start_date=start_date, end_date=end_date, interval = \"60m\", provider=provider, **kwargs\n", " ).to_df().convert_dtypes()\n", " self.daily: pd.DataFrame = obb.equity.price.historical(\n", " symbol=symbol, start_date=start_date, end_date=end_date, interval = \"1d\", provider=provider, **kwargs\n", " ).to_df().convert_dtypes()\n", " self.weekly: pd.DataFrame = obb.equity.price.historical(\n", " symbol=symbol, start_date=start_date, end_date=end_date, interval = \"1W\", provider=provider, **kwargs\n", " ).to_df().convert_dtypes()\n", " self.monthly: pd.DataFrame = obb.equity.price.historical(\n", " symbol=symbol, start_date=start_date, end_date=end_date, interval = \"1M\", provider=provider, **kwargs\n", " ).to_df().convert_dtypes()\n", "\n", "def load_historical(\n", " symbol: str = \"\",\n", " start_date = None,\n", " end_date = None,\n", " provider = None,\n", " **kwargs\n", ") -> HistoricalPrices:\n", "\n", " if symbol == \"\":\n", " display(\"Please enter a ticker symbol\")\n", " if provider is None:\n", " provider = \"yfinance\"\n", " prices = HistoricalPrices(symbol, start_date, end_date, provider, **kwargs)\n", "\n", " return prices\n", "\n", "prices = load_historical(\"spy\")\n", "display(prices.__dict__.keys())\n", "prices.weekly.tail(2)\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "To demonstrate the difference between sources, let's compare values for daily volume from several sources." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "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", "
AV VolumeFMP VolumeIntrinio VolumeYahoo Volume
date
2023-11-0983174417.08307141783174417.083174400
2023-11-1089558054.08955805489558054.089462200
2023-11-1352236068.05219256852236068.052236100
2023-11-1497176935.09713050397176935.097176900
2023-11-1577327573.07732757377327573.077327600
2023-11-1666665797.06665446866665797.066665800
2023-11-1783193902.08319390283193902.083133200
2023-11-2070055633.06961463370055633.069936200
2023-11-2149244639.04924463949244639.049244600
2023-11-2259446573.05931382058205780.059394900
\n", "
" ], "text/plain": [ " AV Volume FMP Volume Intrinio Volume Yahoo Volume\n", "date \n", "2023-11-09 83174417.0 83071417 83174417.0 83174400\n", "2023-11-10 89558054.0 89558054 89558054.0 89462200\n", "2023-11-13 52236068.0 52192568 52236068.0 52236100\n", "2023-11-14 97176935.0 97130503 97176935.0 97176900\n", "2023-11-15 77327573.0 77327573 77327573.0 77327600\n", "2023-11-16 66665797.0 66654468 66665797.0 66665800\n", "2023-11-17 83193902.0 83193902 83193902.0 83133200\n", "2023-11-20 70055633.0 69614633 70055633.0 69936200\n", "2023-11-21 49244639.0 49244639 49244639.0 49244600\n", "2023-11-22 59446573.0 59313820 58205780.0 59394900" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Collect the data\n", "\n", "yahoo = obb.equity.price.historical(\"spy\", provider=\"yfinance\").to_df()\n", "alphavantage = obb.equity.price.historical(\"spy\", provider = \"alpha_vantage\").to_df()\n", "intrinio = obb.equity.price.historical(\"spy\", provider=\"intrinio\").to_df()\n", "fmp = obb.equity.price.historical(\"spy\", provider=\"fmp\").to_df()\n", "\n", "# Make a new DataFrame with just the volume columns\n", "compare = pd.DataFrame()\n", "compare[\"AV Volume\"] = alphavantage[\"volume\"].tail(10)\n", "compare[\"FMP Volume\"] = fmp[\"volume\"].tail(10)\n", "compare[\"Intrinio Volume\"] = intrinio[\"volume\"].tail(10)\n", "compare[\"Yahoo Volume\"] = yahoo[\"volume\"].tail(10)\n", "\n", "compare\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Other Types of Symbols\n", "\n", "Other types of assets and ticker symbols can be loaded from `obb.equity.price.historical()`, below are some examples but not an exhaustive list.\n", "\n", "### Share Classes\n", "\n", "Some sources use `-` as the distinction between a share class, e.g., `BRK-A` and `BRK-B`. Other formats include:\n", "\n", "- A period: `BRK.A`\n", "- A slash: `BRK/A`\n", "- No separator, the share class becomes the fourth or fifth letter.\n", "\n", "```python\n", "obb.equity.price.historical(\"brk.b\", provider=\"polygon\")\n", "```\n", "\n", "```python\n", "obb.equity.price.historical(\"brk-b\", provider=\"fmp\")\n", "```\n", "\n", "While some providers handle the different formats on their end, others do not. This is something to consider when no results are returned from one source. Some may even use a combination, or accept multiple variations. Sometimes there is no real logic behind the additional characters, `GOOGL` vs. `GOOG`. These are known unknown variables of ticker symbology, what's good for one source may return errors from another. \n", "\n", "### Regional Identifiers\n", "\n", "With providers supporting market data from multiple jurisdictions, the most common method for requesting data outside of US-listings is to append a suffix to the ticker symbol (e.g., `RELIANCE.NS` for Indian equities). Formats may be unique to a provider, so it is best to review the source's documentation for an overview of their specific conventions. [This page](https://help.yahoo.com/kb/SLN2310.html) on Yahoo describes how they format symbols, which many others follow to some degree.\n", "\n", "### Indexes\n", "\n", "Sources will have their own treatment of these symbols, some examples are:\n", "\n", "- YahooFinance/FMP/CBOE: ^RUT\n", "- Polygon: I:NDX\n", "\n", "### Currencies\n", "\n", "FX symbols face the same dilemna as share classes, there are several variations of the same symbol.\n", "\n", "- YahooFinance: `EURUSD=X`\n", "- Polygon: `C:EURUSD`\n", "- AlphaVantage/FMP: `EURUSD`\n", "\n", "**The symbol prefixes are handled internally when `obb.currency.price.historical()` is used to enter a pair with no extra characters.**\n", "\n", "### Crypto\n", "\n", "Similar, but different to FX tickers.\n", "\n", "- YahooFinance: `BTC-USD`\n", "- Polygon: `X:BTCUSD`\n", "- AlphaVantage/FMP: `BTCUSD`\n", "\n", "**The symbol prefixes are handled internally when `obb.crypto.price.historical()` is used to enter a pair with no extra characters and placing the fiat currency second.**\n", "\n", "### Futures\n", "\n", "Historical prices for active contracts, and the continuation chart, can be fetched via `yfinance`.\n", "\n", "- Continuous front-month: `CL=F`\n", "- December 2023 contract: `CLZ24.NYM`\n", "- March 2024 contract: `CLH24.NYM`\n", "\n", "Individual contracts will require knowing which of the CME venues the future is listed on. `[\"NYM\", \"NYB\", \"CME\", \"CBT\"]`.\n", "\n", "### Options\n", "\n", "Individual options contracts are also loadable from `openbb.equity.price.historical()`.\n", "\n", "- YahooFinance: `SPY241220P00400000`\n", "- Polygon: `O:SPY241220P00400000`" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "These examples represent only a few methods for fetching historical price data. Explore the contents of each module to find more!" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "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", "
openhighlowclosevolumedividendsstock splits
date
2022-11-2243.0844.2443.0043.002870.00.0
2022-11-2341.5842.4539.0039.0060.00.0
2022-11-2842.5042.9042.5042.90180.00.0
2022-11-3041.0041.0041.0041.0010.00.0
2022-12-0140.7340.8139.8540.25420.00.0
........................
2023-11-1611.4111.8811.2711.702640.00.0
2023-11-1711.5011.5011.1911.4000.00.0
2023-11-2011.0011.1010.5010.761210.00.0
2023-11-2110.9010.9510.7510.75170.00.0
2023-11-2210.5010.8210.2510.61770.00.0
\n", "

239 rows × 7 columns

\n", "
" ], "text/plain": [ " open high low close volume dividends stock splits\n", "date \n", "2022-11-22 43.08 44.24 43.00 43.00 287 0.0 0.0\n", "2022-11-23 41.58 42.45 39.00 39.00 6 0.0 0.0\n", "2022-11-28 42.50 42.90 42.50 42.90 18 0.0 0.0\n", "2022-11-30 41.00 41.00 41.00 41.00 1 0.0 0.0\n", "2022-12-01 40.73 40.81 39.85 40.25 42 0.0 0.0\n", "... ... ... ... ... ... ... ...\n", "2023-11-16 11.41 11.88 11.27 11.70 264 0.0 0.0\n", "2023-11-17 11.50 11.50 11.19 11.40 0 0.0 0.0\n", "2023-11-20 11.00 11.10 10.50 10.76 121 0.0 0.0\n", "2023-11-21 10.90 10.95 10.75 10.75 17 0.0 0.0\n", "2023-11-22 10.50 10.82 10.25 10.61 77 0.0 0.0\n", "\n", "[239 rows x 7 columns]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "obb.equity.price.historical(\"SPY241220P00400000\", provider=\"yfinance\").to_df()\n" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "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", "
openhighlowclosevolume
date
2020-11-271846.261855.271845.501855.270
2020-11-301854.871854.871813.561819.820
2020-12-011822.921848.021822.921836.050
2020-12-021833.081842.531817.021838.030
2020-12-031838.521860.351838.521848.700
..................
2023-11-161797.001797.001767.421773.760
2023-11-171784.861798.441784.861797.770
2023-11-201798.561809.211794.711807.080
2023-11-211799.331799.331783.261783.260
2023-11-221796.371804.961785.931792.920
\n", "

752 rows × 5 columns

\n", "
" ], "text/plain": [ " open high low close volume\n", "date \n", "2020-11-27 1846.26 1855.27 1845.50 1855.27 0\n", "2020-11-30 1854.87 1854.87 1813.56 1819.82 0\n", "2020-12-01 1822.92 1848.02 1822.92 1836.05 0\n", "2020-12-02 1833.08 1842.53 1817.02 1838.03 0\n", "2020-12-03 1838.52 1860.35 1838.52 1848.70 0\n", "... ... ... ... ... ...\n", "2023-11-16 1797.00 1797.00 1767.42 1773.76 0\n", "2023-11-17 1784.86 1798.44 1784.86 1797.77 0\n", "2023-11-20 1798.56 1809.21 1794.71 1807.08 0\n", "2023-11-21 1799.33 1799.33 1783.26 1783.26 0\n", "2023-11-22 1796.37 1804.96 1785.93 1792.92 0\n", "\n", "[752 rows x 5 columns]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "obb.equity.price.historical(\"^RUT\", provider=\"cboe\").to_df()\n" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "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", "
openhighlowclosevolumevwaplabeladj_closeunadjusted_volumechangechange_percentchange_over_time
date
2022-11-221843.8699951861.0799561840.0400391860.43994138879900001853.85November 22, 221860.4399413.887990e+0916.569950.898650.008986
2022-11-231857.5899661868.9200441851.6800541863.52002032797200001861.37November 23, 221863.5200203.279720e+095.930050.319230.003192
2022-11-251862.9200441873.5899661861.0000001869.18994117064600001867.93November 25, 221869.1899411.706460e+096.269900.336560.003366
2022-11-281857.1800541857.5200201827.0799561830.95996136154300001838.52November 28, 221830.9599613.615430e+09-26.22009-1.41000-0.014100
2022-11-291832.5200201846.0699461832.5200201836.55004935460400001838.38November 29, 221836.5500493.546040e+094.030030.219920.002199
.......................................
2023-11-161797.0000001797.0000001767.4200401773.76001039645200001783.80November 16, 231773.7600103.964520e+09-23.23999-1.29000-0.012900
2023-11-171784.8599901798.4399401784.8599901797.77002037772400001791.48November 17, 231797.7700203.777240e+0912.910030.723310.007233
2023-11-201798.5600601809.2099601794.7099601807.07996036447900001802.39November 20, 231807.0799603.644790e+098.519900.473710.004737
2023-11-211799.3299601799.3299601783.2600101783.26001035110800001791.29November 21, 231783.2600103.511080e+09-16.06995-0.89311-0.008931
2023-11-221792.5114801803.1167001789.8768301795.54041001796.18November 22, 231795.5404100.000000e+003.028930.168980.001690
\n", "

252 rows × 12 columns

\n", "
" ], "text/plain": [ " open high low close volume \\\n", "date \n", "2022-11-22 1843.869995 1861.079956 1840.040039 1860.439941 3887990000 \n", "2022-11-23 1857.589966 1868.920044 1851.680054 1863.520020 3279720000 \n", "2022-11-25 1862.920044 1873.589966 1861.000000 1869.189941 1706460000 \n", "2022-11-28 1857.180054 1857.520020 1827.079956 1830.959961 3615430000 \n", "2022-11-29 1832.520020 1846.069946 1832.520020 1836.550049 3546040000 \n", "... ... ... ... ... ... \n", "2023-11-16 1797.000000 1797.000000 1767.420040 1773.760010 3964520000 \n", "2023-11-17 1784.859990 1798.439940 1784.859990 1797.770020 3777240000 \n", "2023-11-20 1798.560060 1809.209960 1794.709960 1807.079960 3644790000 \n", "2023-11-21 1799.329960 1799.329960 1783.260010 1783.260010 3511080000 \n", "2023-11-22 1792.511480 1803.116700 1789.876830 1795.540410 0 \n", "\n", " vwap label adj_close unadjusted_volume \\\n", "date \n", "2022-11-22 1853.85 November 22, 22 1860.439941 3.887990e+09 \n", "2022-11-23 1861.37 November 23, 22 1863.520020 3.279720e+09 \n", "2022-11-25 1867.93 November 25, 22 1869.189941 1.706460e+09 \n", "2022-11-28 1838.52 November 28, 22 1830.959961 3.615430e+09 \n", "2022-11-29 1838.38 November 29, 22 1836.550049 3.546040e+09 \n", "... ... ... ... ... \n", "2023-11-16 1783.80 November 16, 23 1773.760010 3.964520e+09 \n", "2023-11-17 1791.48 November 17, 23 1797.770020 3.777240e+09 \n", "2023-11-20 1802.39 November 20, 23 1807.079960 3.644790e+09 \n", "2023-11-21 1791.29 November 21, 23 1783.260010 3.511080e+09 \n", "2023-11-22 1796.18 November 22, 23 1795.540410 0.000000e+00 \n", "\n", " change change_percent change_over_time \n", "date \n", "2022-11-22 16.56995 0.89865 0.008986 \n", "2022-11-23 5.93005 0.31923 0.003192 \n", "2022-11-25 6.26990 0.33656 0.003366 \n", "2022-11-28 -26.22009 -1.41000 -0.014100 \n", "2022-11-29 4.03003 0.21992 0.002199 \n", "... ... ... ... \n", "2023-11-16 -23.23999 -1.29000 -0.012900 \n", "2023-11-17 12.91003 0.72331 0.007233 \n", "2023-11-20 8.51990 0.47371 0.004737 \n", "2023-11-21 -16.06995 -0.89311 -0.008931 \n", "2023-11-22 3.02893 0.16898 0.001690 \n", "\n", "[252 rows x 12 columns]" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "obb.equity.price.historical(\"^RUT\", provider=\"fmp\").to_df()\n" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "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", "
openhighlowclosevolumedividendsstock splits
date
2022-11-2272.0072.5071.7071.9161010.00.0
2022-11-2372.0172.1270.5371.33105130.00.0
2022-11-2571.2172.2170.5570.6656090.00.0
2022-11-2870.5071.5369.2671.21124090.00.0
2022-11-2970.8072.5370.6171.77144180.00.0
........................
2023-11-1673.9474.1070.9471.34581590.00.0
2023-11-1771.3773.6971.2173.58366440.00.0
2023-11-2073.0575.3973.0574.98382850.00.0
2023-11-2174.6575.0574.3974.98262770.00.0
2023-11-2274.0774.0773.4173.616110.00.0
\n", "

252 rows × 7 columns

\n", "
" ], "text/plain": [ " open high low close volume dividends stock splits\n", "date \n", "2022-11-22 72.00 72.50 71.70 71.91 6101 0.0 0.0\n", "2022-11-23 72.01 72.12 70.53 71.33 10513 0.0 0.0\n", "2022-11-25 71.21 72.21 70.55 70.66 5609 0.0 0.0\n", "2022-11-28 70.50 71.53 69.26 71.21 12409 0.0 0.0\n", "2022-11-29 70.80 72.53 70.61 71.77 14418 0.0 0.0\n", "... ... ... ... ... ... ... ...\n", "2023-11-16 73.94 74.10 70.94 71.34 58159 0.0 0.0\n", "2023-11-17 71.37 73.69 71.21 73.58 36644 0.0 0.0\n", "2023-11-20 73.05 75.39 73.05 74.98 38285 0.0 0.0\n", "2023-11-21 74.65 75.05 74.39 74.98 26277 0.0 0.0\n", "2023-11-22 74.07 74.07 73.41 73.61 611 0.0 0.0\n", "\n", "[252 rows x 7 columns]" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "obb.equity.price.historical(\"CLZ24.NYM\", provider=\"yfinance\").to_df()\n" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "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", "
openhighlowclosevolumevwaplabeladj_closeunadjusted_volumechangechange_percentchange_over_time
date
2022-11-2280.2282.3679.8580.9526961581.05November 22, 2280.949997269615.00.730.910000.009100
2022-11-2381.0881.9576.8377.9437914578.91November 23, 2277.940002379145.0-3.14-3.87000-0.038700
2022-11-2577.5179.9076.2276.2826645177.47November 25, 2276.279999266451.0-1.23-1.59000-0.015900
2022-11-2875.9377.8473.6077.2440503376.23November 28, 2277.239998405033.01.311.730000.017300
2022-11-2976.5479.6576.2978.2038186978.05November 29, 2278.199997381869.01.662.170000.021700
.......................................
2023-11-1772.9775.9972.7575.8910148474.88November 17, 2375.890000101484.02.924.000000.040000
2023-11-1975.6575.8075.6575.801075.75November 19, 2375.80000010.00.150.198280.001983
2023-11-2075.6578.2275.6577.6027063877.16November 20, 2377.600000270638.01.952.580000.025800
2023-11-2177.6577.9276.9277.7727063877.54November 21, 2377.770000270638.00.120.154540.001545
2023-11-2277.7777.9773.7976.7836868676.18November 22, 2376.780000368686.0-0.99-1.27000-0.012700
\n", "

277 rows × 12 columns

\n", "
" ], "text/plain": [ " open high low close volume vwap label \\\n", "date \n", "2022-11-22 80.22 82.36 79.85 80.95 269615 81.05 November 22, 22 \n", "2022-11-23 81.08 81.95 76.83 77.94 379145 78.91 November 23, 22 \n", "2022-11-25 77.51 79.90 76.22 76.28 266451 77.47 November 25, 22 \n", "2022-11-28 75.93 77.84 73.60 77.24 405033 76.23 November 28, 22 \n", "2022-11-29 76.54 79.65 76.29 78.20 381869 78.05 November 29, 22 \n", "... ... ... ... ... ... ... ... \n", "2023-11-17 72.97 75.99 72.75 75.89 101484 74.88 November 17, 23 \n", "2023-11-19 75.65 75.80 75.65 75.80 10 75.75 November 19, 23 \n", "2023-11-20 75.65 78.22 75.65 77.60 270638 77.16 November 20, 23 \n", "2023-11-21 77.65 77.92 76.92 77.77 270638 77.54 November 21, 23 \n", "2023-11-22 77.77 77.97 73.79 76.78 368686 76.18 November 22, 23 \n", "\n", " adj_close unadjusted_volume change change_percent \\\n", "date \n", "2022-11-22 80.949997 269615.0 0.73 0.91000 \n", "2022-11-23 77.940002 379145.0 -3.14 -3.87000 \n", "2022-11-25 76.279999 266451.0 -1.23 -1.59000 \n", "2022-11-28 77.239998 405033.0 1.31 1.73000 \n", "2022-11-29 78.199997 381869.0 1.66 2.17000 \n", "... ... ... ... ... \n", "2023-11-17 75.890000 101484.0 2.92 4.00000 \n", "2023-11-19 75.800000 10.0 0.15 0.19828 \n", "2023-11-20 77.600000 270638.0 1.95 2.58000 \n", "2023-11-21 77.770000 270638.0 0.12 0.15454 \n", "2023-11-22 76.780000 368686.0 -0.99 -1.27000 \n", "\n", " change_over_time \n", "date \n", "2022-11-22 0.009100 \n", "2022-11-23 -0.038700 \n", "2022-11-25 -0.015900 \n", "2022-11-28 0.017300 \n", "2022-11-29 0.021700 \n", "... ... \n", "2023-11-17 0.040000 \n", "2023-11-19 0.001983 \n", "2023-11-20 0.025800 \n", "2023-11-21 0.001545 \n", "2023-11-22 -0.012700 \n", "\n", "[277 rows x 12 columns]" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "obb.equity.price.historical(\"CL=F\", provider=\"fmp\").to_df()\n" ] } ], "metadata": { "kernelspec": { "display_name": "obb", "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.11.4" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }