bayesline.api.equity.AsyncPortfolioApi#
- class bayesline.api.equity.AsyncPortfolioApi#
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 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 the portfolio groups.
Get the list of portfolio names.
Attributes
Get the name of the portfolio.
- abstract async 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 async 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 async 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) AsyncTask[DataFrame]#
- abstract async get_portfolio_names() list[str]#
Get the list of portfolio names.
Returns#
- list[str]
The list of portfolio names.
- abstract async 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 async 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 async 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 async 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) AsyncTask[DataFrame]#