bayesline.api.equity.ExposureSettings#
- pydantic model bayesline.api.equity.ExposureSettings#
Defines exposures as hierarchy of selected styles and substyles.
Show JSON schema
{ "title": "ExposureSettings", "description": "Defines exposures as hierarchy of selected styles and substyles.", "type": "object", "properties": { "exposures": { "default": [], "description": "The exposures to build the factor risk model on.", "items": { "discriminator": { "mapping": { "categorical": "#/$defs/CategoricalExposureGroupSettings", "continuous": "#/$defs/ContinuousExposureGroupSettings", "interaction": "#/$defs/InteractionExposureGroupSettings" }, "propertyName": "exposure_type" }, "oneOf": [ { "$ref": "#/$defs/ContinuousExposureGroupSettings" }, { "$ref": "#/$defs/CategoricalExposureGroupSettings" }, { "$ref": "#/$defs/InteractionExposureGroupSettings" } ] }, "title": "Exposures", "type": "array" } }, "$defs": { "CategoricalExposureGroupSettings": { "additionalProperties": false, "description": "The settings for a categorical exposure group.\n\nCategorical exposures are exposures to a categorical variable, e.g. industry,\ncountry, etc. For example, an asset exposure may be to a single industry factor,\nand we say the exposure is to the industry category factor \"Materials\". The exposure\nitself may be continuous (e.g. not 0.0 or 1.0), and an asset may be exposed to\nmultiple industry factors (but typically not all of them). The distinction with\ncontinuous exposures is primarily in the settings that are available.", "properties": { "exposure_type": { "const": "categorical", "default": "categorical", "title": "Exposure Type", "type": "string" }, "hierarchy": { "description": "The hierarchy to use for the categorical exposures. This is either aHierarchyLevel or HierarchyGroups object. If a string is passed, the value is converted to a HierarchyLevel of that hierarchy with level=1.", "discriminator": { "mapping": { "groups": "#/$defs/HierarchyGroups", "level": "#/$defs/HierarchyLevel" }, "propertyName": "hierarchy_type" }, "examples": [ "trbc", { "hierarchy_type": "level", "level": 2, "name": "trbc" }, { "groupings": { "MyGroup1": [ "Energy" ], "MyGroup2": [ "Materials", "Chemicals" ] }, "hierarchy_type": "groups", "name": "style" } ], "oneOf": [ { "$ref": "#/$defs/HierarchyLevel" }, { "$ref": "#/$defs/HierarchyGroups" } ], "title": "Hierarchy" }, "factor_group": { "default": "", "description": "By default, the name of the factor group will be the name of the hierarchy. But we can override this by specifying an alias here.", "examples": [ "industry", "some_country_group" ], "title": "Factor Group", "type": "string" }, "include": { "anyOf": [ { "const": "All", "type": "string" }, { "items": { "type": "string" }, "type": "array" } ], "default": "All", "description": "Valid industry codes or labels for given hierarchy at any level. If labels are used which may be duplicated, then the code with the highest level is used. If 'All', all codes are included.", "examples": [ [ "3571" ], "All", [ "Materials", "1010" ], [ "Europe", "CAN" ] ], "title": "Include" }, "exclude": { "description": "Valid industry codes or labels for given hierarchy at any level. If labels are used which may be duplicated, then the code with the lowest level is used.", "examples": [ [ "3571" ], [ "Materials", "1010" ], [ "JPN" ] ], "items": { "type": "string" }, "title": "Exclude", "type": "array" } }, "required": [ "hierarchy" ], "title": "CategoricalExposureGroupSettings", "type": "object" }, "ContinuousExposureGroupSettings": { "additionalProperties": false, "description": "The settings for a continuous exposure group.\n\nContinuous exposures are exposures that are measured on a continuous scale,\ne.g. market, size, momentum, etc., and are typically available for most assets.", "properties": { "exposure_type": { "const": "continuous", "default": "continuous", "title": "Exposure Type", "type": "string" }, "hierarchy": { "description": "The hierarchy to use for the continuous exposures. This is either aHierarchyLevel or HierarchyGroups object. If a string is passed, the value is converted to a HierarchyLevel of that hierarchy with level=1.", "discriminator": { "mapping": { "groups": "#/$defs/HierarchyGroups", "level": "#/$defs/HierarchyLevel" }, "propertyName": "hierarchy_type" }, "examples": [ "market", { "hierarchy_type": "level", "level": 2, "name": "style" }, { "groupings": { "momentum": [ "mom6" ], "size": [ "size" ] }, "hierarchy_type": "groups", "name": "style" } ], "oneOf": [ { "$ref": "#/$defs/HierarchyLevel" }, { "$ref": "#/$defs/HierarchyGroups" } ], "title": "Hierarchy" }, "factor_group": { "default": "", "description": "By default, the name of the factor group will be the name of the hierarchy. But we can override this by specifying an alias here.", "examples": [ "style", "some_style_group" ], "title": "Factor Group", "type": "string" }, "include": { "anyOf": [ { "const": "All", "type": "string" }, { "items": { "type": "string" }, "type": "array" } ], "default": "All", "description": "Valid industry codes or labels for given hierarchy at any level. If labels are used which may be duplicated, then the code with the highest level is used. If 'All', all codes are included.", "examples": [ [ "momentum" ], "All", [ "Size", "value" ] ], "title": "Include" }, "exclude": { "description": "Valid industry codes or labels for given hierarchy at any level. If labels are used which may be duplicated, then the code with the lowest level is used.", "examples": [ [ "momentum" ], [ "Size", "value" ] ], "items": { "type": "string" }, "title": "Exclude", "type": "array" }, "standardize_method": { "default": "none", "description": "The method to use for standardizing the exposures. If 'none', no standardization is applied. If 'equal_weighted', then the exposures are standardized with the mean and standard deviation of the estimation universe.", "enum": [ "none", "equal_weighted" ], "examples": [ "none", "equal_weighted" ], "title": "Standardize Method", "type": "string" } }, "required": [ "hierarchy" ], "title": "ContinuousExposureGroupSettings", "type": "object" }, "Hierarchy": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "additionalProperties": { "$ref": "#/$defs/Hierarchy" }, "type": "object" } ] }, "HierarchyGroups": { "additionalProperties": false, "description": "The hierarchy decscription for a custom nested grouping of the hierarchy.\n\nThe top level groupings will turn into factors, whereas any nested\ngroupings will be retained for other uses (e.g. risk decomposition).", "properties": { "hierarchy_type": { "const": "groups", "default": "groups", "title": "Hierarchy Type", "type": "string" }, "name": { "description": "\n The name of the hierarchy to use, e.g. 'trbc' or 'continent'.\n If it is not given then the default hierarchy will be used.\n ", "examples": [ "trbc", "continent" ], "minLength": 1, "title": "Name", "type": "string" }, "groupings": { "additionalProperties": { "$ref": "#/$defs/Hierarchy" }, "description": "\n A nested structure of groupings where the keys are the group names\n and the leaf level is a list of hierarchy codes or labels (at any level)\n to include for this group.\n ", "title": "Groupings", "type": "object" } }, "required": [ "name", "groupings" ], "title": "HierarchyGroups", "type": "object" }, "HierarchyLevel": { "additionalProperties": false, "description": "The hierarchy decscription for a level in the hierarchy.\n\nE.g. for industries specifying level `1` would\ncreate top level sector factors.", "properties": { "hierarchy_type": { "const": "level", "default": "level", "title": "Hierarchy Type", "type": "string" }, "name": { "description": "\n The name of the hierarchy to use, e.g. 'trbc' or 'continent'.\n If it is not given then the default hierarchy will be used.\n ", "examples": [ "trbc", "continent" ], "minLength": 1, "title": "Name", "type": "string" }, "level": { "default": 1, "description": "The level of the hierarchy to use, e.g. 1\n to use all level 1 names (i.e. sectors for industries or\n continents for regions) or 2 to use all level 2\n names (i.e. sub-sectors for industries and\n countries for regions).\n ", "examples": [ 1, 2 ], "minimum": 1, "title": "Level", "type": "integer" } }, "required": [ "name" ], "title": "HierarchyLevel", "type": "object" }, "InteractionExposureGroupSettings": { "additionalProperties": false, "description": "The settings for an interaction exposure group.\n\nInteraction exposures are exposures that are a combination of two or more\nexposure groups. For example, we may want to create industry-specific style factors.", "properties": { "exposure_type": { "const": "interaction", "default": "interaction", "title": "Exposure Type", "type": "string" }, "exposure_groups": { "default": [], "description": "The exposure groups to use for the Cartesian product.", "items": { "anyOf": [ { "$ref": "#/$defs/ContinuousExposureGroupSettings" }, { "$ref": "#/$defs/CategoricalExposureGroupSettings" } ] }, "minItems": 2, "title": "Exposure Groups", "type": "array" }, "factor_group": { "default": "", "description": "By default, the name of the factor group will be a concatenation of the names of the exposure groups separated by the a colon.", "examples": [ "industry:style" ], "title": "Factor Group", "type": "string" } }, "title": "InteractionExposureGroupSettings", "type": "object" } }, "additionalProperties": false }
- Config:
frozen: bool = True
extra: str = forbid
- Fields:
exposures (list[bayesline.api._src.equity.exposure_settings.ContinuousExposureGroupSettings | bayesline.api._src.equity.exposure_settings.CategoricalExposureGroupSettings | bayesline.api._src.equity.exposure_settings.InteractionExposureGroupSettings])
- Validators:
validate_exposure_groups»exposures
- field exposures: Annotated[list[ExposureGroupSettings], BeforeValidator(_ensure_list), Field(description='The exposures to build the factor risk model on.')] = []#
The exposures to build the factor risk model on.
- Constraints:
func = <function _ensure_list at 0x7fe2ecbea340>
json_schema_input_type = PydanticUndefined
- Validated by:
validate_exposure_groups
Get the menu type for this settings object.
Returns#
- type[SettingsMenuType]
The menu type for this settings object.
- describe(menu: ExposureSettingsMenu) str#
Describe the exposure settings.
Parameters#
- menuExposureSettingsMenu
The menu to get context information from.
Returns#
- str
The description of the exposure settings.
- validator validate_exposure_groups list[Annotated[ContinuousExposureGroupSettings | CategoricalExposureGroupSettings | InteractionExposureGroupSettings, FieldInfo(annotation=NoneType, required=True, discriminator='exposure_type')]] » exposures#
- normalize(universe_settings: UniverseSettings | None, exposure_settings_menu: ExposureSettingsMenu) ExposureSettings#
Normalize the given exposure settings.
Normalize the given exposure settings by converting all exposure hierarchies to a HierarchyGroups object, and then filtering the hierarchy groupings based on the include and exclude statements in the exposure settings, and possibly the universe filters.
This means that if the UniverseSettings have a filter that trims down to just the North American region, and the ExposureSettings include factors from the same country hierarchy, then the factors will be trimmed down to just include the ones corresponding to the North American region.
Parameters#
- universe_settings: UniverseSettings | None
the universe settings to use for normalization. If None, then no normalization is performed in relation to the filters in the universe.
- exposure_settings_menu: ExposureSettingsMenu
The menu to get the total factors from.
Returns#
- ExposureSettings
A new exposure settings object with all exposure hierarchies converted to HierarchyGroups objects, and the hierarchy groupings filtered based on the include and exclude statements in the exposure settings, and possibly the universe filters. This normalized object is also validated.