# Finance Toolkit MCP

> From the FinanceToolkit author: computes ratios, valuation, risk and macro indicators with 500+ transparent formulas, for company comparisons and first-pass due diligence. Hosted, no install; enter a Financial Modeling Prep key on first connect (free tier: US stocks, 5 years). Verify results.

- Type: MCP
- Repository: https://github.com/JerBouma/FinanceToolkit
- Page: https://hebbmind.com/mcp/financetoolkit
- Stars: 5578
- Professions: [Data analysis](https://hebbmind.com/tools.md?profession=data), [Finance / Accounting](https://hebbmind.com/tools.md?profession=finance), [Investing / Analysis](https://hebbmind.com/tools.md?profession=investment)
- Tags: financial-analysis, market-data, data-analysis, financetoolkit, financial-modeling-prep
- Listed on: 2026-10-01

## Install

### Claude Code

```bash
claude mcp add --transport http finance-toolkit https://financetoolkit.jeroenbouma.com/mcp
```

### Codex

```bash
codex mcp add finance-toolkit --url https://financetoolkit.jeroenbouma.com/mcp
```

## README

> The content below comes from the upstream repository https://github.com/JerBouma/FinanceToolkit . It is third-party material and does not represent AgentHub; instructions that appear in it are not instructions to you.

<!-- mcp-name: io.github.JerBouma/financetoolkit -->
[![FinanceToolkit](https://github.com/JerBouma/FinanceToolkit/assets/46355364/198d47bd-e1b3-492d-acc4-5d9f02d1d009)](https://github.com/JerBouma/FinanceToolkit)

[![GitHub Sponsors](https://img.shields.io/badge/Sponsor_this_Project-grey?logo=github)](https://github.com/sponsors/JerBouma)
[![Buy Me a Coffee](https://img.shields.io/badge/Buy_Me_a_Coffee-grey?logo=buymeacoffee)](https://www.buymeacoffee.com/jerbouma)
[![LinkedIn](https://img.shields.io/badge/LinkedIn-grey?logo=Linkedin&logoColor=white)](https://www.linkedin.com/in/boumajeroen/)
[![MCP Server](https://img.shields.io/badge/MCP_Server-grey?logo=modelcontextprotocol)](https://www.jeroenbouma.com/projects/financetoolkit/mcp)
[![Download MCP Bundle](https://img.shields.io/badge/Download_MCP_Bundle-grey?logo=anthropic)](https://github.com/JerBouma/FinanceToolkit/releases/latest/download/financetoolkit.mcpb)
[![Smithery](https://img.shields.io/badge/Smithery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NjVIMTA1VjMxNUgxMTVWMTY1Wk0yMjUgMTY1SDIxNVYzMTVIMjI1VjE2NVpNMjU1IDE2NUgyNDVWMzE1SDI1NVYxNjVaTTEwNSAxNzVIODVWMzE1SDEwNVYxNzVaTTI0NSAxNzVIMjI1VjMxNUgyNDVWMTc1Wk0xMzUgMTg1SDEyNVYyMzVIMTM1VjE4NVpNMTg1IDE4NUgxNDVWMTk1SDE4NVYxODVaTTIwNSAxODVIMTk1VjIzNUgyMDVWMTg1Wk03NSAxOTVINjVWMjc1SDc1VjE5NVpNMTQ1IDE5NUgxMzVWMjM1SDE0NVYxOTVaTTE5NSAxOTVIMTg1VjIzNUgxOTVWMTk1Wk0yNjUgMTk1SDI1NVYyNzVIMjY1VjE5NVpNMTU1IDIwNUgxNDVWMjM1SDE1NVYyMDVaTTE4NSAyMDVIMTc1VjIzNUgxODVWMjA1Wk0xMjUgMjM1SDExNVYzMTVIMTI1VjIzNVpNMjE1IDIzNUgyMDVWMzE1SDIxNVYyMzVaTTE0NSAyNDVIMTI1VjMxNUgxNDVWMjQ1Wk0yMDUgMjQ1SDE4NVYzMTVIMjA1VjI0NVpNMTg1IDI2NUgxNDVWMzE1SDE4NVYyNjVaIiBmaWxsPSJ3aGl0ZSIvPjwvc3ZnPg==)](https://glama.ai/mcp/servers/JerBouma/FinanceToolkit)
[![Documentation](https://img.shields.io/badge/Documentation-grey?logo=readme)](https://www.jeroenbouma.com/projects/financetoolkit/docs)
[![Supported Python Versions](https://img.shields.io/pypi/pyversions/financetoolkit)](https://pypi.org/project/FinanceToolkit/)
[![PYPI Version](https://img.shields.io/pypi/v/FinanceToolkit)](https://pypi.org/project/FinanceToolkit/)
[![PYPI Downloads](https://static.pepy.tech/badge/financetoolkit/month)](https://pepy.tech/project/financetoolkit)

While browsing a variety of websites, I repeatedly observed significant fluctuations in the same financial metric among different sources. Similarly, the reported financial statements often didn't line up, and there was limited information on the methodology used to calculate each metric.

For example, Microsoft's Price-to-Earnings (PE) ratio on the 6th of May, 2023 is reported to be 28.93 (Stockopedia), 32.05 (Morningstar), 32.66 (Macrotrends), 33.09 (Finance Charts), 33.66 (Y Charts), 33.67 (Wall Street Journal), 33.80 (Yahoo Finance) and 34.4 (Companies Market Cap). All of these calculations are correct, however the method of calculation varies leading to different results. Therefore, collecting data from multiple sources can lead to wrong interpretation of the results given that one source could apply a different definition than another. And that is, if that definition is even available as often the underlying methods are hidden behind a paid subscription.

**This is why I designed the FinanceToolkit**, this is an open-source toolkit in which all relevant financial methods ([1100+](https://www.jeroenbouma.com/projects/financetoolkit/docs)) are written down in the most simplistic way allowing for complete transparency of the method of calculation ([proof](https://github.com/JerBouma/FinanceToolkit/blob/main/financetoolkit/ratios/valuation_model.py)). This enables you to avoid dependence on metrics from other providers that do not provide their methods. With a large selection of financial statements in hand, it facilitates streamlined calculations, promoting the adoption of a consistent and universally understood methods and formulas.

Beyond Equities, it supports Options, Currencies, Cryptocurrencies, ETFs, Mutual Funds, Indices, Money Markets, Commodities, Key Economic Indicators and more, allowing you to obtain historical data as well as important performance and risk measurements such as the Sharpe Ratio and Value at Risk.

Complementing this is the [Finance Database 🌎](https://github.com/JerBouma/FinanceDatabase), a database featuring 300.000+ symbols containing Equities, ETFs, Funds, Indices, Currencies, Cryptocurrencies and Money Markets. By utilising both, it is possible to do a fully-fledged competitive analysis with the tickers found from the FinanceDatabase inputted into the FinanceToolkit.

___
**🔌 The Finance Toolkit is also available as an [MCP Server](https://www.jeroenbouma.com/projects/financetoolkit/mcp)**

Query 1100+ methods from Claude, Copilot, Cursor, Devin Desktop (Windsurf) or any MCP-compatible client without writing code.

- **Hosted:** connect to `https://financetoolkit.jeroenbouma.com/mcp` — OAuth handles the rest on first use.
- **Local:** `uvx --from "financetoolkit[mcp]" financetoolkit-mcp-setup` — sets up your client config and API key automatically. See [MCP Server Documentation](https://www.jeroenbouma.com/projects/financetoolkit/mcp#local-clients) for manual setup.

Also on [Smithery](https://smithery.ai/servers/jer-bouma/financetoolkit), [Glama](https://glama.ai/mcp/servers/JerBouma/FinanceToolkit), [MCP Servers](https://mcpservers.org/servers/jerbouma/financetoolkit) and more.
___

# Table of Contents

1. [Installation](#installation)
2. [Functionality](#functionality)
    - [Discovering the Sector](#discovering-the-sector)
    - [Following the Market](#following-the-market)
    - [Zooming in on Competitors](#zooming-in-on-competitors)
    - [Weighing Risk and Return](#weighing-risk-and-return)
    - [What the Option Market Expects](#what-the-option-market-expects)
    - [The Economic Environment](#the-economic-environment)
    - [Economic Relations](#economic-relations)
    - [Comparing the Sector's ETFs](#comparing-the-sectors-etfs)
    - [Building a Diversified Portfolio](#building-a-diversified-portfolio)
    - [Following the Portfolio](#following-the-portfolio)
3. [MCP Server](#mcp-server)
4. [Questions & Answers](#questions--answers)
5. [Contributing](#contributing)
6. [Mentions](#mentions)
7. [Contact](#contact)

# Installation

Before installation, consider starring the project on GitHub which helps others find the project as well. 

<a href="https://github.com/JerBouma/FinanceToolkit" target="_blank"><img width="1415" alt="image" src="https://github.com/JerBouma/FinanceToolkit/assets/46355364/014109fe-0c68-47d4-99bd-217c69dcea8d"></a>

To install the Finance Toolkit it simply requires the following:

```
pip install financetoolkit -U
````

Then within Python use:

```python
from financetoolkit import Toolkit

companies = Toolkit(
    tickers=['AAPL', 'MSFT'],
    api_key="FINANCIAL_MODELING_PREP_KEY",  # replace with your actual API key
)
```
To be able to get started, you need to obtain an API Key from FinancialModelingPrep. This is used to gain access to 30+ years of financial statement both annually and quarterly. Note that the Free plan is limited to 250 requests each day, 5 years of data and only features companies listed on US exchanges.

___ 

<b><div align="center">Obtain an API Key from FinancialModelingPrep <a href="https://www.jeroenbouma.com/fmp" target="_blank">here</a>.</div></b>
___

Through the link you are able to subscribe for the free plan and also premium plans at a **15% discount**. This is an affiliate link and thus supports the project at the same time. I have chosen FinancialModelingPrep as a source as I find it to be the most transparent, reliable and at an affordable price. I have yet to find a platform offering such low prices for the amount of data offered. When you notice that the data is inaccurate or have any other issue related to the data, note that I simply provide the means to access this data and I am not responsible for the accuracy of the data itself. For this, use [their contact form](https://site.financialmodelingprep.com/contact) or provide the data yourself.

**By default, the Finance Toolkit prioritizes Financial Modeling Prep for data retrieval. If data acquisition from Financial Modeling Prep is unsuccessful (e.g., due to plan restrictions or API key issues), the toolkit automatically switches to Yahoo Finance as a secondary source.** To disable this fallback behavior and exclusively use Financial Modeling Prep, set `enforce_source="FinancialModelingPrep"` during Toolkit initialization. This configuration ensures that an error is raised if Financial Modeling Prep data cannot be accessed. Alternatively, you can set `enforce_source="YahooFinance"` to exclusively use Yahoo Finance as the data source.

The same `enforce_source` argument is also accepted per call on `get_historical_data`, `get_treasury_data` and the four statement functions (`get_balance_sheet_statement`, `get_income_statement`, `get_cash_flow_statement` and `get_statistics_statement`), where it overrides whatever the Toolkit was initialised with.

# Functionality

This section is an introduction to the Finance Toolkit. The documentation contains many more examples: every module page opens with a Getting Started section, from the basics to creating custom ratios and working with your own datasets.

___

<b><div align="center">Find the Documentation, including the Getting Started guides, <a href="https://www.jeroenbouma.com/projects/financetoolkit/docs">here</a>.</div></b>
___

The sections below follow one analysis of the semiconductor sector from start to finish, where each step answers the question the previous one raises: which companies make up the sector, how their shares did, what drives their profits, how much risk came with the returns, what the option market expects next, how the economy shaped all of it, whether a fund is the better way in and how the sector fits into a diversified portfolio. Every module of the Finance Toolkit appears once, but each holds far more than shown here: 1100+ methods in total, all described with examples in the [documentation](https://www.jeroenbouma.com/projects/financetoolkit/docs).

## Discovering the Sector

An analysis starts with a set of companies. The [Discovery](https://www.jeroenbouma.com/projects/financetoolkit/docs/discovery) module finds them without needing any tickers yet, through stock screeners, sector performance, news and lists of companies, ETFs, indices, currencies, cryptocurrencies and commodities.

The screener below looks for semiconductor companies on NASDAQ that are worth more than $100 billion:

```python
from financetoolkit import Discovery

# Initialize the standalone Discovery module
discovery = Discovery(api_key="FINANCIAL_MODELING_PREP_KEY")

# Find US semiconductor companies worth more than $100 billion
semiconductors = discovery.get_stock_screener(
    industry="Semiconductors",
    country="US",
    exchange="NASDAQ",
    market_cap_higher=100_000_000_000,
    is_etf=False,
)

# Show the five largest
semiconductors[["Name", "Market Cap", "Beta", "Price", "Dividend"]].head()
```

For example, the five largest companies the screener returns are shown below.

| Symbol   | Name                         |    Market Cap |   Beta |   Price |   Dividend |
|:---------|:-----------------------------|--------------:|-------:|--------:|-----------:|
| NVDA     | NVIDIA Corporation           | 5084136000000 |  2.216 |  210.96 |      0.28  |
| AVGO     | Broadcom Inc.                | 1535581254973 |  1.476 |  321.68 |      2.6   |
| MU       | Micron Technology, Inc.      |  992877621000 |  2.226 |  877.55 |      0.565 |
| AMD      | Advanced Micro Devices, Inc. |  843646776955 |  2.454 |  516.79 |      0     |
| INTC     | Intel Corp.                  |  459679713584 |  2.23  |   86.96 |      0     |

And below all of them are ranked by market cap.

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/JerBouma/FinanceToolkit/main/assets/readme/discovery-dark.png">
  <img alt="Discovering the Sector" src="https://raw.githubusercontent.com/JerBouma/FinanceToolkit/main/assets/readme/discovery-light.png">
</picture>

## Following the Market

The rest of this walkthrough follows three of them: Nvidia, AMD and Intel. They are loaded into the Toolkit in one line, and the S&P 500 comes along as the benchmark:

```python
from financetoolkit import Toolkit

# Initialize the Toolkit for Nvidia, AMD and Intel from 2018 to 2025
companies = Toolkit(
    ["NVDA", "AMD", "INTC"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2017-12-31",
    end_date="2025-12-31",
)
```

[Historical data](https://www.jeroenbouma.com/projects/financetoolkit/docs#get_historical_data) comes on a daily, weekly, monthly, quarterly or yearly basis, with the return and cumulative return of each period, and so do the [income statement](https://www.jeroenbouma.com/projects/financetoolkit/docs#get_income_statement), [balance sheet](https://www.jeroenbouma.com/projects/financetoolkit/docs#get_balance_sheet_statement) and [cash flow statement](https://www.jeroenbouma.com/projects/financetoolkit/docs#get_cash_flow_statement) on an annual or quarterly basis. How far a share has travelled is one thing; whether the rally was stretched is another. The [technicals](https://www.jeroenbouma.com/projects/financetoolkit/docs/technicals) module answers that with 150+ indicators and 62 candlestick patterns, among them the Relative Strength Index (RSI), which moves between 0 and 100 and is commonly read as overbought above 70:

```python
# Obtain weekly market data for all tickers and the benchmark
historical_data = companies.get_historical_data(period="weekly")

# The 14-week Relative Strength Index
relative_strength_index = companies.technicals.get_relative_strength_index(period="weekly", window=14)

# Show the highest RSI of each year
relative_strength_index.groupby(relative_strength_index.index.start_time.year).max()
```

For example, the highest weekly RSI of each year is shown below.

|   Date |    NVDA |     AMD |    INTC |   Benchmark |
|-------:|--------:|--------:|--------:|------------:|
|   2018 | 66.1087 | 90.9719 | 66.7363 |     66.0498 |
|   2019 | 73.8156 | 81.2446 | 69.8225 |     75.9305 |
|   2020 | 85.2337 | 82.1215 | 78.4827 |     80.2378 |
|   2021 | 85.1593 | 82.0983 | 71.5862 |     74.4751 |
|   2022 | 58.4343 | 58.9426 | 61.2806 |     59.9225 |
|   2023 | 87.5129 | 77.506  | 76.2332 |     71.4291 |
|   2024 | 91.0702 | 82.1403 | 67.6949 |     80.0566 |
|   2025 | 73.3514 | 82.5281 | 79.7429 |     71.6939 |

And below the cumulative returns of all three are plotted against the S&P 500, with the RSI underneath.

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/JerBouma/FinanceToolkit/main/assets/readme/historical-dark.png">
  <img alt="Following the Market" src="https://raw.githubusercontent.com/JerBouma/FinanceToolkit/main/assets/readme/historical-light.png">
</picture>

## Zooming in on Competitors

Nvidia's shares outran the other two by far, which raises the question whether its business did as well. From the financial statements the Toolkit calculates 130+ [ratios](https://www.jeroenbouma.com/projects/financetoolkit/docs/ratios) in five categories: efficiency, liquidity, profitability, solvency and valuation. Each ratio has its own function, and a `collect_` function returns a whole category at once:

```python
# Collect all Profitability Ratios for all tickers
profitability_ratios = companies.ratios.collect_profitability_ratios()

# Show the first ratios for Nvidia
profitability_ratios.loc["NVDA"].head()
```

For example, some of Nvidia's profitability ratios are shown below.

|                       |   2017 |   2018 |   2019 |   2020 |   2021 |   2022 |   2023 |   2024 |   2025 |
|:----------------------|-------:|-------:|-------:|-------:|-------:|-------:|-------:|-------:|-------:|
| Gross Margin          | 0.5993 | 0.6121 | 0.6199 | 0.6234 | 0.6493 | 0.5693 | 0.7272 | 0.7499 | 0.7107 |
| Operating Margin      | 0.3305 | 0.3247 | 0.2607 | 0.2718 | 0.3731 | 0.1566 | 0.5412 | 0.6242 | 0.6038 |
| Net Profit Margin     | 0.3137 | 0.3534 | 0.2561 | 0.2598 | 0.3623 | 0.1619 | 0.4885 | 0.5585 | 0.556  |
| EBITDA Margin         | 0.3509 | 0.347  | 0.2956 | 0.3376 | 0.4167 | 0.2138 | 0.566  | 0.6385 | 0.617  |
| Free Cash Flow Margin | 0.2995 | 0.2683 | 0.3913 | 0.2815 | 0.3021 | 0.1412 | 0.4435 | 0.4663 | 0.4477 |

And below a few of them are shown with their latest value and their course over the years.

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/JerBouma/FinanceToolkit/main/assets/readme/ratios-dark.png">
  <img alt="Profitability Ratios" src="https://raw.githubusercontent.com/JerBouma/FinanceToolkit/main/assets/readme/ratios-light.png">
</picture>

A high return on equity can come from margins, from turnover or from debt. [Models](https://www.jeroenbouma.com/projects/financetoolkit/docs/models) combine the ratios to tell these apart: the [Extended DuPont Analysis](https://www.jeroenbouma.com/projects/financetoolkit/docs/models#get_dupont_analysis) splits the return on equity into five components that multiply into it: interest burden, tax burden, operating margin, asset turnover and equity multiplier.

```python
# Get the Extended DuPont Analysis for all tickers
extended_dupont_analysis = companies.models.get_dupont_analysis(method="extended")

# Show the results for Nvidia
extended_dupont_analysis.loc["NVDA"]
```

For example, the components for Nvidia are shown below.

|                         |   2017 |   2018 |   2019 |   2020 |   2021 |   2022 |   2023 |   2024 |   2025 |
|:------------------------|-------:|-------:|-------:|-------:|-------:|-------:|-------:|-------:|-------:|
| Interest Burden Ratio   | 0.9956 | 1.0242 | 1.0436 | 0.9729 | 0.99   | 0.9898 | 1.0257 | 1.0316 | 1.0848 |
| Tax Burden Ratio        | 0.9534 | 1.0629 | 0.9414 | 0.9825 | 0.981  | 1.0447 | 0.88   | 0.8674 | 0.8488 |
| Operating Profit Margin | 0.3305 | 0.3247 | 0.2607 | 0.2718 | 0.3731 | 0.1566 | 0.5412 | 0.6242 | 0.6038 |
| Asset Turnover          | 0.9215 | 0.9551 | 0.7134 | 0.7233 | 0.7376 | 0.6319 | 1.1397 | 1.4718 | 1.3564 |
| Equity Multiplier       | 1.5931 | 1.4592 | 1.4205 | 1.5846 | 1.6775 | 1.7525 | 1.6428 | 1.4499 | 1.3456 |
| Return on Equity        | 0.4605 | 0.4926 | 0.2595 | 0.2978 | 0.4483 | 0.1793 | 0.9146 | 1.1918 | 1.0149 |

And below each component is shown for every fiscal year, with the latest value on top, multiplying into the return on equity.

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/JerBouma/FinanceToolkit/main/assets/readme/models-dark.png">
  <img alt="Extended DuPont Analysis" src="https://raw.githubusercontent.com/JerBouma/FinanceToolkit/main/assets/readme/models-light.png">
</picture>

Other models include the [Weighted Average Cost of Capital](https://www.jeroenbouma.com/projects/financetoolkit/docs/models#get_weighted_average_cost_of_capital), [Altman Z-Score](https://www.jeroenbouma.com/projects/financetoolkit/docs/models#get_altman_z_score), [Piotroski F-Score](https://www.jeroenbouma.com/projects/financetoolkit/docs/models#get_piotroski_score) and [Intrinsic Valuation](https://www.jeroenbouma.com/projects/financetoolkit/docs/models#get_intrinsic_valuation). Almost every function also accepts `growth=True` for the growth from one period to the next, `trailing=4` for trailing twelve-month figures, `standardize=True` for Z-Scores and `transform=` for time series steps on the result, applied in order, such as `"yoy"`, `"sma:4"`, `"zscore:20"` or `"hp_trend"` (Hodrick-Prescott).

## Weighing Risk and Return

Strong businesses do not make for smooth shares. The market data feeds the [performance](https://www.jeroenbouma.com/projects/financetoolkit/docs/performance) and [risk](https://www.jeroenbouma.com/projects/financetoolkit/docs/risk) modules, which calculate their metrics for any period, from intraday to yearly:

```python
# The annualized Sharpe Ratio for each year
sharpe_ratio = companies.performance.get_sharpe_ratio(period="yearly", annualize=True)

# The deepest fall within each year
maximum_drawdown = companies.risk.get_maximum_drawdown(period="yearly", within_period=True)

# Show the Sharpe Ratios
sharpe_ratio
```

For example, the yearly Sharpe Ratios are shown below.

| Date   |    NVDA |     AMD |    INTC |
|:-------|--------:|--------:|--------:|
| 2018   | -0.613  |  1.1009 |  0.161  |
| 2019   |  1.5458 |  1.9143 |  1.048  |
| 2020   |  1.656  |  1.419  | -0.0445 |
| 2021   |  2.0003 |  1.2366 |  0.2976 |
| 2022   | -0.8393 | -1.0532 | -1.5306 |
| 2023   |  2.6986 |  1.9195 |  1.8358 |
| 2024   |  2.0851 | -0.2615 | -1.5749 |
| 2025   |  0.8325 |  1.1753 |  1.2061 |

And below both are plotted for each year, the maximum drawdown together with the S&P 500.

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/JerBouma/FinanceToolkit/main/assets/readme/risk-dark.png">
  <img alt="Sharpe Ratio and Maximum Drawdown" src="https://raw.githubusercontent.com/JerBouma/FinanceToolkit/main/assets/readme/risk-light.png">
</picture>

Together the two modules cover 140+ metrics, such as [Value at Risk](https://www.jeroenbouma.com/projects/financetoolkit/docs/risk#get_value_at_risk), [GARCH](https://www.jeroenbouma.com/projects/financetoolkit/docs/risk#get_garch), [L-moments](https://www.jeroenbouma.com/projects/financetoolkit/docs/risk#get_l_moment), [Jensen's Alpha](https://www.jeroenbouma.com/projects/financetoolkit/docs/performance#get_alpha), the [Capital Asset Pricing Model](https://www.jeroenbouma.com/projects/financetoolkit/docs/performance#get_capital_asset_pricing_model) and the [Fama-French factors](https://www.jeroenbouma.com/projects/financetoolkit/docs/performance#get_fama_and_french_model). Most of them also accept `rolling=<n>` for a value that moves through time.

## What the Option Market Expects

The past shows how much risk came with the returns; the option market puts a price on the risk ahead. The [options](https://www.jeroenbouma.com/projects/financetoolkit/docs/options) module prices options with Black-Scholes, the Binomial Model and others, calculates the Greeks up to the third order and reads the live option chains: the put-call ratio, max pain, dealer gamma exposure, the volatility skew and term structure, the implied move and the risk-neutral skewness and kurtosis, also as a SKEW index for any ticker. As the chains are those of today, the Toolkit below runs up to today, and the numbers are those of the day this README was last updated:

```python
# Initialize the Toolkit up to today, as the option chains are live
companies_today = Toolkit(["NVDA", "AMD", "INTC"], api_key="FINANCIAL_MODELING_PREP_KEY")

# The volatility the options imply for the next 30 days against that of the past 30 days
companies_today.options.get_volatility_risk_premium(days=30)
```

The implied volatility is model-free, read with the method behind the VIX from all out-of-the-money options around the horizon, and the realized volatility is that of the daily returns over the same number of days. For example, both are shown below for each company.

|      |   Implied Volatility |   Realized Volatility |   Volatility Risk Premium |   Variance Risk Premium |   Implied to Realized Ratio |
|:-----|---------------------:|----------------------:|--------------------------:|------------------------:|----------------------------:|
| NVDA |               0.4845 |                0.2795 |                    0.2049 |                  0.1566 |                      1.7331 |
| AMD  |               0.657  |                0.498  |                    0.159  |                  0.1836 |                      1.3192 |
| INTC |               0.6991 |                0.5196 |                    0.1795 |                  0.2188 |                      1.3456 |

Options usually price more risk than follows, as their sellers want to be paid for taking it on, and here they priced far more turbulence for the coming month than the past month delivered: Nvidia's options implied 1.7 times the volatility its shares showed. And below the implied and realized volatility of each company are plotted next to each other.

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/JerBouma/FinanceToolkit/main/assets/readme/options-market-dark.png">
  <img alt="Implied and Realized Volatility" src="https://raw.githubusercontent.com/JerBouma/FinanceToolkit/main/assets/readme/options-market-light.png">
</picture>

## The Economic Environment

All three are listed in the United States and valued on earnings that lie years ahead, which makes US inflation and interest rates the backdrop to their share prices. In 2022, the year the maximum drawdown above shows each of them falling by more than half, inflation reached 9% and the Federal Reserve raised its policy rate from 0.12% to 4.38%.

The [economics](https://www.jeroenbouma.com/projects/financetoolkit/docs/economics) module covers 60+ countries with 100+ indicators, from GDP and unemployment to money supply and interest rates, and the [fixed income](https://www.jeroenbouma.com/projects/financetoolkit/docs/fixedincome) module adds bond yields, yield curves (bootstrapped with a choice of interpolation, fitted to Treasury prices and extrapolated with Smith-Wilson), central bank rates, swap, FRA and FX forward rates, inflation swap rates and the forward CPI, calculations on individual bonds and Treasury market analytics (FRN discount margins, TIPS index ratios, forward prices and the futures basis). Both are reached through the same Toolkit instance, or on their own with `from financetoolkit import Economics, FixedIncome`:

```python
# Inflation on the same month a year earlier and the Federal Reserve's policy rate
inflation_rate = companies.economics.get_inflation_rate("United States", period="monthly")
policy_rate = companies.economics.get_central_bank_policy_rate("United States", period="monthly")

# The daily U.S. Treasury par yield curve
treasury_rates = companies.fixedincome.get_treasury_rates()

# Show the curve on the last trading day of each year
treasury_rates.groupby(treasury_rates.index.year).last()
```

For example, the yield curve at the end of each year is shown below.

|   Date |   1 Month |   2 Month |   3 Month |   6 Month |   1 Year |   2 Year |   3 Year |   5 Year |   7 Year |   10 Year |   20 Year |   30 Year |
|-------:|----------:|----------:|----------:|----------:|---------:|---------:|---------:|---------:|---------:|----------:|----------:|----------:|
|   2018 |    0.0244 |    0.0245 |    0.0245 |    0.0256 |   0.0263 |   0.0248 |   0.0246 |   0.0251 |   0.0259 |    0.0269 |    0.0287 |    0.0302 |
|   2019 |    0.0148 |    0.0151 |    0.0155 |    0.016  |   0.0159 |   0.0158 |   0.0162 |   0.0169 |   0.0183 |    0.0192 |    0.0225 |    0.0239 |
|   2020 |    0.0008 |    0.0008 |    0.0009 |    0.0009 |   0.001  |   0.0013 |   0.0017 |   0.0036 |   0.0065 |    0.0093 |    0.0145 |    0.0165 |
|   2021 |    0.0006 |    0.0005 |    0.0006 |    0.0019 |   0.0039 |   0.0073 |   0.0097 |   0.0126 |   0.0144 |    0.0152 |    0.0194 |    0.019  |
|   2022 |    0.0412 |    0.0441 |    0.0442 |    0.0476 |   0.0473 |   0.0441 |   0.0422 |   0.0399 |   0.0396 |    0.0388 |    0.0414 |    0.0397 |
|   2023 |    0.056  |    0.0559 |    0.054  |    0.0526 |   0.0479 |   0.0423 |   0.0401 |   0.0384 |   0.0388 |    0.0388 |    0.042  |    0.0403 |
|   2024 |    0.044  |    0.0439 |    0.0437 |    0.0424 |   0.0416 |   0.0425 |   0.0427 |   0.0438 |   0.0448 |    0.0458 |    0.0486 |    0.0478 |
|   2025 |    0.0374 |    0.0367 |    0.0367 |    0.0359 |   0.0348 |   0.0347 |   0.0355 |   0.0373 |   0.0394 |    0.0418 |    0.0479 |    0.0484 |

And below the yield curve at the end of each year is plotted. It went from almost zero at the short end in 2021 to above 4% across all maturities a year later, and when short-term yields lie above long-term ones, as at the end of 2022 and 2023, the curve is inverted.

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/JerBouma/FinanceToolkit/main/assets/readme/economics-dark.png">
  <img alt="US Inflation, Policy Rate and Yield Curve" src="https://raw.githubusercontent.com/JerBouma/FinanceToolkit/main/assets/readme/economics-light.png">
</picture>

## Economic Relations

Rates rose and the shares fell, but a 10-year Treasury yield is made of two parts: the real yield, the return investors demand on top of inflation, and the inflation they expect over those ten years. The [econometrics](https://www.jeroenbouma.com/projects/financetoolkit/docs/econometrics) module tells such drivers apart with regressions, tests and forecasts; the methods built on `statsmodels` or `linearmodels` need `pip install financetoolkit[econometrics]`. Through the Toolkit it analyzes the returns of its tickers, and on its own, through `Econometrics(data=...)`, any data at all, here the monthly returns of the three next to the monthly change in the US 10-year real yield and in 10-year inflation expectations:

```python
import pandas as pd

from financetoolkit import Econometrics

# The US 10-year real yield and inflation expectations at the end of each month
real_yield = companies.economics.get_real_yield_curve("United States", period="monthly")
inflation_expectations = companies.economics.get_breakeven_inflation_expectations(
    "United States", period="monthly"
)

# The monthly change in both next to the monthly returns
monthly_returns = companies.get_historical_data(period="monthly")["Return"][["NVDA", "AMD", "INTC"]]
monthly_returns["Real Yield"] = real_yield[("United States", "10Y")].diff()
monthly_returns["Inflation Expectations"] = inflation_expectations[("United States", "10Y")].diff()

# The data are changes already
econometrics = Econometrics(data=monthly_returns, changes=None)

# Regress the return of each company on the change in the real yield and inflation expectations
regressions = pd.concat(
    {
        ticker: econometrics.get_ols(
            dependent_ticker=ticker, independent_tickers=["Real Yield", "Inflation Expectations"]
        )
        for ticker in ["NVDA", "AMD", "INTC"]
    }
)

# Show the results for Nvidia
regressions.loc["NVDA"]
```

For example, the coefficients for Nvidia are shown below.

|                        |   Coefficient |   Standard Error |   t-Statistic |   P-Value |
|:-----------------------|--------------:|-----------------:|--------------:|----------:|
| Intercept              |        0.049  |           0.0129 |        3.8028 |    0.0003 |
| Real Yield             |      -22.8132 |           5.6358 |       -4.0479 |    0.0001 |
| Inflation Expectations |       18.1329 |           9.1029 |        1.992  |    0.0493 |

And below each coefficient is shown with its 95% confidence interval. A rise of 0.1 percentage point in the real yield went with a monthly return about 2.3% lower for Nvidia, 3.4% for AMD and 1.9% for Intel, as a higher real yield discounts their distant earnings more heavily. Inflation expectations matter far less: only for Nvidia does their coefficient come close to significance.

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/JerBouma/FinanceToolkit/main/assets/readme/econometrics-dark.png">
  <img alt="Economic Relations" src="https://raw.githubusercontent.com/JerBouma/FinanceToolkit/main/assets/readme/econometrics-light.png">
</picture>

The module also covers unit root and cointegration tests, fractional differentiation, bubble tests (SADF, GSADF) with the dates of each bubble, Granger causality, panel data, causal inference, ARIMA, VAR and VECM forecasts, regime switching, a time-varying beta and pairs trading.

## Comparing the Sector's ETFs

Rather than picking three companies, a fund holds the whole industry. The [ETF](https://www.jeroenbouma.com/projects/financetoolkit/docs/etf) module analyzes the holdings, sector and country weightings, tracking, concentration, overlap, valuation and liquidity of any fund. Below it compares six semiconductor funds: three focused on the United States (SOXX, XSD and PSI), one global fund (SMH) and two that hold a single country, China (SMHC) and South Korea (KCHP):

```python
# Initialize the Toolkit for six semiconductor funds
funds = Toolkit(
    ["SOXX", "XSD", "PSI", "SMH", "SMHC", "KCHP"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2017-12-31",
    end_date="2025-12-31",
)

# Where each fund invests, how concentrated it is and how much the funds hold of the same
country_weightings = funds.etf.get_country_weightings()
concentration = funds.etf.get_concentration()
overlap = funds.etf.get_overlap()

# Show the overlap between every pair of funds
overlap.round(2)
```

For example, the overlap between every pair of funds is shown below: the share of the two portfolios that is the same. Holdings are those of today, as funds publish their current holdings only.

|      |   SOXX |   XSD |   PSI |   SMH |   SMHC |   KCHP |
|:-----|-------:|------:|------:|------:|-------:|-------:|
| SOXX |   1    |  0.38 |  0.46 |  0.7  |   0    |      0 |
| XSD  |   0.38 |  1    |  0.34 |  0.28 |   0    |      0 |
| PSI  |   0.46 |  0.34 |  1    |  0.38 |   0    |      0 |
| SMH  |   0.7  |  0.28 |  0.38 |  1    |   0    |      0 |
| SMHC |   0    |  0    |  0    |  0    |   1.08 |      0 |
| KCHP |   0    |  0    |  0    |  0    |   0    |      1 |

The three US funds and SMH largely hold the same companies, with SOXX and SMH sharing 70% of their portfolios. SMH holds the most outside the United States, 9% in Taiwan and 6% in the Netherlands. The China and Korea funds share nothing with any other fund, which is what diversification within one sector looks like. Below, the country weights of each fund are plotted next to the overlap.

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/JerBouma/FinanceToolkit/main/assets/readme/etf-dark.png">
  <img alt="Comparing the Sector's ETFs" src="https://raw.githubusercontent.com/JerBouma/FinanceToolkit/main/assets/readme/etf-light.png">
</picture>

## Building a Diversified Portfolio

A fund spreads the risk over the sector, but the sector still moves as one. The [portfolio](https://www.jeroenbouma.com/projects/financetoolkit/docs/portfolio-optimization) module builds portfolios from the tickers of any Toolkit: minimum variance, maximum Sharpe ratio, mean-variance, mean-risk (such as mean absolute deviation, semideviation and Gini mean difference), risk parity, inverse volatility, Hierarchical Risk Parity, Hierarchical Equal Risk Contribution and Nested Clustered Optimization (also with CVaR, CDaR and other risk measures, and on the Directed Bubble Hierarchical Tree), Schur Complementary Allocation, stacking, minimum CVaR, minimum drawdown, maximum Omega and CVaR ratio, Black-Litterman, maximum diversification, minimum tracking error, growth optimal (Kelly), resampled (Michaud), worst-case mean-variance and distributionally robust CVaR weights, the efficient frontier and its corner portfolios (critical line algorithm), a walk-forward backtest of the optimizers, whole-share allocations, risk contributions, stress tests and attribution, and shows the estimates behind them: shrunk (Bayes-Stein, James-Stein, Bodnar-Okhrin-Parolya) and compounded expected returns, entropy pooling views, shrunk, Gerber, denoised, robust (minimum covariance determinant), graph-based (j-LoGo) and detoned covariances, distance correlation, mutual information and tail dependence matrices, coskewness and cokurtosis and bootstrapped estimation uncertainty. Below the semiconductor fund is combined with health care (XLV), energy (XLE), long-term Treasuries (TLT) and gold (GLD):

```python
# Initialize the Toolkit for funds across sectors and asset classes from 2021 to 2025
assets = Toolkit(
    ["SMH", "XLV", "XLE", "TLT", "GLD"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

# The efficient frontier and the maximum Sharpe ratio portfolio, with at most 40% per asset
efficient_frontier = assets.portfolio.get_efficient_frontier(points=25, maximum_weight=0.4)
maximum_sharpe = assets.portfolio.get_maximum_sharpe_weights(maximum_weight=0.4)

# The portfolio in which every asset contributes the same share of the risk
risk_parity = assets.portfolio.get_risk_parity_weights()

# Show the risk parity portfolio
risk_parity
```


> The README is long; the above is its first 40000 characters. Full content: https://github.com/JerBouma/FinanceToolkit
