Cross-Sectional Factor Axis
Types
PortfolioOptimisers.CrossSectionalFactorAxisResult — Type
struct CrossSectionalFactorAxisResult{__T_nf, __T_fam} <: AbstractResultThe 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 innf, in the same order.
Constructors
CrossSectionalFactorAxisResult(nf::VecStr, fam::VecStr) -> CrossSectionalFactorAxisResultCrossSectionalFactorAxisResult(; nf::VecStr, fam::VecStr) -> CrossSectionalFactorAxisResultKeywords 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 aDimensionMismatchotherwise.nfrepeats no name. Raises anArgumentErrorotherwise.
Examples
julia> ax = CrossSectionalFactorAxisResult(; nf = ["market", "value", "size"], fam = ["market", "style", "style"]);julia> ax.fam3-element Vector{String}: "market" "style" "style"Related
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
- Take the Pairs in the order the caller wrote them, which is the column order of the exposures.
- Expand each Pair through
exposure_axis_names, so a one-hot member contributes one name per level. - Build the
CrossSectionalFactorAxisResultof the names and the labels. Its constructor refuses a repeated factor name.
Arguments
factors: Pairs offactor name => Exposure Estimator.rd: Returns data that carries the Asset Panel, which declares the levels of each one-hot member.
Validation
factorsis not empty.- No factor name appears twice.
Returns
ax::CrossSectionalFactorAxisResult: The raw factor names in column order, inax.nf, and the Factor Family label of each name, inax.fam.
Related
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
- The rules of the Pairs method of
cross_sectional_factor_axis.
Returns
ax::CrossSectionalFactorAxisResult: The raw factor names in column order, inax.nf, and the Factor Family label of each name, inax.fam.
Related
PortfolioOptimisers.cross_sectional_factor_sets — Function
cross_sectional_factor_sets(factors::AbstractVector{<:Pair}, rd::ReturnsResult,
sets::Option{<:UniverseSets} = nothing) -> UniverseSetsDeclare the cross-sectional factor axis and its Factor Family groups on a UniverseSets.
Algorithm
- Read the axis with
cross_sectional_factor_axis. - Take the universe to widen. When
setsisnothing, build a new one overrd.nxwith the default key prefixes. - Copy the dictionary of that universe with
cross_sectional_sets_dict, and write the names under itscfkey, sofactor_axis_keyfinds them from aCrossSectionalFactorModel. - 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.
- Build the widened
UniverseSetswith the key prefixes of step 2, throughrebuild_struct. The keyword constructor runs every one of its guards again.
Arguments
factors: Pairs offactor 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 isnothing, the function builds a new one overrd.nxwith 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 aUniverseSets. - 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,cfkeyorucfkeyof the universe, or equals itsnikey, is refused.UniverseSetsreads 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 withnikey, 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
cross_sectional_factor_sets(pe::CrossSectionalFactorPrior, rd::ReturnsResult,
sets::Option{<:UniverseSets} = nothing) -> UniverseSetsDeclare 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 isnothing, a new one is built overrd.nxwith the default key prefixes.
Validation
- The rules of the Pairs method of
cross_sectional_factor_sets.
Returns
sets::UniverseSets: The declared universe, carrying the cross-sectional factor axis and one group per Factor Family.
Related