bayesline.api.equity.CategoricalExposureGroupSettings#

pydantic model bayesline.api.equity.CategoricalExposureGroupSettings#

The settings for a categorical exposure group.

Categorical exposures are exposures to a categorical variable, e.g. industry, country, etc. For example, an asset exposure may be to a single industry factor, and we say the exposure is to the industry category factor “Materials”. The exposure itself may be continuous (e.g. not 0.0 or 1.0), and an asset may be exposed to multiple industry factors (but typically not all of them). The distinction with continuous exposures is primarily in the settings that are available.

Show JSON schema
{
   "title": "CategoricalExposureGroupSettings",
   "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.",
   "type": "object",
   "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"
      }
   },
   "$defs": {
      "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"
      }
   },
   "additionalProperties": false,
   "required": [
      "hierarchy"
   ]
}

Config:
  • frozen: bool = True

  • extra: str = forbid

Fields:
  • exclude (list[str])

  • exposure_type (Literal['categorical'])

  • factor_group (str)

  • hierarchy (bayesline.api._src.equity.exposure_settings.HierarchyLevel | bayesline.api._src.equity.exposure_settings.HierarchyGroups)

  • include (Literal['All'] | list[str])

Validators:
  • check_valid_factor_group » factor_group

  • set_factor_group » all fields

  • validate_filters » all fields

field exposure_type: Literal['categorical'] = 'categorical'#
Validated by:
  • set_factor_group

  • validate_filters

field hierarchy: Annotated[HierarchyType, Field(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.', examples=['trbc', HierarchyLevel(name='trbc', level=2), HierarchyGroups(name='style', groupings={'MyGroup1': ['Energy'], 'MyGroup2': ['Materials', 'Chemicals']})])] [Required]#

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.

Constraints:
  • func = <function _hierarchy_name_to_hierarchy_level at 0x7fe2ecbeb380>

  • json_schema_input_type = PydanticUndefined

Validated by:
  • set_factor_group

  • validate_filters

field factor_group: str = ''#

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.

Validated by:
  • check_valid_factor_group

  • set_factor_group

  • validate_filters

field include: Literal['All'] | list[str] = 'All'#

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.

Validated by:
  • set_factor_group

  • validate_filters

field exclude: list[str] [Optional]#

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.

Validated by:
  • set_factor_group

  • validate_filters

validator set_factor_group Any  »  all fields#
validator check_valid_factor_group str  »  factor_group#
validator validate_filters CategoricalExposureGroupSettings  »  all fields#
property hierarchies: list[Annotated[HierarchyLevel | HierarchyGroups, FieldInfo(annotation=NoneType, required=True, discriminator='hierarchy_type'), BeforeValidator(func=_hierarchy_name_to_hierarchy_level, json_schema_input_type=PydanticUndefined)]]#

The list of hierarchies for the exposure group.

Returns#

list[HierarchyType]

The list of hierarchies for the exposure group.

effective_exposure_group_factors(menu: ExposureSettingsMenu) list[str]#

Get the effective factors.

Effective factors are the factors that are included and not excluded in the exposure group settings.

Parameters#

menuExposureSettingsMenu

The menu to get the total factors from.

Returns#

list[str]

The list of effective factors.

normalize_group_settings(menu: ExposureSettingsMenu, universe_filter_dict: Mapping[str, CategoricalFilterSettings] | None) CategoricalExposureGroupSettings#

Normalize the exposure group settings.

Normalized group settings have all hierarchies replaced by HierarchyGroups with two levels, the factor names and the leaf codes. All includes and excludes are resolved.

This means that if the universe_filter_dict has 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#

menuExposureSettingsMenu

The menu to get the total factors from.

universe_filter_dictMapping[str, CategoricalFilterSettings] | None

The universe filter dictionary to potentially further cut the factors down. The keys are the hierarchy names and the values are the filter settings. If None, then no filtering is performed.

Returns#

CategoricalExposureGroupSettings

The normalized exposure group settings.