bayesline.api.equity.FactorModelApi#

class bayesline.api.equity.FactorModelApi#

Provide access to factor risk model data and operations.

A factor risk model provides exposure data, factor returns, and other risk metrics for a set of assets based on predefined factors.

__init__()#

Methods

__init__()

dates()

Get all dates covered by this risk model.

estimation_universe(*[, start, end, ...])

Get the risk model estimation universe for this risk model.

estimation_universe_as_task(*[, start, end, ...])

exposures(*[, start, end, id_type, stage])

Get the risk model exposures for this risk model.

exposures_as_task(*[, start, end, id_type, ...])

factors()

Get the factor groups and their factors.

fret(*[, freq, cumulative, start, end])

Get factor returns for the given date range.

fret_as_task(*[, freq, cumulative, start, end])

future_asset_returns(*[, start, end, id_type])

Get the asset returns for this risk model on the next day.

future_asset_returns_as_task(*[, start, ...])

market_caps(*[, start, end, id_type])

Get the exposure-weighted market caps for this risk model.

market_caps_as_task(*[, start, end, id_type])

p_values()

Get p-values for the risk model factors.

p_values_as_task()

r2()

Get R-squared values for the factor model.

r2_as_task()

sigma2()

Get sigma squared values for the factor model.

sigma2_as_task()

t_stats()

Get t-statistics for the factor model.

t_stats_as_task()

universe(*[, start, end, id_type, stage])

Get the risk model universe for this risk model.

universe_as_task(*[, start, end, id_type, stage])

weights(*[, start, end, id_type])

Get the idiosyncratic volatility weights for this risk model.

weights_as_task(*[, start, end, id_type])

abstract dates() list[date]#

Get all dates covered by this risk model.

Returns#

list[dt.date]

All dates covered by this risk model.

abstract factors() dict[str, list[str]]#

Get the factor groups and their factors.

Returns#

dict[str, list[str]]

Dict where the keys are the included factor groups, and the values are the factors in that group.

abstract exposures(*, 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, stage: int = 1) DataFrame#

Get the risk model exposures for this risk model.

Parameters#

startDateLike | None, default=None

The start date of the data 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 by the linked universe.

stageint, default=1

The stage of the factor model to return exposures for, of the potentially multi-stage regression. Default to 1 (the first stage).

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 with the first two column as the date and asset id. The remaining columns are the individual styles.

abstract exposures_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, stage: int = 1) Task[DataFrame]#
abstract universe(*, 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, stage: int = 1) DataFrame#

Get the risk model universe for this risk model.

Parameters#

startDateLike | None, default=None

The start date of the data 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 by the linked universe.

stageint, default=1

The stage of the factor model to return universe for, of the potentially multi-stage regression. Default to 1 (the first stage).

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 where the first column is the date and the remaining columns are the asset ids. The values are the universe inclusion.

abstract universe_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, stage: int = 1) Task[DataFrame]#
abstract estimation_universe(*, 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, stage: int = 1) DataFrame#

Get the risk model estimation universe for this risk model.

Parameters#

startDateLike | None, default=None

The start date of the data 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 by the linked universe.

stageint, default=1

The stage of the factor model to return universe for, of the potentially multi-stage regression. Default to 1 (the first stage).

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 where the first column is the date and the remaining columns are the asset ids. The values are the estimation universe inclusion.

abstract estimation_universe_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, stage: int = 1) Task[DataFrame]#
abstract market_caps(*, 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) DataFrame#

Get the exposure-weighted market caps for this risk model.

Parameters#

startDateLike | None, default=None

The start date of the data 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 by the linked universe.

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 where the rows are the total market cap for each date, weighted by the exposure of each asset. For industry factors, this specifically means that the value is the sum of all assets in the estimation universe in that industry.

abstract market_caps_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) Task[DataFrame]#
abstract weights(*, 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) DataFrame#

Get the idiosyncratic volatility weights for this risk model.

Parameters#

startDateLike | None, default=None

The start date of the data 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 by the linked universe.

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 where the rows are the idiosyncratic volatility for each date.

abstract weights_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) Task[DataFrame]#
abstract future_asset_returns(*, 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) DataFrame#

Get the asset returns for this risk model on the next day.

Parameters#

startDateLike | None, default=None

The start date of the data 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 by the linked universe.

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 where the index is the date and the columns are the asset id. The values are the asset returns.

abstract future_asset_returns_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) Task[DataFrame]#
abstract fret(*, freq: str | None = None, cumulative: bool = False, start: str | date | datetime | None = None, end: str | date | datetime | None = None) DataFrame#

Get factor returns for the given date range.

Parameters#

freqstr | None, default=None

The frequency of the return aggregation, e.g. D for daily. Defaults to daily (i.e. unaggregated).

cumulativebool, default=False

If True, returns the cumulative returns.

startDateLike | None, default=None

The start date of the data to return, inclusive.

endDateLike | None, default=None

The end date of the data to return, inclusive.

Returns#

pl.DataFrame

The factor returns for the given date range.

abstract fret_as_task(*, freq: str | None = None, cumulative: bool = False, start: str | date | datetime | None = None, end: str | date | datetime | None = None) Task[DataFrame]#
abstract t_stats() DataFrame#

Get t-statistics for the factor model.

Returns#

pl.DataFrame

The t-statistics for the factor model.

abstract t_stats_as_task() Task[DataFrame]#
abstract p_values() DataFrame#

Get p-values for the risk model factors.

Returns#

pl.DataFrame

The p-values for the risk model factors.

abstract p_values_as_task() Task[DataFrame]#
abstract r2() DataFrame#

Get R-squared values for the factor model.

Returns#

pl.DataFrame

The R-squared values for the factor model.

abstract r2_as_task() Task[DataFrame]#
abstract sigma2() DataFrame#

Get sigma squared values for the factor model.

Returns#

pl.DataFrame

The sigma squared values for the factor model.

abstract sigma2_as_task() Task[DataFrame]#