mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 20:42:26 +00:00
* development index * refactor development section of documentation * codespell * add template zip file * fixing * update changed syntax * dependency thing * fix sentence * review edits, add_toolkit_extension * Add ZIp file * headtitle * couple more things * codespell * fix sentence * url fix * review updates * forgot one file in the commit * syntax updates * json file * more syntax things --------- Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com> Co-authored-by: James Maslek <jmaslek11@gmail.com>
1062 lines
36 KiB
Plaintext
Vendored
1062 lines
36 KiB
Plaintext
Vendored
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"# Financial Statements in the OpenBB Platform\n",
|
||
"\n",
|
||
"OpenBB Platform data extensions provide access to financial statements as quarterly or annual. There are also endpoints for ratios and other common non-GAAP metrics. Most data providers require a subscription to access all data. Refer to the website of a specific provider for details on entitlements and coverage.\n",
|
||
"\n",
|
||
"Financial statement functions are grouped under the `obb.equity.fundamental` module.\n",
|
||
"\n",
|
||
"## Endpoints\n",
|
||
"\n",
|
||
"The typical financial statements consist of three endpoints:\n",
|
||
"\n",
|
||
"- Balance Sheet: `obb.equity.fundamental.balance()`\n",
|
||
"- Income Statement: `obb.equity.fundamental.income()`\n",
|
||
"- Cash Flow Statement: `obb.equity.fundamental.cash()`\n",
|
||
"\n",
|
||
"The main parameters are:\n",
|
||
"\n",
|
||
"- `symbol`: The company's symbol.\n",
|
||
"- `period`: 'annual' or 'quarter'. Default is 'annual'.\n",
|
||
"- `limit`: Limit the number of results returned, from the latest. Default is 5. For perspective, 150 will go back to 1985. The amount of historical records varies by provider.\n",
|
||
"\n",
|
||
"### Field Names\n",
|
||
"\n",
|
||
"Some considerations to keep in mind when working with financial statements data are:\n",
|
||
"\n",
|
||
"- Every data provider has their own way of parsing and organizing the three financial statements.\n",
|
||
"- Items within each statement will vary by source and by the type of company reporting.\n",
|
||
"- Names of line items will vary by source.\n",
|
||
"- \"Date\" values may differ because they are from the period starting/ending or date of reporting.\n",
|
||
"\n",
|
||
"This example highlights how different providers will have different labels for compnay facts."
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 1,
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/html": [
|
||
"<div>\n",
|
||
"<style scoped>\n",
|
||
" .dataframe tbody tr th:only-of-type {\n",
|
||
" vertical-align: middle;\n",
|
||
" }\n",
|
||
"\n",
|
||
" .dataframe tbody tr th {\n",
|
||
" vertical-align: top;\n",
|
||
" }\n",
|
||
"\n",
|
||
" .dataframe thead th {\n",
|
||
" text-align: right;\n",
|
||
" }\n",
|
||
"</style>\n",
|
||
"<table border=\"1\" class=\"dataframe\">\n",
|
||
" <thead>\n",
|
||
" <tr style=\"text-align: right;\">\n",
|
||
" <th></th>\n",
|
||
" <th>yfinance</th>\n",
|
||
" <th>fmp</th>\n",
|
||
" <th>intrinio</th>\n",
|
||
" <th>polygon</th>\n",
|
||
" </tr>\n",
|
||
" </thead>\n",
|
||
" <tbody>\n",
|
||
" <tr>\n",
|
||
" <th>0</th>\n",
|
||
" <td>42779000000</td>\n",
|
||
" <td>42779000000</td>\n",
|
||
" <td>42779000000</td>\n",
|
||
" <td>42779000000</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>1</th>\n",
|
||
" <td>51248000000</td>\n",
|
||
" <td>51248000000</td>\n",
|
||
" <td>51248000000</td>\n",
|
||
" <td>51248000000</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>2</th>\n",
|
||
" <td>53811000000</td>\n",
|
||
" <td>53811000000</td>\n",
|
||
" <td>53811000000</td>\n",
|
||
" <td>53811000000</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>3</th>\n",
|
||
" <td>53335000000</td>\n",
|
||
" <td>53335000000</td>\n",
|
||
" <td>53335000000</td>\n",
|
||
" <td>53335000000</td>\n",
|
||
" </tr>\n",
|
||
" </tbody>\n",
|
||
"</table>\n",
|
||
"</div>"
|
||
],
|
||
"text/plain": [
|
||
" yfinance fmp intrinio polygon\n",
|
||
"0 42779000000 42779000000 42779000000 42779000000\n",
|
||
"1 51248000000 51248000000 51248000000 51248000000\n",
|
||
"2 53811000000 53811000000 53811000000 53811000000\n",
|
||
"3 53335000000 53335000000 53335000000 53335000000"
|
||
]
|
||
},
|
||
"execution_count": 1,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"import pandas as pd\n",
|
||
"\n",
|
||
"df = pd.DataFrame()\n",
|
||
"\n",
|
||
"df[\"yfinance\"] = (\n",
|
||
" obb.equity.fundamental.balance(\"TGT\", provider=\"yfinance\", limit=3)\n",
|
||
" .to_df().get(\"total_assets\")\n",
|
||
")\n",
|
||
"\n",
|
||
"df[\"fmp\"] = (\n",
|
||
" obb.equity.fundamental.balance(\"TGT\", provider=\"fmp\", limit=3)\n",
|
||
" .to_df().get(\"total_assets\")\n",
|
||
")\n",
|
||
"\n",
|
||
"df[\"intrinio\"] = (\n",
|
||
" obb.equity.fundamental.balance(\"TGT\", provider=\"intrinio\", limit=3)\n",
|
||
" .to_df().get(\"total_assets\")\n",
|
||
")\n",
|
||
"\n",
|
||
"df[\"polygon\"] = (\n",
|
||
" obb.equity.fundamental.balance(\"TGT\", provider=\"polygon\", limit=3)\n",
|
||
" .to_df().get(\"total_assets\")\n",
|
||
")\n",
|
||
"\n",
|
||
"df\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"### Weighted Average Shares Outstanding\n",
|
||
"\n",
|
||
"This key metric will be found under the income statement. It might also be called, 'basic', and the numbers do not include authorized but unissued shares. A declining count over time is a sign that the company is returning capital to shareholders in the form of buy backs. Under ideal circumstances, it is more capital-efficient, for both company and shareholders, because distributions are double-taxed. The company pays income tax on paid dividends, and the beneficiary pays income tax again on receipt.\n",
|
||
"\n",
|
||
"A company will disclose how many shares are outstanding at the end of the period as a weighted average over the reporting period - three months.\n",
|
||
"\n",
|
||
"Let's take a look at Target. To make the numbers easier to read, we'll divide the entire column by one million."
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 2,
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"date\n",
|
||
"1986-07-31 1168.816\n",
|
||
"Name: weighted_average_shares_outstanding, dtype: float64"
|
||
]
|
||
},
|
||
"metadata": {},
|
||
"output_type": "display_data"
|
||
},
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"date\n",
|
||
"2023-10-31 461.6\n",
|
||
"Name: weighted_average_shares_outstanding, dtype: float64"
|
||
]
|
||
},
|
||
"metadata": {},
|
||
"output_type": "display_data"
|
||
}
|
||
],
|
||
"source": [
|
||
"data = (\n",
|
||
" obb.equity.fundamental.income(\"TGT\", provider='fmp', limit=150, period=\"quarter\")\n",
|
||
" .to_df()\n",
|
||
")\n",
|
||
"\n",
|
||
"shares = data[\"weighted_average_basic_shares_outstanding\"]/1000000\n",
|
||
"\n",
|
||
"display(shares.head(1))\n",
|
||
"\n",
|
||
"display(shares.tail(1))\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"Thirty-seven years later, the share count is approaching a two-thirds reduction. 12.2% over the past five years. In four reporting periods, 1.3 million shares have been taken out of the float."
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 3,
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"-0.12226659060657907"
|
||
]
|
||
},
|
||
"metadata": {},
|
||
"output_type": "display_data"
|
||
},
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"-1.3000000000000114"
|
||
]
|
||
},
|
||
"metadata": {},
|
||
"output_type": "display_data"
|
||
}
|
||
],
|
||
"source": [
|
||
"display(shares.pct_change(20).iloc[-1])\n",
|
||
"\n",
|
||
"display(shares.iloc[-4] - shares.iloc[-1])\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"With an average closing price of $143.37, that represents approximately $190M in buy backs."
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 4,
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"187.55"
|
||
]
|
||
},
|
||
"execution_count": 4,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"price = (\n",
|
||
" obb.equity.price.historical(\"TGT\", start_date=\"2022-10-01\", provider=\"fmp\")\n",
|
||
" .to_df()\n",
|
||
")\n",
|
||
"\n",
|
||
"round((price[\"close\"].mean()*1300000)/1000000, 2)\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"### Dividends Paid\n",
|
||
"\n",
|
||
"Dividends paid is in the cash flow statement. We can calculate the amount-per-share with the reported data."
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 5,
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"date\n",
|
||
"2023-01-28 -1.079731\n",
|
||
"2023-04-29 -1.078325\n",
|
||
"2023-07-29 -1.081023\n",
|
||
"2023-10-31 -1.098354\n",
|
||
"Name: div_per_share, dtype: float64"
|
||
]
|
||
},
|
||
"execution_count": 5,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"dividends = (\n",
|
||
" obb.equity.fundamental.cash(\"TGT\", provider='fmp', limit=150, period=\"quarter\")\n",
|
||
" .to_df()[[\"payment_of_dividends\"]]\n",
|
||
")\n",
|
||
"\n",
|
||
"dividends[\"shares\"] = data[[\"weighted_average_basic_shares_outstanding\"]]\n",
|
||
"dividends[\"div_per_share\"] = abs(dividends[\"payment_of_dividends\"]/dividends[\"shares\"])\n",
|
||
"\n",
|
||
"dividends[\"div_per_share\"].tail(4)\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"This can be compared against the real amounts paid to common share holders, as announced. Note that the dates above represent the report date, and that dividends paid are attributed to the quarter they were paid in. The value from \"2023-01-28\" equates to the fourth quarter of 2022."
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 6,
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"date\n",
|
||
"2022-11-15 1.08\n",
|
||
"2023-02-14 1.08\n",
|
||
"2023-05-16 1.08\n",
|
||
"2023-08-15 1.10\n",
|
||
"Name: dividend, dtype: float64"
|
||
]
|
||
},
|
||
"execution_count": 6,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"data = (\n",
|
||
" obb.equity.fundamental.dividends(\"TGT\", provider=\"fmp\")\n",
|
||
" .to_df()\n",
|
||
" [[\"ex_dividend_date\", \"amount\"]]\n",
|
||
")\n",
|
||
"data.ex_dividend_date = data.ex_dividend_date.astype(str)\n",
|
||
"data.set_index(\"ex_dividend_date\").loc[\"2023-08-15\": \"2022-11-15\"]\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"The numbers check out, and the $2B paid to investors over four quarters is more than ten times the $190M returned through share buy backs.\n",
|
||
"\n",
|
||
"### Financial Attributes\n",
|
||
"\n",
|
||
"The `openbb-intrinio` data extension has an endpoint for extracting a single fact from financial statements. There is a helper function for looking up the correct `tag`.\n",
|
||
"\n",
|
||
"#### Search Financial Attributes\n",
|
||
"\n",
|
||
"Search attributes by keyword."
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 7,
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/html": [
|
||
"<div>\n",
|
||
"<style scoped>\n",
|
||
" .dataframe tbody tr th:only-of-type {\n",
|
||
" vertical-align: middle;\n",
|
||
" }\n",
|
||
"\n",
|
||
" .dataframe tbody tr th {\n",
|
||
" vertical-align: top;\n",
|
||
" }\n",
|
||
"\n",
|
||
" .dataframe thead th {\n",
|
||
" text-align: right;\n",
|
||
" }\n",
|
||
"</style>\n",
|
||
"<table border=\"1\" class=\"dataframe\">\n",
|
||
" <thead>\n",
|
||
" <tr style=\"text-align: right;\">\n",
|
||
" <th></th>\n",
|
||
" <th>id</th>\n",
|
||
" <th>name</th>\n",
|
||
" <th>tag</th>\n",
|
||
" <th>statement_code</th>\n",
|
||
" <th>statement_type</th>\n",
|
||
" <th>parent_name</th>\n",
|
||
" <th>sequence</th>\n",
|
||
" <th>factor</th>\n",
|
||
" <th>transaction</th>\n",
|
||
" <th>type</th>\n",
|
||
" <th>unit</th>\n",
|
||
" </tr>\n",
|
||
" </thead>\n",
|
||
" <tbody>\n",
|
||
" <tr>\n",
|
||
" <th>0</th>\n",
|
||
" <td>tag_BgkbWy</td>\n",
|
||
" <td>Market Capitalization</td>\n",
|
||
" <td>marketcap</td>\n",
|
||
" <td>calculations</td>\n",
|
||
" <td>industrial</td>\n",
|
||
" <td>None</td>\n",
|
||
" <td>NaN</td>\n",
|
||
" <td>None</td>\n",
|
||
" <td>None</td>\n",
|
||
" <td>valuation</td>\n",
|
||
" <td>usd</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>1</th>\n",
|
||
" <td>tag_kylOqz</td>\n",
|
||
" <td>Market Capitalization</td>\n",
|
||
" <td>marketcap</td>\n",
|
||
" <td>calculations</td>\n",
|
||
" <td>financial</td>\n",
|
||
" <td>None</td>\n",
|
||
" <td>NaN</td>\n",
|
||
" <td>None</td>\n",
|
||
" <td>None</td>\n",
|
||
" <td>valuation</td>\n",
|
||
" <td>usd</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>2</th>\n",
|
||
" <td>tag_XLRlqy</td>\n",
|
||
" <td>Market Sector</td>\n",
|
||
" <td>market_sector</td>\n",
|
||
" <td>current</td>\n",
|
||
" <td>None</td>\n",
|
||
" <td>None</td>\n",
|
||
" <td>NaN</td>\n",
|
||
" <td>None</td>\n",
|
||
" <td>None</td>\n",
|
||
" <td>security</td>\n",
|
||
" <td>string</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>3</th>\n",
|
||
" <td>tag_2gBA8y</td>\n",
|
||
" <td>Market Category</td>\n",
|
||
" <td>market_category</td>\n",
|
||
" <td>current</td>\n",
|
||
" <td>None</td>\n",
|
||
" <td>None</td>\n",
|
||
" <td>NaN</td>\n",
|
||
" <td>None</td>\n",
|
||
" <td>None</td>\n",
|
||
" <td>security</td>\n",
|
||
" <td>string</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>4</th>\n",
|
||
" <td>tag_DzonXe</td>\n",
|
||
" <td>Marketing Expense</td>\n",
|
||
" <td>marketingexpense</td>\n",
|
||
" <td>income_statement</td>\n",
|
||
" <td>industrial</td>\n",
|
||
" <td>totaloperatingexpenses</td>\n",
|
||
" <td>9.0</td>\n",
|
||
" <td>+</td>\n",
|
||
" <td>debit</td>\n",
|
||
" <td>income_statement_metric</td>\n",
|
||
" <td>usd</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>...</th>\n",
|
||
" <td>...</td>\n",
|
||
" <td>...</td>\n",
|
||
" <td>...</td>\n",
|
||
" <td>...</td>\n",
|
||
" <td>...</td>\n",
|
||
" <td>...</td>\n",
|
||
" <td>...</td>\n",
|
||
" <td>...</td>\n",
|
||
" <td>...</td>\n",
|
||
" <td>...</td>\n",
|
||
" <td>...</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>95</th>\n",
|
||
" <td>tag_nzJAmX</td>\n",
|
||
" <td>Total Long-Term Debt</td>\n",
|
||
" <td>ltdebtandcapleases</td>\n",
|
||
" <td>calculations</td>\n",
|
||
" <td>financial</td>\n",
|
||
" <td>None</td>\n",
|
||
" <td>NaN</td>\n",
|
||
" <td>None</td>\n",
|
||
" <td>None</td>\n",
|
||
" <td>metric</td>\n",
|
||
" <td>usd</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>96</th>\n",
|
||
" <td>tag_9XaL5g</td>\n",
|
||
" <td>Other Net Changes in Cash</td>\n",
|
||
" <td>othernetchangesincash</td>\n",
|
||
" <td>cash_flow_statement</td>\n",
|
||
" <td>industrial</td>\n",
|
||
" <td>netchangeincash</td>\n",
|
||
" <td>33.0</td>\n",
|
||
" <td>+</td>\n",
|
||
" <td>debit</td>\n",
|
||
" <td>cash_flow_statement_metric</td>\n",
|
||
" <td>usd</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>97</th>\n",
|
||
" <td>tag_5X7p6z</td>\n",
|
||
" <td>Other Net Changes in Cash</td>\n",
|
||
" <td>othernetchangesincash</td>\n",
|
||
" <td>cash_flow_statement</td>\n",
|
||
" <td>financial</td>\n",
|
||
" <td>netchangeincash</td>\n",
|
||
" <td>37.0</td>\n",
|
||
" <td>+</td>\n",
|
||
" <td>debit</td>\n",
|
||
" <td>cash_flow_statement_metric</td>\n",
|
||
" <td>usd</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>98</th>\n",
|
||
" <td>tag_qzEwng</td>\n",
|
||
" <td>Changes in Operating Assets and Liabilities, net</td>\n",
|
||
" <td>increasedecreaseinoperatingcapital</td>\n",
|
||
" <td>cash_flow_statement</td>\n",
|
||
" <td>financial</td>\n",
|
||
" <td>netcashfromcontinuingoperatingactivities</td>\n",
|
||
" <td>8.0</td>\n",
|
||
" <td>+</td>\n",
|
||
" <td>debit</td>\n",
|
||
" <td>cash_flow_statement_metric</td>\n",
|
||
" <td>usd</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>99</th>\n",
|
||
" <td>tag_pgVB2g</td>\n",
|
||
" <td>Changes in Operating Assets and Liabilities, net</td>\n",
|
||
" <td>increasedecreaseinoperatingcapital</td>\n",
|
||
" <td>cash_flow_statement</td>\n",
|
||
" <td>industrial</td>\n",
|
||
" <td>netcashfromcontinuingoperatingactivities</td>\n",
|
||
" <td>7.0</td>\n",
|
||
" <td>+</td>\n",
|
||
" <td>debit</td>\n",
|
||
" <td>cash_flow_statement_metric</td>\n",
|
||
" <td>usd</td>\n",
|
||
" </tr>\n",
|
||
" </tbody>\n",
|
||
"</table>\n",
|
||
"<p>100 rows × 11 columns</p>\n",
|
||
"</div>"
|
||
],
|
||
"text/plain": [
|
||
" id name \\\n",
|
||
"0 tag_BgkbWy Market Capitalization \n",
|
||
"1 tag_kylOqz Market Capitalization \n",
|
||
"2 tag_XLRlqy Market Sector \n",
|
||
"3 tag_2gBA8y Market Category \n",
|
||
"4 tag_DzonXe Marketing Expense \n",
|
||
".. ... ... \n",
|
||
"95 tag_nzJAmX Total Long-Term Debt \n",
|
||
"96 tag_9XaL5g Other Net Changes in Cash \n",
|
||
"97 tag_5X7p6z Other Net Changes in Cash \n",
|
||
"98 tag_qzEwng Changes in Operating Assets and Liabilities, net \n",
|
||
"99 tag_pgVB2g Changes in Operating Assets and Liabilities, net \n",
|
||
"\n",
|
||
" tag statement_code statement_type \\\n",
|
||
"0 marketcap calculations industrial \n",
|
||
"1 marketcap calculations financial \n",
|
||
"2 market_sector current None \n",
|
||
"3 market_category current None \n",
|
||
"4 marketingexpense income_statement industrial \n",
|
||
".. ... ... ... \n",
|
||
"95 ltdebtandcapleases calculations financial \n",
|
||
"96 othernetchangesincash cash_flow_statement industrial \n",
|
||
"97 othernetchangesincash cash_flow_statement financial \n",
|
||
"98 increasedecreaseinoperatingcapital cash_flow_statement financial \n",
|
||
"99 increasedecreaseinoperatingcapital cash_flow_statement industrial \n",
|
||
"\n",
|
||
" parent_name sequence factor transaction \\\n",
|
||
"0 None NaN None None \n",
|
||
"1 None NaN None None \n",
|
||
"2 None NaN None None \n",
|
||
"3 None NaN None None \n",
|
||
"4 totaloperatingexpenses 9.0 + debit \n",
|
||
".. ... ... ... ... \n",
|
||
"95 None NaN None None \n",
|
||
"96 netchangeincash 33.0 + debit \n",
|
||
"97 netchangeincash 37.0 + debit \n",
|
||
"98 netcashfromcontinuingoperatingactivities 8.0 + debit \n",
|
||
"99 netcashfromcontinuingoperatingactivities 7.0 + debit \n",
|
||
"\n",
|
||
" type unit \n",
|
||
"0 valuation usd \n",
|
||
"1 valuation usd \n",
|
||
"2 security string \n",
|
||
"3 security string \n",
|
||
"4 income_statement_metric usd \n",
|
||
".. ... ... \n",
|
||
"95 metric usd \n",
|
||
"96 cash_flow_statement_metric usd \n",
|
||
"97 cash_flow_statement_metric usd \n",
|
||
"98 cash_flow_statement_metric usd \n",
|
||
"99 cash_flow_statement_metric usd \n",
|
||
"\n",
|
||
"[100 rows x 11 columns]"
|
||
]
|
||
},
|
||
"execution_count": 7,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"(\n",
|
||
" obb.equity.fundamental.search_attributes(\"marketcap\")\n",
|
||
" .to_df()\n",
|
||
")\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"The `tag` is what we need, in this case it is what we searched for."
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 8,
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/html": [
|
||
"<div>\n",
|
||
"<style scoped>\n",
|
||
" .dataframe tbody tr th:only-of-type {\n",
|
||
" vertical-align: middle;\n",
|
||
" }\n",
|
||
"\n",
|
||
" .dataframe tbody tr th {\n",
|
||
" vertical-align: top;\n",
|
||
" }\n",
|
||
"\n",
|
||
" .dataframe thead th {\n",
|
||
" text-align: right;\n",
|
||
" }\n",
|
||
"</style>\n",
|
||
"<table border=\"1\" class=\"dataframe\">\n",
|
||
" <thead>\n",
|
||
" <tr style=\"text-align: right;\">\n",
|
||
" <th></th>\n",
|
||
" <th>value</th>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>date</th>\n",
|
||
" <th></th>\n",
|
||
" </tr>\n",
|
||
" </thead>\n",
|
||
" <tbody>\n",
|
||
" <tr>\n",
|
||
" <th>2022-12-31</th>\n",
|
||
" <td>6.692963e+10</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>2023-03-31</th>\n",
|
||
" <td>7.502370e+10</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>2023-06-30</th>\n",
|
||
" <td>5.991695e+10</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>2023-09-30</th>\n",
|
||
" <td>5.061437e+10</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>2023-11-22</th>\n",
|
||
" <td>6.049500e+10</td>\n",
|
||
" </tr>\n",
|
||
" </tbody>\n",
|
||
"</table>\n",
|
||
"</div>"
|
||
],
|
||
"text/plain": [
|
||
" value\n",
|
||
"date \n",
|
||
"2022-12-31 6.692963e+10\n",
|
||
"2023-03-31 7.502370e+10\n",
|
||
"2023-06-30 5.991695e+10\n",
|
||
"2023-09-30 5.061437e+10\n",
|
||
"2023-11-22 6.049500e+10"
|
||
]
|
||
},
|
||
"execution_count": 8,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"marketcap = (\n",
|
||
" obb.equity.fundamental.historical_attributes(symbol=\"TGT\", tag = \"marketcap\", period=\"quarter\")\n",
|
||
" .to_df()\n",
|
||
")\n",
|
||
"\n",
|
||
"marketcap.tail(5)\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"Doing some quick math, and ignoring the most recent value, we can see that the market cap of Target was down nearly a quarter over the last four reporting periods."
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 9,
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"-0.24376733082703084"
|
||
]
|
||
},
|
||
"execution_count": 9,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"marketcap.index = marketcap.index.astype(str)\n",
|
||
"(\n",
|
||
" (marketcap.loc[\"2023-09-30\"].value - marketcap.loc[\"2022-12-31\"].value)/marketcap.loc[\"2022-12-31\"].value\n",
|
||
")"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"## Ratios and Other Metrics\n",
|
||
"\n",
|
||
"Other valuation functions are derivatives of the financial statements, but the data provider does the math. Values are typically ratios between line items, on a per-share basis, or as a percent growth.\n",
|
||
"\n",
|
||
"This data set is where you can find EPS, FCF, P/B, EBIT, quick ratio, etc.\n",
|
||
"\n",
|
||
"### Quick Ratio\n",
|
||
"\n",
|
||
"Target's quick ratio could be one reason why its share price is losing traction against the market. Its ability to pay current obligations is not optimistically reflected in a 0.27 score, approximately 50% below the historical median."
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 28,
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"'Current Quick Ratio: 0.2701'"
|
||
]
|
||
},
|
||
"metadata": {},
|
||
"output_type": "display_data"
|
||
},
|
||
{
|
||
"data": {
|
||
"text/plain": [
|
||
"'Median Quick Ratio: 0.5844'"
|
||
]
|
||
},
|
||
"metadata": {},
|
||
"output_type": "display_data"
|
||
}
|
||
],
|
||
"source": [
|
||
"ratios = (\n",
|
||
" obb.equity.fundamental.ratios(\"TGT\", limit=50, provider=\"fmp\")\n",
|
||
" .to_df()\n",
|
||
")\n",
|
||
"\n",
|
||
"display(f\"Current Quick Ratio: {round(ratios['quick_ratio'].iloc[-1], 4)}\")\n",
|
||
"display(f\"Median Quick Ratio: {round(ratios['quick_ratio'].median(), 4)}\")\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"### Free Cash Flow Yield\n",
|
||
"\n",
|
||
"The `metrics` endpoint, with the `openbb-fmp` data extension, has a field for free cash flow yield. It is calculated by taking the free cash flow per share divided by the current share price. We could arrive at this answer by writing some code, but these types of endpoints do the work so we don't have to. This is part of the value-add that API data distributors provide, they allow you to get straight to work with data.\n",
|
||
"\n",
|
||
"We'll use this endpoint to extract the data, and compare with some of Target's competition over the last ten years."
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 26,
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"data": {
|
||
"text/html": [
|
||
"<div>\n",
|
||
"<style scoped>\n",
|
||
" .dataframe tbody tr th:only-of-type {\n",
|
||
" vertical-align: middle;\n",
|
||
" }\n",
|
||
"\n",
|
||
" .dataframe tbody tr th {\n",
|
||
" vertical-align: top;\n",
|
||
" }\n",
|
||
"\n",
|
||
" .dataframe thead th {\n",
|
||
" text-align: right;\n",
|
||
" }\n",
|
||
"</style>\n",
|
||
"<table border=\"1\" class=\"dataframe\">\n",
|
||
" <thead>\n",
|
||
" <tr style=\"text-align: right;\">\n",
|
||
" <th>calendar_year</th>\n",
|
||
" <th>2023</th>\n",
|
||
" <th>2022</th>\n",
|
||
" <th>2021</th>\n",
|
||
" <th>2020</th>\n",
|
||
" <th>2019</th>\n",
|
||
" <th>2018</th>\n",
|
||
" <th>2017</th>\n",
|
||
" <th>2016</th>\n",
|
||
" <th>2015</th>\n",
|
||
" <th>2014</th>\n",
|
||
" </tr>\n",
|
||
" </thead>\n",
|
||
" <tbody>\n",
|
||
" <tr>\n",
|
||
" <th>Costco Wholesale Corporation</th>\n",
|
||
" <td>0.027922</td>\n",
|
||
" <td>0.014860</td>\n",
|
||
" <td>0.026582</td>\n",
|
||
" <td>0.039351</td>\n",
|
||
" <td>0.025906</td>\n",
|
||
" <td>0.027438</td>\n",
|
||
" <td>0.060884</td>\n",
|
||
" <td>0.008941</td>\n",
|
||
" <td>0.030741</td>\n",
|
||
" <td>0.037483</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>BJ's Wholesale Club Holdings, Inc.</th>\n",
|
||
" <td>NaN</td>\n",
|
||
" <td>0.044709</td>\n",
|
||
" <td>0.067213</td>\n",
|
||
" <td>0.113551</td>\n",
|
||
" <td>0.056630</td>\n",
|
||
" <td>0.091107</td>\n",
|
||
" <td>0.026186</td>\n",
|
||
" <td>0.065871</td>\n",
|
||
" <td>0.016947</td>\n",
|
||
" <td>NaN</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>Dollar Tree, Inc.</th>\n",
|
||
" <td>NaN</td>\n",
|
||
" <td>0.010756</td>\n",
|
||
" <td>0.013957</td>\n",
|
||
" <td>0.075627</td>\n",
|
||
" <td>0.040338</td>\n",
|
||
" <td>0.041252</td>\n",
|
||
" <td>0.034069</td>\n",
|
||
" <td>0.063465</td>\n",
|
||
" <td>0.016602</td>\n",
|
||
" <td>0.041047</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>Dollar General Corporation</th>\n",
|
||
" <td>NaN</td>\n",
|
||
" <td>0.008256</td>\n",
|
||
" <td>0.037507</td>\n",
|
||
" <td>0.058973</td>\n",
|
||
" <td>0.036922</td>\n",
|
||
" <td>0.046197</td>\n",
|
||
" <td>0.042609</td>\n",
|
||
" <td>0.050776</td>\n",
|
||
" <td>0.039524</td>\n",
|
||
" <td>0.046052</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>Walmart Inc.</th>\n",
|
||
" <td>0.031243</td>\n",
|
||
" <td>0.028372</td>\n",
|
||
" <td>0.065462</td>\n",
|
||
" <td>0.044591</td>\n",
|
||
" <td>0.062023</td>\n",
|
||
" <td>0.057275</td>\n",
|
||
" <td>0.101038</td>\n",
|
||
" <td>0.073506</td>\n",
|
||
" <td>0.059712</td>\n",
|
||
" <td>0.041544</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>Big Lots, Inc.</th>\n",
|
||
" <td>NaN</td>\n",
|
||
" <td>-0.550469</td>\n",
|
||
" <td>0.025262</td>\n",
|
||
" <td>0.115757</td>\n",
|
||
" <td>0.069464</td>\n",
|
||
" <td>-0.111853</td>\n",
|
||
" <td>0.037219</td>\n",
|
||
" <td>0.100721</td>\n",
|
||
" <td>0.110443</td>\n",
|
||
" <td>0.089253</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>Macy's, Inc.</th>\n",
|
||
" <td>NaN</td>\n",
|
||
" <td>0.050473</td>\n",
|
||
" <td>0.270980</td>\n",
|
||
" <td>0.039111</td>\n",
|
||
" <td>0.091301</td>\n",
|
||
" <td>0.101426</td>\n",
|
||
" <td>0.155761</td>\n",
|
||
" <td>0.098993</td>\n",
|
||
" <td>0.065634</td>\n",
|
||
" <td>0.072322</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>Kohl's Corporation</th>\n",
|
||
" <td>NaN</td>\n",
|
||
" <td>-0.143961</td>\n",
|
||
" <td>0.189677</td>\n",
|
||
" <td>0.147968</td>\n",
|
||
" <td>0.119492</td>\n",
|
||
" <td>0.139799</td>\n",
|
||
" <td>0.096137</td>\n",
|
||
" <td>0.198790</td>\n",
|
||
" <td>0.081652</td>\n",
|
||
" <td>0.110697</td>\n",
|
||
" </tr>\n",
|
||
" <tr>\n",
|
||
" <th>The TJX Companies, Inc.</th>\n",
|
||
" <td>0.027159</td>\n",
|
||
" <td>0.023497</td>\n",
|
||
" <td>0.051769</td>\n",
|
||
" <td>0.040167</td>\n",
|
||
" <td>0.048827</td>\n",
|
||
" <td>0.039935</td>\n",
|
||
" <td>0.053697</td>\n",
|
||
" <td>0.043328</td>\n",
|
||
" <td>0.046442</td>\n",
|
||
" <td>0.040643</td>\n",
|
||
" </tr>\n",
|
||
" </tbody>\n",
|
||
"</table>\n",
|
||
"</div>"
|
||
],
|
||
"text/plain": [
|
||
"calendar_year 2023 2022 2021 2020 \\\n",
|
||
"Costco Wholesale Corporation 0.027922 0.014860 0.026582 0.039351 \n",
|
||
"BJ's Wholesale Club Holdings, Inc. NaN 0.044709 0.067213 0.113551 \n",
|
||
"Dollar Tree, Inc. NaN 0.010756 0.013957 0.075627 \n",
|
||
"Dollar General Corporation NaN 0.008256 0.037507 0.058973 \n",
|
||
"Walmart Inc. 0.031243 0.028372 0.065462 0.044591 \n",
|
||
"Big Lots, Inc. NaN -0.550469 0.025262 0.115757 \n",
|
||
"Macy's, Inc. NaN 0.050473 0.270980 0.039111 \n",
|
||
"Kohl's Corporation NaN -0.143961 0.189677 0.147968 \n",
|
||
"The TJX Companies, Inc. 0.027159 0.023497 0.051769 0.040167 \n",
|
||
"\n",
|
||
"calendar_year 2019 2018 2017 2016 \\\n",
|
||
"Costco Wholesale Corporation 0.025906 0.027438 0.060884 0.008941 \n",
|
||
"BJ's Wholesale Club Holdings, Inc. 0.056630 0.091107 0.026186 0.065871 \n",
|
||
"Dollar Tree, Inc. 0.040338 0.041252 0.034069 0.063465 \n",
|
||
"Dollar General Corporation 0.036922 0.046197 0.042609 0.050776 \n",
|
||
"Walmart Inc. 0.062023 0.057275 0.101038 0.073506 \n",
|
||
"Big Lots, Inc. 0.069464 -0.111853 0.037219 0.100721 \n",
|
||
"Macy's, Inc. 0.091301 0.101426 0.155761 0.098993 \n",
|
||
"Kohl's Corporation 0.119492 0.139799 0.096137 0.198790 \n",
|
||
"The TJX Companies, Inc. 0.048827 0.039935 0.053697 0.043328 \n",
|
||
"\n",
|
||
"calendar_year 2015 2014 \n",
|
||
"Costco Wholesale Corporation 0.030741 0.037483 \n",
|
||
"BJ's Wholesale Club Holdings, Inc. 0.016947 NaN \n",
|
||
"Dollar Tree, Inc. 0.016602 0.041047 \n",
|
||
"Dollar General Corporation 0.039524 0.046052 \n",
|
||
"Walmart Inc. 0.059712 0.041544 \n",
|
||
"Big Lots, Inc. 0.110443 0.089253 \n",
|
||
"Macy's, Inc. 0.065634 0.072322 \n",
|
||
"Kohl's Corporation 0.081652 0.110697 \n",
|
||
"The TJX Companies, Inc. 0.046442 0.040643 "
|
||
]
|
||
},
|
||
"execution_count": 26,
|
||
"metadata": {},
|
||
"output_type": "execute_result"
|
||
}
|
||
],
|
||
"source": [
|
||
"# List of other retail chains\n",
|
||
"tickers = [\"COST\", \"BJ\", \"DLTR\", \"DG\", \"WMT\", \"BIG\", \"M\", \"KSS\", \"TJX\"]\n",
|
||
"\n",
|
||
"# Create a dictionary of tickers and company names.\n",
|
||
"names = {\n",
|
||
" ticker: obb.equity.fundamental.overview(ticker, provider=\"fmp\").results[0].name\n",
|
||
" for ticker in tickers\n",
|
||
"}\n",
|
||
"# Create a column for each.\n",
|
||
"fcf_yield = pd.DataFrame()\n",
|
||
"for ticker in tickers:\n",
|
||
" fcf_yield[names[ticker]] = (\n",
|
||
" obb.equity.fundamental.metrics(ticker, provider=\"fmp\", period=\"annual\", limit=10)\n",
|
||
" .to_df()\n",
|
||
" .reset_index()\n",
|
||
" .set_index(\"calendar_year\")\n",
|
||
" .sort_index(ascending=False)\n",
|
||
" [\"free_cash_flow_yield\"]\n",
|
||
" )\n",
|
||
"fcf_yield.transpose()\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"There are more usage examples on our [website](https://docs.openbb.co/platform/usage)"
|
||
]
|
||
}
|
||
],
|
||
"metadata": {
|
||
"kernelspec": {
|
||
"display_name": "obb-sdk4",
|
||
"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"
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 2
|
||
}
|