pyvallocation.utils.data_helpers module

This module provides helper functions for converting between pandas DataFrames and NumPy arrays, primarily for handling financial time series data and portfolio weights. These utilities facilitate seamless data manipulation for various asset allocation and portfolio optimization tasks.

Helpers for converting between pandas and NumPy structures.

pyvallocation.utils.data_helpers.numpy_weights_to_pandas_series(weights: numpy.ndarray, asset_names: List[str]) pandas.Series[source]

Convert a 1D numpy array of weights to a pandas Series with asset names as index.

pyvallocation.utils.data_helpers.pandas_to_numpy_returns(dataframe: pandas.DataFrame, price_columns: List[str] | None = None, date_column: str | None = None, return_calculation_method: str = 'log', fill_na_method: str = 'ffill') numpy.ndarray[source]

Convert a pandas DataFrame of prices to a numpy array of returns.

Functions

pyvallocation.utils.data_helpers.pandas_to_numpy_returns(dataframe: pandas.DataFrame, price_columns: List[str] | None = None, date_column: str | None = None, return_calculation_method: str = 'log', fill_na_method: str = 'ffill') numpy.ndarray[source]

Convert a pandas DataFrame of prices to a numpy array of returns.

pyvallocation.utils.data_helpers.numpy_weights_to_pandas_series(weights: numpy.ndarray, asset_names: List[str]) pandas.Series[source]

Convert a 1D numpy array of weights to a pandas Series with asset names as index.