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

Install the Finance Toolkit 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:

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

Parameters

read_portfolio_dataset accepts the following parameters.

ParameterTypeDescriptionExample
adjust_duplicatesbool | NoneFlag to indicate whether to adjust duplicate rows in the dataset. If None, defaults to the configuration setting.False
date_columnlist[str] | NoneList of column names for date information. Defaults to configuration settings.["Trade Date"]
date_format_optionslist[str] | NoneList of date format strings to attempt when parsing date columns (e.g. [‘%Y-%m-%d’, ‘%d/%m/%Y’]). Defaults to configuration.["%d/%m/%Y"]
name_columnslist[str] | NoneList of column names for transaction descriptions. Defaults to configuration.["Description"]
ticker_columnslist[str] | NoneList of column names for asset tickers. Defaults to configuration.["Symbol"]
price_columnslist[str] | NoneList of column names for asset prices. Defaults to configuration.["Trade Price"]
volume_columnslist[str] | NoneList of column names for asset volumes. Defaults to configuration.["Shares"]
currency_columnslist[str] | NoneList of column names for transaction currencies. Defaults to configuration.["Trade Currency"]
costs_columnslist[str] | NoneList of column names for costs or income categories. Defaults to configuration.["Commission"]
column_mappingdict[str, str] | NoneDictionary mapping dataset columns to the appropriate field names. Defaults to configuration.configuration
Share