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. If the historical data of the assets or the benchmark cannot be collected, an empty DataFrame is returned instead.

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.

Load into the Toolkit in Python

Install the Finance Toolkit 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.2551 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.1115 0.2345 0.338 0.3931 0.1143
BAC 0.1757 0.3256 0.2261 0.1446 0.1325
BLDR 0.0366 0.0867 0.121 0.0901 0.0657
CAMT 0.1397 0.2239 0.2525 0.2528 0.2787
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 0.8095
MSFT 0.3096 0.3645 0.3669 0.3415 0.3596
NFLX 0.1105 0.1723 0.1421 0.1604 0.2234
NVDA 0.2598 0.3623 0.1619 0.4885 0.5585
OXY -0.9146 0.0582 0.3428 0.1324 0.0872
SKY 0.0597 0.1124 0.1542 0.0724 0.0799
WMT 0.0242 0.0239 0.0191 0.0239 0.0285
Portfolio 0.2509 0.2266 0.2051 0.2171 0.2769
Share