bayesline.api.equity.PortfolioApi#

class bayesline.api.equity.PortfolioApi#

Abstract base class for portfolio APIs.

This class defines the interface for portfolio APIs that provide access to portfolio data and metadata.

__init__()#

Methods

__init__()

get_coverage([names, by, metric, stats])

Get coverage information for portfolios.

get_coverage_as_task([names, by, metric, stats])

get_dates([names, collapse])

Get the available dates for portfolios.

get_id_types()

Get the available ID types for each portfolio.

get_portfolio(names[, start_date, end_date, ...])

Get portfolios for the given names between given start and end dates.

get_portfolio_as_task(names[, start_date, ...])

get_portfolio_groups()

Get the portfolio groups.

get_portfolio_names()

Get the list of portfolio names.

Attributes

name

Get the name of the portfolio.

abstract property name: str#

Get the name of the portfolio.

Returns#

str

The name of the portfolio.

abstract get_id_types() dict[str, list[Literal['bayesid', 'bayesid_core', 'ticker', 'composite_figi', 'cik', 'cusip8', 'cusip9', 'isin', 'sedol6', 'sedol7', 'proxy', 'name']]]#

Get the available ID types for each portfolio.

Returns#

dict[str, list[IdType]]

The available ID types that at least a portion of assets can be mapped to for each portfolio.

abstract get_coverage(names: str | list[str] | None = None, *, by: Literal['date', 'asset'] = 'date', metric: Literal['count', 'holding'] = 'count', stats: list[str] | None = None) DataFrame#

Get coverage information for portfolios.

Parameters#

namesstr | list[str] | None, default=None

The names of the portfolios. If not given all portfolios will be calculated.

byLiteral[“date”, “asset”], default=”date”

The coverage aggregation, either by date or by asset.

metricLiteral[“count”, “holding”], default=”count”

The metric to calculate, either count of observations or sum of holding values.

statslist[str] | None, default=None

List of ‘min’, ‘max’, ‘mean’, collapses by into these stats.

Returns#

pl.DataFrame

The dated coverage count for each id type. portfolio_group and portfolio are the first two columns. If stats given, collapses the by index to the given aggregations.

abstract get_coverage_as_task(names: str | list[str] | None = None, *, by: Literal['date', 'asset'] = 'date', metric: Literal['count', 'holding'] = 'count', stats: list[str] | None = None) Task[DataFrame]#
abstract get_portfolio_names() list[str]#

Get the list of portfolio names.

Returns#

list[str]

The list of portfolio names.

abstract get_portfolio_groups() dict[str, list[str]]#

Get the portfolio groups.

Returns#

dict[str, list[str]]

A dictionary mapping group names to lists of portfolio names.

abstract get_dates(names: list[str] | str | None = None, *, collapse: bool = False) dict[str, list[date]]#

Get the available dates for portfolios.

Parameters#

nameslist[str] | str | None, default=None

The portfolio names to get dates for.

collapsebool, default=False

Whether to collapse the results.

Returns#

dict[str, list[dt.date]]

A dictionary mapping portfolio names to lists of available dates.

abstract get_portfolio(names: list[str] | str, start_date: str | date | datetime | None = None, end_date: str | date | datetime | None = None, id_type: Literal['bayesid', 'bayesid_core', 'ticker', 'composite_figi', 'cik', 'cusip8', 'cusip9', 'isin', 'sedol6', 'sedol7', 'proxy', 'name'] | None = None) DataFrame#

Get portfolios for the given names between given start and end dates.

Parameters#

nameslist[str] | str

The list of portfolio names.

start_dateDateLike | None, default=None

The start date of the data to return, inclusive.

end_dateDateLike | None, default=None

The end date of the data to return, inclusive.

id_typeIdType | None, default=None

ID type to return the portfolio holdings in.

Returns#

pl.DataFrame

A dataframe with columns portfolio_group, portfolio, date, input_asset_id, input_asset_id_type, asset_id, asset_id_type and value.

If no id_type is given then the input ID space will be used unmapped. In this case the columns asset_id, asset_id_type will not be returned.

abstract get_portfolio_as_task(names: list[str] | str, start_date: str | date | datetime | None = None, end_date: str | date | datetime | None = None, id_type: Literal['bayesid', 'bayesid_core', 'ticker', 'composite_figi', 'cik', 'cusip8', 'cusip9', 'isin', 'sedol6', 'sedol7', 'proxy', 'name'] | None = None) Task[DataFrame]#