bayesline.api.equity.AsyncPortfolioImpl#
- class bayesline.api.equity.AsyncPortfolioImpl(dataset: str, settings: PortfolioSettings, report_loader: AsyncReportLoaderApi, metadata: AsyncPortfolioMetadata) None#
Report-backed portfolio facade.
Serves calculations and calculated identities from reports. The metadata backend is limited to source state that reports do not own.
- __init__(dataset: str, settings: PortfolioSettings, report_loader: AsyncReportLoaderApi, metadata: AsyncPortfolioMetadata) None#
Methods
__init__(dataset, settings, report_loader, ...)get_coverage([names, by, metric, stats, ...])Get coverage information for portfolios.
get_coverage_as_task([names, by, metric, ...])get_dates([names, collapse])Get raw holdings snapshot dates for the selected portfolios.
Get the fund-of-funds graph for the underlying portfolio source(s).
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.
Get the list of portfolios with per-portfolio metadata.
Attributes
Get the name of the portfolio.
- __init__(dataset: str, settings: PortfolioSettings, report_loader: AsyncReportLoaderApi, metadata: AsyncPortfolioMetadata) None#
- async get_id_types() dict[str, list[str]]#
Get the available ID types for each portfolio.
Returns#
- dict[str, list[IdType]]
["bayesid"]for each portfolio. Other output ID types are not currently supported by the report-backed façade.
- async get_portfolio_names() list[str]#
Get the list of portfolio names.
Returns#
- list[str]
The list of portfolio names.
- async get_portfolios() list[PortfolioName]#
Get the list of portfolios with per-portfolio metadata.
Same identifiers as
get_portfolio_names()plus per-portfolio metadata (currentlyfof_depth) that the GUI uses to render the picker with FoF awareness. The list is in the same order asget_portfolio_names().Returns#
- list[PortfolioName]
The list of portfolios with metadata.
- 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.
- async get_fof_graph() dict[str, list[str]]#
Get the fund-of-funds graph for the underlying portfolio source(s).
Returns#
- dict[str, list[str]]
Mapping
parent_portfolio_id -> list[child_portfolio_id]. Children are theasset_idvalues from rows whereasset_id_type == "portfolio_id". Collapsed across dates. Empty dict when the source has no FoF rows.
- async get_dates(names: list[str] | str | None = None, *, collapse: bool = False) dict[str, list[date]]#
Get raw holdings snapshot dates for the selected portfolios.
Parameters#
- nameslist[str] | str | None, default=None
The portfolio names to get dates for; None selects all portfolios.
- collapsebool, default=False
Whether to collapse the per-portfolio dates into
all/anykeys instead of returning one entry per portfolio.
Returns#
- dict[str, list[dt.date]]
A dictionary mapping portfolio names (or the
all/anykeys when collapsed) to lists of snapshot dates.
- async get_coverage(names: str | list[str] | None = None, *, by: Literal['date', 'asset'] = 'date', metric: Literal['count', 'holding'] = 'count', stats: list[Literal['min', 'max', 'mean']] | None = None, start_date: str | date | datetime | None = None, end_date: str | date | datetime | 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 in USD. Mapped holdings are repriced daily; an unmapped holding carries its uploaded nav, converted to USD at its snapshot date, or zero when only a quantity was uploaded.
- statslist[CoverageStat] | None, default=None
List of ‘min’, ‘max’, ‘mean’, collapses by into these stats.
- start_dateDateLike | None, default=None
If given, only consider holdings on or after this date. Combined with
end_date(e.g. both set to a portfolio’s latest holdings date) this scopesby="asset"coverage to a single day.- end_dateDateLike | None, default=None
If given, only consider holdings on or before this date.
Returns#
- pl.DataFrame
Coverage values in exactly two metric columns:
inputfor raw identifier observations andbayesidfor observations resolved into the dataset. Dimensions includeportfolio_group,portfolio_id,asset_id_type, and the selected date or asset axis. Ifstatsis given, that axis is replaced by astatcolumn.
- async get_coverage_as_task(names: str | list[str] | None = None, *, by: Literal['date', 'asset'] = 'date', metric: Literal['count', 'holding'] = 'count', stats: list[Literal['min', 'max', 'mean']] | None = None, start_date: str | date | datetime | None = None, end_date: str | date | datetime | None = None) AsyncTask[DataFrame]#
- async get_portfolio(names: list[str] | str, start_date: str | date | datetime | None = None, end_date: str | date | datetime | None = None, id_type: str | None = None, *, currency: str = 'USD') 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
Output ID type. Only
Noneand"bayesid"are currently supported.- currencystr, default=”USD”
The currency to return the forward-filled, looked-through holdings in.
Returns#
- pl.DataFrame
A forward-filled, fully looked-through dataframe with columns
date,portfolio_group,portfolio_id,input_asset_id_type,input_asset_id,asset_id_type,asset_id,currency,share_qty, andnav.asset_id_typeis alwaysbayesidfor leaf assets.