bayesline.api.equity.PortfolioApi#
- class bayesline.api.equity.PortfolioApi#
Bases:
ABC
Methods
__init__
()get_coverage
([names, by, metric, stats])Parameters names: str | list[str], optional The names of the portfolios. If not given all portfolios will be calculated. by: str, optional The coverage aggregation, either by date or by asset. metric: str, optional The metric to calculate, either count of observations or sum of holding values. stats: list[str], optional list of 'min', 'max', 'mean', collapses by into these stats.
get_dates
([names, collapse])Returns dict[str, list[IdType]]: The available ID types that at least a portion of assets can be mapped to for each portfolio.
get_portfolio
(names[, start_date, end_date, ...])Obtains the portfolios for the given names between given start and end dates.
Attributes
- abstract get_id_types() dict[str, list[Literal['bayesid', 'ticker', 'composite_figi', 'cik', 'cusip8', 'cusip9', 'isin', 'sedol6', 'sedol7', 'proxy', 'name']]] #
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 #
Parameters#
- names: str | list[str], optional
The names of the portfolios. If not given all portfolios will be calculated.
- by: str, optional
The coverage aggregation, either by date or by asset.
- metric: str, optional
The metric to calculate, either count of observations or sum of holding values.
- stats: list[str], optional
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_dates(names: list[str] | str | None = None, *, collapse: bool = False) dict[str, list[date]] #
- 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', 'ticker', 'composite_figi', 'cik', 'cusip8', 'cusip9', 'isin', 'sedol6', 'sedol7', 'proxy', 'name'] | None = None) DataFrame #
Obtains the portfolios for the given names between given start and end dates.
Parameters#
- names: list[str] | str
The list of portfolio names.
- start_date: DateLike, optional
The start date of the data to return, inclusive.
- end_date: DateLike, optional
The end date of the data to return, inclusive.
- id_type: IdType, optional
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.