Cross-Sectional Factor Axis

Types

PortfolioOptimisers.CrossSectionalFactorAxisResult — Type
struct CrossSectionalFactorAxisResult{__T_nf, __T_fam} <: AbstractResult

The Cross-Sectional Factor Axis that a set of Factor Exposures produces, before any fit.

cross_sectional_factor_axis returns it. It holds the name of each factor and the Factor Family label of each name, in the column order of the exposures. The fitted CrossSectionalFactorModel stores the same two lists in its nf and fam.

Fields

  • nf: The raw name of each factor, in the column order of the exposures. A one-hot member gives one name for each level of its Panel Field.
  • fam: The Factor Family label of each name in nf, in the same order.

Constructors

CrossSectionalFactorAxisResult(nf::VecStr, fam::VecStr) -> CrossSectionalFactorAxisResultCrossSectionalFactorAxisResult(; nf::VecStr, fam::VecStr) -> CrossSectionalFactorAxisResult

Keywords correspond to the struct's fields. The keyword form calls the positional form, so the two forms run the same checks.

Validation

  • length(nf) == length(fam). Raises a DimensionMismatch otherwise.
  • nf repeats no name. Raises an ArgumentError otherwise.

Examples

julia> ax = CrossSectionalFactorAxisResult(; nf = ["market", "value", "size"],                                           fam = ["market", "style", "style"]);julia> ax.fam3-element Vector{String}: "market" "style" "style"

Related

source

Functions

PortfolioOptimisers.cross_sectional_factor_axis — Function
cross_sectional_factor_axis(
    factors::AbstractVector{<:Pair},
    rd::ReturnsResult
) -> CrossSectionalFactorAxisResult{Vector{String}, Vector{String}}

Return the cross-sectional factor axis that a set of Factor Exposures produces, before any fit.

The axis holds one name for each member that is not one-hot, and one name for each level of a one-hot member. A one-hot member reads the levels that its Panel Field declares, and not the levels that the observations hold, so the axis is the same in every fold. A caller who writes a FactorSpace mandate reads the axis before a prior exists, and the fitted CrossSectionalFactorModel stores the same answer in its nf and fam.

Algorithm

  1. Take the Pairs in the order the caller wrote them, which is the column order of the exposures.
  2. Expand each Pair through exposure_axis_names, so a one-hot member contributes one name per level.
  3. Build the CrossSectionalFactorAxisResult of the names and the labels. Its constructor refuses a repeated factor name.

Arguments

  • factors: Pairs of factor name => Exposure Estimator.
  • rd: Returns data that carries the Asset Panel, which declares the levels of each one-hot member.

Validation

  • factors is not empty.
  • No factor name appears twice.

Returns

  • ax::CrossSectionalFactorAxisResult: The raw factor names in column order, in ax.nf, and the Factor Family label of each name, in ax.fam.

Related

source
cross_sectional_factor_axis(
    pe::CrossSectionalFactorPrior,
    rd::ReturnsResult
) -> CrossSectionalFactorAxisResult{Vector{String}, Vector{String}}

Return the cross-sectional factor axis a CrossSectionalFactorPrior will produce, before any fit.

The method forwards pe.factors to the Pairs method of cross_sectional_factor_axis, with its observed members moved after the estimated ones by cross_sectional_axis_pairs, so a caller who holds the estimator reads the axis off it rather than copying the Pairs. The observed factors are the last names of the axis, as they are in the fitted block. The method reads the levels of a one-hot member off the Asset Panel that rd carries, so the field index of the panel sets the answer, and the answer is the same in every fold.

Arguments

  • pe: Cross-Sectional Factor Prior estimator.
  • rd: Returns data carrying the Asset Panel the one-hot levels are read from.

Validation

Returns

  • ax::CrossSectionalFactorAxisResult: The raw factor names in column order, in ax.nf, and the Factor Family label of each name, in ax.fam.

Related

source
PortfolioOptimisers.cross_sectional_factor_sets — Function
cross_sectional_factor_sets(factors::AbstractVector{<:Pair}, rd::ReturnsResult,
                            sets::Option{<:UniverseSets} = nothing) -> UniverseSets

Declare the cross-sectional factor axis and its Factor Family groups on a UniverseSets.

Algorithm

  1. Read the axis with cross_sectional_factor_axis.
  2. Take the universe to widen. When sets is nothing, build a new one over rd.nx with the default key prefixes.
  3. Copy the dictionary of that universe with cross_sectional_sets_dict, and write the names under its cfkey, so factor_axis_key finds them from a CrossSectionalFactorModel.
  4. Write one plain group per Factor Family label, which holds the names of the members of that family. A plain group carries no key prefix, so a constraint generator reads it as a group of names and not as a partition of an axis.
  5. Build the widened UniverseSets with the key prefixes of step 2, through rebuild_struct. The keyword constructor runs every one of its guards again.

Arguments

  • factors: Pairs of factor name => Exposure Estimator.
  • rd: Returns data that carries the Asset Panel, which declares the levels of each one-hot member. It also carries the asset names that a new sets declares.
  • sets: A declared universe to widen. When it is nothing, the function builds a new one over rd.nx with the default key prefixes.

Validation

  • The rules of cross_sectional_factor_axis.
  • A new sets needs rd.nx, because the asset axis is the one mandatory axis of a UniverseSets.
  • A Factor Family label that equals a factor name is refused, unless the family holds that one factor and nothing else. Otherwise one name would name two different lists.
  • A Factor Family label that starts with xkey, uxkey, tfkey, utfkey, cfkey or ucfkey of the universe, or equals its nikey, is refused. UniverseSets reads such a key as an axis, as a partition of an axis, or as the Non-Investable Axis, and not as a group of names. A label that only starts with nikey, such as "nikkei" against the default "ni", is a plain group.
  • A widened universe that already declares the cross-sectional axis, or a group under a Factor Family label, must declare the same list. cross_sectional_sets_write! refuses a different list and does not replace it.
  • The rules of UniverseSets.

Returns

  • sets::UniverseSets: The declared universe, which carries the cross-sectional factor axis and one group per Factor Family.

Related

source
cross_sectional_factor_sets(pe::CrossSectionalFactorPrior, rd::ReturnsResult,
                            sets::Option{<:UniverseSets} = nothing) -> UniverseSets

Declare the cross-sectional factor axis a CrossSectionalFactorPrior will produce, and its Factor Family groups, on a UniverseSets.

The method forwards pe.factors to the Pairs method of cross_sectional_factor_sets, with its observed members moved after the estimated ones by cross_sectional_axis_pairs, so the observed factors take their names and a group under their family labels. A caller who writes a FactorSpace mandate against the estimator, in a Pipeline step or in a fold of a cross-validation, declares the universe from the estimator it will fit, so nobody types the list of one-hot levels by hand.

Arguments

  • pe: Cross-Sectional Factor Prior estimator.
  • rd: Returns data carrying the Asset Panel the one-hot levels are read from, and the asset names a new sets declares.
  • sets: A declared universe to widen. When it is nothing, a new one is built over rd.nx with the default key prefixes.

Validation

Returns

  • sets::UniverseSets: The declared universe, carrying the cross-sectional factor axis and one group per Factor Family.

Related

source