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_fof_graph()

Get the fund-of-funds graph for the underlying portfolio source(s).

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.

get_portfolios()

Get the list of portfolios with per-portfolio metadata.

Attributes

name

Get the name of the portfolio.

__init__(dataset: str, settings: PortfolioSettings, report_loader: AsyncReportLoaderApi, metadata: AsyncPortfolioMetadata) None#
property name: str#

Get the name of the portfolio.

Returns#

str

The name of the portfolio.

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 (currently fof_depth) that the GUI uses to render the picker with FoF awareness. The list is in the same order as get_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 the asset_id values from rows where asset_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 / any keys instead of returning one entry per portfolio.

Returns#

dict[str, list[dt.date]]

A dictionary mapping portfolio names (or the all / any keys 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 scopes by="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: input for raw identifier observations and bayesid for observations resolved into the dataset. Dimensions include portfolio_group, portfolio_id, asset_id_type, and the selected date or asset axis. If stats is given, that axis is replaced by a stat column.

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 None and "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, and nav. asset_id_type is always bayesid for leaf assets.

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: str | None = None, *, currency: str = 'USD') AsyncTask[DataFrame]#