Toolkit Integration
Converts the Portfolio to a Finance Toolkit object.
This method converts the Portfolio object to a Finance Toolkit object, enabling the use of the Toolkit’s 500+ financial methods for the portfolio’s assets.
Next to the historical data, the portfolio weights are also loaded in the Toolkit class. This, together with the “Portfolio” ticker, enables the possibility to calculate any Toolkit metric for all assets in the portfolio in combination with the Portfolio itself which is a weighted average of other results based on the portfolio weights over time.
Toolkit Integration in Python
toolkit is part of the Portfolio module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call toolkit as shown below.
from financetoolkit import Portfolio
portfolio = Portfolio(example=True, api_key="FINANCIAL_MODELING_PREP_KEY")
toolkit = portfolio.toolkit
toolkit.ratios.get_net_profit_margin()
Which returns:
| 2020 | 2021 | 2022 | 2023 | 2024 | |
|---|---|---|---|---|---|
| AAPL | 0.2091 | 0.2588 | 0.2531 | 0.2531 | 0.2397 |
| ALGN | 0.7184 | 0.1953 | 0.0968 | 0.1152 | 0.1054 |
| AMD | 0.255 | 0.1924 | 0.0559 | 0.0377 | 0.0636 |
| AMZN | 0.0553 | 0.071 | -0.0053 | 0.0529 | 0.0929 |
| ASML | 0.2542 | 0.3161 | 0.2656 | 0.2844 | 0.2679 |
| AVGO | 0.1239 | 0.2454 | 0.3462 | 0.3931 | 0.1143 |
| BAC | 0.2092 | 0.3588 | 0.2899 | 0.269 | 0.2663 |
| BLDR | 0.0366 | 0.0867 | 0.121 | 0.0901 | 0.0657 |
| CAMT | 0.1397 | 0.2235 | 0.2491 | 0.2493 | nan |
| CWST | 0.1176 | 0.0462 | 0.0489 | 0.0201 | 0.0087 |
| FICO | 0.1826 | 0.2978 | 0.2712 | 0.2837 | 0.2986 |
| FIX | 0.0526 | 0.0466 | 0.0594 | 0.0621 | 0.0743 |
| GOOGL | 0.2206 | 0.2951 | 0.212 | 0.2401 | 0.286 |
| KHC | 0.0136 | 0.0389 | 0.0892 | 0.1072 | 0.1062 |
| META | 0.339 | 0.3338 | 0.199 | 0.2898 | 0.3791 |
| MPWR | 0.1947 | 0.2004 | 0.2439 | 0.2347 | nan |
| MSFT | 0.3096 | 0.3645 | 0.3669 | 0.3415 | 0.3596 |
| NFLX | 0.1105 | 0.1723 | 0.1421 | 0.1604 | 0.2234 |
| NVDA | 0.2561 | 0.2598 | 0.3623 | 0.1619 | 0.4885 |
| OXY | -0.7599 | 0.0895 | 0.3632 | 0.1662 | 0.0889 |
| SKY | 0.0598 | 0.1124 | 0.1542 | 0.0724 | nan |
| WMT | 0.0284 | 0.0242 | 0.0239 | 0.0191 | 0.0239 |
| Portfolio | 0.2373 | 0.2183 | 0.2001 | 0.2098 | 0.202 |