bayesline.api.equity.PortfolioHierarchySettings#

pydantic model bayesline.api.equity.PortfolioHierarchySettings#

Specifies portfolio hierarchies with arbitrary groupings (e.g. manager, etc.).

Show JSON schema
{
   "title": "PortfolioHierarchySettings",
   "description": "Specifies portfolio hierarchies with arbitrary groupings (e.g. manager, etc.).",
   "type": "object",
   "properties": {
      "portfolio_schema": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "integer"
            },
            {
               "$ref": "#/$defs/PortfolioOrganizerSettings"
            }
         ],
         "description": "The portfolio organizer settings to use as an underlying schema of portfolios. The 'Default' schema is used by default.",
         "title": "Portfolio Schema"
      },
      "groupings": {
         "additionalProperties": {
            "items": {
               "type": "string"
            },
            "type": "array"
         },
         "title": "Groupings",
         "type": "object"
      },
      "portfolio_ids": {
         "items": {
            "type": "string"
         },
         "title": "Portfolio Ids",
         "type": "array"
      },
      "benchmark_ids": {
         "items": {
            "anyOf": [
               {
                  "type": "string"
               },
               {
                  "type": "null"
               }
            ]
         },
         "title": "Benchmark Ids",
         "type": "array"
      }
   },
   "$defs": {
      "PortfolioOrganizerSettings": {
         "additionalProperties": false,
         "description": "Specifies which portfolios to enable (from different sources).\n\nDifferent sources (e.g. uploaded portfolios) can provide the same portfolio\nidentifiers. These settings allow to specify which portfolios to enable from\nwhich sources.",
         "properties": {
            "dataset": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "The name of the underlying dataset to use for price data needed to forward fill portfolios, obtain corporate actions, etc.If none is given then the configured default dataset is used.",
               "examples": [
                  "Bayesline-US"
               ],
               "title": "Dataset"
            },
            "enabled_portfolios": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "additionalProperties": {
                        "type": "string"
                     },
                     "type": "object"
                  }
               ],
               "description": "The enabled portfolios from different sources. The key is the portfolio ID, and the value is the source (name of the underlying portfolio service). Pass a str to reference an entire portfolio source (e.g. all portfolios from an upload).",
               "title": "Enabled Portfolios"
            }
         },
         "required": [
            "enabled_portfolios"
         ],
         "title": "PortfolioOrganizerSettings",
         "type": "object"
      }
   },
   "additionalProperties": false,
   "required": [
      "portfolio_schema",
      "portfolio_ids",
      "benchmark_ids"
   ]
}

Config:
  • frozen: bool = True

  • extra: str = forbid

Fields:
  • benchmark_ids (list[str | None])

  • groupings (dict[str, list[str]])

  • portfolio_ids (list[str])

  • portfolio_schema (str | int | bayesline.api._src.equity.portfolio_settings.PortfolioOrganizerSettings)

Validators:
  • _fill_benchmark_ids » all fields

  • _validate_benchmark_ids » portfolio_ids

  • _validate_dimensions » all fields

  • _validate_groupings » groupings

  • _validate_ids_with_rest » all fields

  • _validate_portfolio_ids » portfolio_ids

  • _validate_portfolio_schema » portfolio_schema

field portfolio_schema: Annotated[str | int | PortfolioOrganizerSettings, Field(description="The portfolio organizer settings to use as an underlying schema of portfolios. The 'Default' schema is used by default."), SettingsTypeMetaData[str | int | PortfolioOrganizerSettings](references=PortfolioOrganizerSettings)] [Required]#

The portfolio organizer settings to use as an underlying schema of portfolios. The ‘Default’ schema is used by default.

Constraints:
  • references = <class ‘bayesline.api._src.equity.portfolio_settings.PortfolioOrganizerSettings’>

Validated by:
  • _fill_benchmark_ids

  • _validate_dimensions

  • _validate_ids_with_rest

  • _validate_portfolio_schema

field groupings: dict[str, list[str]] [Optional]#
Validated by:
  • _fill_benchmark_ids

  • _validate_dimensions

  • _validate_groupings

  • _validate_ids_with_rest

field portfolio_ids: list[str] [Required]#
Validated by:
  • _fill_benchmark_ids

  • _validate_benchmark_ids

  • _validate_dimensions

  • _validate_ids_with_rest

  • _validate_portfolio_ids

field benchmark_ids: list[str | None] [Required]#
Validated by:
  • _fill_benchmark_ids

  • _validate_dimensions

  • _validate_ids_with_rest

property menu_type: type[PortfolioHierarchySettingsMenu]#

Get the menu type for this settings object.

Returns#

type[SettingsMenuType]

The menu type for this settings object.

classmethod from_source(source: str, portfolio_ids: list[str], benchmark_ids: list[str | None] | None = None, groupings: dict[str, list[str]] | None = None, dataset: str | None = None) PortfolioHierarchySettings#

Create portfolio hierarchy settings from a source.

Parameters#

sourcestr

The name of an upload from the portfolio uploader.

portfolio_idslist[str]

The list of portfolio IDs.

benchmark_idslist[str | None] | None, default=None

The list of benchmark IDs, defaults to None for each portfolio.

groupingsdict[str, list[str]] | None, default=None

The groupings dictionary, defaults to empty dict.

datasetstr | None, default=None

The risk dataset to use for the security master and asset returns. If None, the default dataset is used.

Returns#

PortfolioHierarchySettings

The created portfolio hierarchy settings.

classmethod from_polars(df: DataFrame, portfolio_schema: str | int | PortfolioOrganizerSettings = 'Default', portfolio_source: str | None = None, dataset: str | None = None) PortfolioHierarchySettings#

Create a portfolio hierarchy from a dataframe.

Must contain a column portfolio_id and optionally benchmark_id. Every other column is interpreted as a grouping. 0 groupings are allowed. Index is ignored.

Parameters#

dfpl.DataFrame

The dataframe to create the hierarchy from.

portfolio_schemastr | int | PortfolioOrganizerSettings, default=”Default”

The underlying portfolio schema to use.

portfolio_sourcestr | None, default=None

The source to use for the portfolio schema. If not provided then the portfolio schema is used. If provided then it will override the portfolio schema.

datasetstr | None, default=None

The dataset to use for the portfolio schema. If not provided then the default dataset is used. Will be ignored if source is not provided.

Returns#

PortfolioHierarchySettings

The created portfolio hierarchy settings.

Raises#

ValueError

If the portfolio_id column is not found in the dataframe.

to_polars() DataFrame#

Convert the hierarchy to a polars dataframe.

The last two columns are the portfolio and benchmark IDs. Every column before that is a grouping. 0 groupings are possible.

Returns#

pl.DataFrame

The dataframe representation of the hierarchy, sorted by portfolio ID.

describe(menu: PortfolioHierarchySettingsMenu) str#

Describe the portfolio hierarchy settings.

Parameters#

menuPortfolioHierarchySettingsMenu

The menu to get context information from.

Returns#

str

The description of the portfolio hierarchy settings.