bayesline.api.equity.AsyncUniverseApi#
- class bayesline.api.equity.AsyncUniverseApi#
Provide access to universe data and operations.
A universe represents a filtered set of assets with specific properties.
- __init__()#
Methods
__init__()counts([dates, ...])Get universe counts with optional grouping and aggregation.
counts_as_task([dates, ...])coverage([id_type])Get the list of all asset IDs this universe covers.
coverage_as_task([id_type])dates(*[, range_only, trade_only])Get the list of all dates this universe covers.
get(*[, start, end, id_type, filter_tradedays])Get universe data for a specific date range.
get_as_task(*[, start, end, id_type, ...])input_id_mapping(*[, id_type, filter_mode, mode])Get input ID mappings with various filtering and output modes.
Attributes
Get the supported ID types for this universe.
Get the settings used to create this universe.
- abstract property settings: UniverseSettings#
Get the settings used to create this universe.
Returns#
- UniverseSettings
The settings used to create this universe.
- abstract property id_types: list[Literal['bayesid', 'bayesid_core', 'ticker', 'composite_figi', 'cik', 'cusip8', 'cusip9', 'isin', 'sedol6', 'sedol7', 'proxy', 'name']]#
Get the supported ID types for this universe.
Returns#
- list[IdType]
Supported ID types for this universe.
- abstract async coverage(id_type: Literal['bayesid', 'bayesid_core', 'ticker', 'composite_figi', 'cik', 'cusip8', 'cusip9', 'isin', 'sedol6', 'sedol7', 'proxy', 'name'] | None = None) list[str]#
Get the list of all asset IDs this universe covers.
Parameters#
- id_typeIdType | None, default=None
The ID type to return asset IDs in, e.g. ticker.
Raises#
- ValueError
If the given ID type is not supported.
Returns#
- list[str]
List of all asset IDs this universe covers, in the given ID type.
- abstract async coverage_as_task(id_type: Literal['bayesid', 'bayesid_core', 'ticker', 'composite_figi', 'cik', 'cusip8', 'cusip9', 'isin', 'sedol6', 'sedol7', 'proxy', 'name'] | None = None) AsyncTask[list[str]]#
- abstract async dates(*, range_only: bool = False, trade_only: bool = False) list[date]#
Get the list of all dates this universe covers.
Parameters#
- range_onlybool, default=False
If True, returns the first and last date only.
- trade_onlybool, default=False
If True, filter down the dates to trade dates only.
Returns#
- list[dt.date]
List of all dates this universe covers.
- abstract async counts(dates: bool = True, categorical_hierarchy_levels: dict[str, int] | None = None, id_type: Literal['bayesid', 'bayesid_core', 'ticker', 'composite_figi', 'cik', 'cusip8', 'cusip9', 'isin', 'sedol6', 'sedol7', 'proxy', 'name'] | None = None, labels: bool = True) DataFrame#
Get universe counts with optional grouping and aggregation.
Parameters#
- datesbool, default=True
If True, groups by dates.
- categorical_hierarchy_levelsdict[str, int] | None, default=None
The level of categorical aggregation to group by. The key is the hierarchy name, the value is the level. If None, no categorical aggregation is done. A level of -1 means to use all levels.
- id_typeIdType | None, default=None
The ID type to calculate the daily stats for, e.g. ticker, which is relevant as the coverage may differ by ID type. The given ID type must be supported, i.e. in id_types.
- labelsbool, default=True
If True, return labels for the counts, otherwise use the codes.
Returns#
- pl.DataFrame
Universe counts. If grouped by dates then the count will be given. If not grouped by dates then the mean/min/max across all dates will be given.
- abstract async counts_as_task(dates: bool = True, categorical_hierarchy_levels: dict[str, int] | None = None, id_type: Literal['bayesid', 'bayesid_core', 'ticker', 'composite_figi', 'cik', 'cusip8', 'cusip9', 'isin', 'sedol6', 'sedol7', 'proxy', 'name'] | None = None, labels: bool = True) AsyncTask[DataFrame]#
- abstract async input_id_mapping(*, id_type: Literal['bayesid', 'bayesid_core', 'ticker', 'composite_figi', 'cik', 'cusip8', 'cusip9', 'isin', 'sedol6', 'sedol7', 'proxy', 'name'] | None = None, filter_mode: Literal['all', 'mapped', 'unmapped'] = 'all', mode: Literal['all', 'daily-counts', 'input-asset-counts', 'latest-name'] = 'all') DataFrame#
Get input ID mappings with various filtering and output modes.
Parameters#
- id_typeIdType | None, default=None
The ID type to return asset IDs in, e.g. ticker, or the default ID type of the universe if None.
- filter_modeLiteral[“all”, “mapped”, “unmapped”], default=”all”
If mapped will only consider assets that could be mapped. If unmapped will only consider assets that could not be mapped.
- modeLiteral[“all”, “daily-counts”, “input-asset-counts”, “latest-name”], default=”all” # noqa: B950
If all, returns all dated mappings. If daily-counts, returns the daily counts of mapped assets. If input-asset-counts, returns the total counts of input assets. If latest-name, returns the latest name of mapped assets.
Returns#
- pl.DataFrame
If mode is all, a DataFrame with date, input_asset_id, input_asset_id_type, output_asset_id, output_asset_id_type and name columns. It contains the original input ID space and the mapped IDs. The mapped IDs will be None if for the given date and input ID the asset cannot be mapped. If mode is daily-counts, a DataFrame with date and count columns. If mode is input-asset-counts, a DataFrame with input_asset_id and count columns. If mode is latest-name, a DataFrame with asset_id and name columns.
- abstract async get(*, start: str | date | datetime | None = None, end: str | date | datetime | None = None, id_type: Literal['bayesid', 'bayesid_core', 'ticker', 'composite_figi', 'cik', 'cusip8', 'cusip9', 'isin', 'sedol6', 'sedol7', 'proxy', 'name'] | None = None, filter_tradedays: bool = False) DataFrame#
Get universe data for a specific date range.
Parameters#
- startDateLike | None, default=None
The start date of the universe to return, inclusive.
- endDateLike | None, default=None
The end date of the data to return, inclusive.
- id_typeIdType | None, default=None
The ID type to return asset IDs in, e.g. ticker. The given ID type must be supported, i.e. in id_types.
- filter_tradedaysbool, default=False
If True, filter down the data to trade dates only.
Raises#
- ValueError
If the given ID type is not supported or date range is invalid.
Returns#
- pl.DataFrame
The data for the given date range.
- abstract async get_as_task(*, start: str | date | datetime | None = None, end: str | date | datetime | None = None, id_type: Literal['bayesid', 'bayesid_core', 'ticker', 'composite_figi', 'cik', 'cusip8', 'cusip9', 'isin', 'sedol6', 'sedol7', 'proxy', 'name'] | None = None, filter_tradedays: bool = False) AsyncTask[DataFrame]#