Read and consolidate cash flow data from Excel or CSV files into a single DataFrame.

This method consolidates portfolio data from one or more Excel or CSV files. It processes the data by identifying and handling duplicate entries, adjusting for the required date format, and renaming columns based on configuration or user inputs. It ensures consistency across transaction details, including descriptions, amounts, costs, and currencies, before returning the data as a structured DataFrame.

The function also allows for customization of the column names used in the dataset, including columns for transaction dates, asset tickers, prices, volumes, and costs/incomes. If necessary, adjustments can be made to handle duplicated entries in the dataset based on configuration settings.

Read Portfolio Dataset in Python

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

pip install financetoolkit -U

Then call read_portfolio_dataset as shown below.

from financetoolkit import Portfolio

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

portfolio.read_portfolio_dataset()

Which returns:

Date Name Price Volume Costs Currency
2024-05-14 CAMT 94.4243 4 0 USD
2024-06-11 META 505.574 8 0 USD
2024-06-18 MPWR 847.6 14 -1 USD
2024-06-21 GOOGL 179.908 -2 0 USD
2024-07-30 AMD 139.57 3 0 USD
2024-08-29 AMD 146.358 -5 -2 USD
2024-10-25 MCHI 48.8436 6 0 USD
2024-11-05 EMXC 58.2921 -5 -1 USD
2024-11-13 VOO 552.136 11 0 USD
2024-12-05 OXY 48.2517 -2 0 USD

Parameters

read_portfolio_dataset accepts the following parameters:

  • adjust_duplicates (bool | None): Flag to indicate whether to adjust duplicate rows in the dataset. If None, defaults to the configuration setting.
  • date_column (list[str] | None): List of column names for date information. Defaults to configuration settings.
  • date_format_options (list[str] | None): List of date format strings to attempt when parsing date columns (e.g. [‘%Y-%m-%d’, ‘%d/%m/%Y’]). Defaults to configuration.
  • name_columns (list[str] | None): List of column names for transaction descriptions. Defaults to configuration.
  • ticker_columns (list[str] | None): List of column names for asset tickers. Defaults to configuration.
  • price_columns (list[str] | None): List of column names for asset prices. Defaults to configuration.
  • volume_columns (list[str] | None): List of column names for asset volumes. Defaults to configuration.
  • currency_columns (list[str] | None): List of column names for transaction currencies. Defaults to configuration.
  • costs_columns (list[str] | None): List of column names for costs or income categories. Defaults to configuration.
  • column_mapping (dict[str, str] | None): Dictionary mapping dataset columns to the appropriate field names. Defaults to configuration.
Share