Collect and adjust historical price data for the portfolio’s tickers.

The following columns are included:

  • Open: the opening price of each asset over time.
  • High: the highest price of each asset over time.
  • Low: the lowest price of each asset over time.
  • Close: the closing price of each asset over time.
  • Adj Close: the adjusted closing price of each asset over time.
  • Volume: the volume of each asset over time.
  • Dividends: the dividends of each asset over time.
  • Returns: the returns of each asset over time.
  • Cumulative Return: the cumulative return of each asset over time.

Volatility, Excess Return and Excess Volatility are no longer included here. These are available via the Risk module (e.g. toolkit.risk.get_volatility) and the Performance module (e.g. toolkit.performance.get_excess_return) instead.

This method retrieves historical price data (daily, weekly, monthly, quarterly, and yearly) for the portfolio’s tickers and adjusts for any currency mismatches if necessary. It fetches data from a specified data source, applies currency conversion where applicable, and stores the adjusted data in separate DataFrames for different time periods (daily, weekly, monthly, quarterly, yearly).

The method uses the Toolkit class to fetch historical price data and the Currency Toolkit to handle currency conversions if the portfolio’s transaction currency does not match the historical data’s currency.

Historical Data in Python

collect_historical_data is part of the Portfolio module of the open-source Finance Toolkit. Install it with:

pip install financetoolkit -U

Then call collect_historical_data as shown below.

from financetoolkit import Portfolio

portfolio = Portfolio(example=True, api_key="FINANCIAL_MODELING_PREP_KEY")

portfolio.collect_historical_data()

Which returns:

Date Open High Low Close Adj Close Volume Dividends Return Cumulative Return
2025-02-14 48.23 49.09 48.01 48.06 48.06 1.04361e+07 0 0.0038 9.2171
2025-02-18 48.86 49.14 47.91 48.84 48.84 1.53775e+07 0 0.0162 9.3667
2025-02-19 49.5 52.17 49.3 50.99 50.99 2.72406e+07 0 0.044 9.7791
2025-02-20 51.17 52.58 50.49 52.09 52.09 1.41794e+07 0 0.0216 9.99
2025-02-21 51.8 51.99 50.39 50.42 50.42 1.38929e+07 0 -0.0321 9.6698
2025-02-24 50.07 50.4 49.5 49.86 49.86 1.11417e+07 0 -0.0111 9.5624
2025-02-25 49.81 49.96 48.57 48.89 48.89 1.11453e+07 0 -0.0195 9.3763
2025-02-26 49.02 49.2 48.26 48.55 48.55 7.2188e+06 0 -0.007 9.3111
2025-02-27 48.9 49.43 48.34 48.65 48.65 1.04084e+07 0 0.0021 9.3303
2025-02-28 48.48 48.93 47.75 48.84 48.84 1.26817e+07 0 0.0039 9.3667

Parameters

collect_historical_data accepts the following parameters:

  • rounding (int | None): An optional integer specifying the number of decimal places to round the historical price data. If None, the default rounding value is used.
Share