Asset sets matrix: private API

PortfolioOptimisers.taxonomy_columnFunction
taxonomy_column(
    sets::UniverseSets,
    key::AbstractString,
    need::AbstractString
) -> Any

Read the taxonomy column sets.dict[key], checking that the key exists.

The sibling of factor_universe for a group name key, and written for the same reason: one shared helper whose message names the key and says what to do about it, so every consumer of a caller-supplied taxonomy key fails the same way. A bare sets.dict[key] raises a KeyError carrying the key alone, which says nothing about which of the two producers asked for it, and offers no help with a typo.

need names the consumer. The suggestion comes from suggest_declared_key, the looser configuration shared by every declaration-key suggestion: the candidates here are sets.dict keys the caller authored, not asset names, so the info-leak-safe boundary does not apply.

Arguments

  • sets: A UniverseSets object specifying the asset universe and groupings.
  • key: The group name key to read.
  • need: Names the consumer in the error message.

Validation

  • haskey(sets.dict, key). Raises a KeyError naming key, naming need as the consumer that asked for it, and carrying a suggest_declared_key suggestion. The exception stays a KeyError, as factor_universe does, because a missing key is what it is — only the message improves.

Returns

  • col: The value of sets.dict[key], one group per asset.

Related

source
PortfolioOptimisers.panel_input_nameFunction
panel_input_name(sets::UniverseSets, key::AbstractString) -> String

Name the Panel Field a UniverseSets key becomes: the key with the asset prefix stripped.

Every Panel Field of an AssetPanel is asset-parallel by construction, so the xkey prefix that marks a key as asset-length says nothing there and comes off, with its separating underscore: "nx_sector" becomes "sector". A key that carries no prefix keeps its name.

Algorithm

  1. Return the key unchanged when it does not start with sets.xkey followed by an underscore.
  2. Otherwise return the key with that prefix and the underscore removed.

Arguments

  • sets: The universe sets, read for xkey.
  • key: The key to name.

Returns

  • name::String: The Panel Field name.

Related

source
PortfolioOptimisers.panel_input_kindFunction
panel_input_kind(vals::AbstractVector, key::AbstractString) -> Type

Choose the raw Panel Field input type a UniverseSets key's values ask for.

The element type is the whole rule: a string-valued key is a classification and a number-valued key is a quantity. A mixed element type is refused, because a taxonomy that carries both in one key describes two things.

Algorithm

  1. Return CategoricalPanelInput when every value is a string.
  2. Return NumericPanelInput when every value is a number.
  3. Otherwise raise, naming the key and the two forms that resolve it.

Arguments

  • vals: The key's values.
  • key: The key, named in the message.

Validation

  • Every value is a string, or every value is a number. Raises an ArgumentError.

Returns

  • The input type.

Related

source
PortfolioOptimisers.panel_input_buildFunction
panel_input_build(::Type{CategoricalPanelInput}, sets, key, vals, name, levels, alg)
panel_input_build(::Type{NumericPanelInput}, sets, key, vals, name, levels, alg)

Build the raw Panel Field input panel_input resolved to.

Algorithm

The method that Julia selects is the algorithm. Each builds its own input type from the key's values, named by panel_input_name unless name overrides it. levels reaches the categorical form alone; the numeric form has no levels to declare and refuses one rather than ignoring it.

Arguments

  • The first positional: the input type to build.
  • sets: The universe sets, read for xkey.
  • key: The key the values came from.
  • vals: The key's values.
  • name: Panel Field name, or nothing to derive it.
  • levels: Category levels, or nothing.
  • alg: Fill policy.

Validation

  • levels is nothing on the numeric form. Raises an ArgumentError.

Returns

  • One AbstractPanelFieldInput.

Related

source