Asset sets matrix: private API

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

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

It does for a group name key what factor_universe does for the factor universe key. asset_sets_matrix and panel_input read a Universe Sets key through it, so a missing key gives the same message in both. A bare sets.dict[key] raises a KeyError that holds the key alone. That error does not tell which function asked for the key, and it suggests no correction for a typo.

need names the caller. suggest_declared_key gives the suggestion, with the configuration that admits more matches than the global default. The global default is strict so that a message does not show a real asset name. The candidates here are sets.dict keys that the caller wrote, so that risk does not apply.

Arguments

  • sets: A UniverseSets that holds the asset universe and the groups.
  • key: The group name key to read.
  • need: The name of the caller, which the error message gives.

Validation

  • haskey(sets.dict, key). Raises a KeyError. The message names key and need, and ends with a suggest_declared_key suggestion. The exception stays a KeyError, as in factor_universe, because the key is missing. The message is the only change.

Returns

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

Related

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

Name the Panel Field that a UniverseSets key becomes, which is the key without its asset prefix.

Every Panel Field of an AssetPanel is indexed by asset. The xkey prefix marks a Universe Sets key as asset-length, so it gives no information on a Panel Field. The function removes the prefix and the underscore after it, so "nx_sector" becomes "sector". A key with 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 UniverseSets, which gives xkey.
  • key: The key to name.

Returns

  • name::String: The Panel Field name.

Related

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

Choose the raw Panel Field input type from the values of a UniverseSets key.

A key of strings is a classification, and a key of numbers is a quantity. The function refuses a key that holds both, because such a 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 an ArgumentError. The message names the key and the two Pair forms that force a type.

Arguments

  • vals: The values of the key.
  • key: The key, which the error message names.

Validation

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

Returns

  • The input type.

Related

source
PortfolioOptimisers.panel_input_build — Function
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 of the type that panel_input chose.

Algorithm

The method that Julia selects is the algorithm. Each method builds its own input type from the values of the key. panel_input_name names the input, unless name overrides it. Only the categorical method passes levels on. A numeric input has no levels, so the numeric method refuses levels and does not ignore it.

Arguments

  • The first positional argument: The input type to build.
  • sets: The UniverseSets, which gives xkey.
  • key: The key that holds the values.
  • vals: The values of the key.
  • name: The Panel Field name, or nothing to derive it.
  • levels: The category levels, or nothing.
  • alg: The fill policy.

Validation

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

Returns

  • One AbstractPanelFieldInput.

Related

source