portfolio_optimization.components.io module

This module implements I/O

class portfolio_optimization.components.io.PortfolioData(portfolio_dataframe, columns_rename=None)[source]

Bases: object

The PortfolioData stores the data used for portfolio optimization.

__contains__(other)[source]

Check if other is part of the dataset.

Return type:

bool

__init__(portfolio_dataframe, columns_rename=None)[source]

Creates a PortfolioData object from a pandas DataFrame.

The portfolio data is expected to contain at least the following columns names:

  • "assets": The name of the asset.

  • "outstanding_now_now": Current outstanding amount per asset.

  • "min_outstanding_future": Lower bound outstanding amount in the future per asset.

  • "max_outstanding_future": Upper bound outstanding amount in the future per asset.

  • "income_now": Current income per asset, corresponds to return multiplied by the current outstanding amount.

  • "regcap_now": Current regulatory capital per asset.

Different column names in the dataset can be used but need to be provided as a renaming dictionary to the columns_rename argument.

Parameters:
  • portfolio_dataframe (DataFrame) – Pandas DataFrame containing the portfolio data.

  • column_rename – to rename columns provided as dict with new column names as keys and to replace column name as value. Example {"outstanding_2021": "outstanding_now"}.

Raises:

ValueError if required columns are not present in dataset.

__len__()[source]

Length of the dataset.

Return type:

int

__repr__()[source]

Representation for debugging.

Return type:

str

__str__()[source]

String representation of the PortfolioData object.

Return type:

str

classmethod from_file(filename, columns_rename=None)[source]

Reads portfolio data object into PortfolioData.

The portfolio data is expected to contain at least the following columns names:

  • "assets": The name of the asset.

  • "outstanding_now_now": Current outstanding amount per asset.

  • "min_outstanding_future": Lower bound outstanding amount in the future per asset.

  • "max_outstanding_future": Upper bound outstanding amount in the future per asset.

  • "income_now": Current income per asset, corresponds to return multiplied by the current outstanding amount.

  • "regcap_now": Current regulatory capital per asset.

Different column names in the dataset can be used but need to be provided as a renaming dictionary to the columns_rename argument.

Parameters:
  • filename (str | Path) – path to portfolio data. If instead benchmark_dataset is provided, a default benchmark dataset containing 52 assets will be used.

  • column_rename – to rename columns provided as dict with new column names as keys and to replace column name as value. Example {"outstanding_2021": "outstanding_now"}.

Raises:

ValueError if required columns are not present in dataset.

Return type:

TypeVar(PortfolioDataT, bound= PortfolioData)

get_capital()[source]

Gets the capital data from the dataset.

Return type:

ndarray[Any, dtype[float64]]

Returns:

The regcap_now column from the dataset as a numpy array.

get_column(column_name)[source]

Gets the specified column from the dataset.

Parameters:

column_name (str) – Name of the column to get.

Return type:

ndarray[Any, dtype[float64]]

Returns:

The regcap_now columns from the dataset as a numpy array.

get_income()[source]

Gets the income data from the dataset.

Return type:

ndarray[Any, dtype[float64]]

Returns:

The income_now column from the dataset as a numpy array.

get_l_bound()[source]

Gets the l_bound data from the dataset.

Return type:

ndarray[Any, dtype[float64]]

Returns:

The min_outstanding_future column from the dataset as a numpy array.

get_outstanding_now()[source]

Gets the outstanding_now data from the dataset.

Return type:

ndarray[Any, dtype[float64]]

Returns:

The outstanding_now column from the dataset as a numpy array.

get_returns()[source]

Gets the returns data from the dataset.

Return type:

ndarray[Any, dtype[float64]]

Returns:

Returns is defined as income / outstanding_now

get_u_bound()[source]

Gets the u_bound data from the dataset.

Return type:

ndarray[Any, dtype[float64]]

Returns:

The max_outstanding_future column from the dataset as a numpy array.

print_portfolio_info()[source]

Prints information about portfolio data to terminal.

Return type:

None