Factor Family Basis: private API
Functions
PortfolioOptimisers.dropped_factor_indices — Function
dropped_factor_indices(
fcb::FactorFamilyBasis
) -> Vector{Int64}
Return the raw-axis index of the factor each constrained family drops.
Arguments
fcb: A Factor Family Basis.
Returns
d::Vector{Int}: One raw-axis index per constrained family, in family order.
Examples
julia> fcb = FactorFamilyBasis(; fnm = ["industry"], fi = [[1, 3]], di = [2], ratios = reshape([0.5], 1, 1), K = 4);julia> PortfolioOptimisers.dropped_factor_indices(fcb)1-element Vector{Int64}: 3Related
PortfolioOptimisers.retained_factor_indices — Function
retained_factor_indices(
fcb::FactorFamilyBasis
) -> Vector{Int64}
Return the raw-axis indices the reduced axis keeps, in raw order.
The reduced axis is the raw axis with the dropped factor of every constrained family removed, so every other factor keeps its relative position.
Arguments
fcb: A Factor Family Basis.
Returns
r::Vector{Int}: The retained raw-axis indices, in increasing order.
Examples
julia> fcb = FactorFamilyBasis(; fnm = ["industry"], fi = [[1, 3]], di = [2], ratios = reshape([0.5], 1, 1), K = 4);julia> PortfolioOptimisers.retained_factor_indices(fcb)3-element Vector{Int64}: 1 2 4Related
PortfolioOptimisers.reduced_factor_count — Function
reduced_factor_count(fcb::FactorFamilyBasis) -> Int64
Return the number of factors on the reduced axis.
Arguments
fcb: A Factor Family Basis.
Returns
K::Int:fcb.Kless one factor per constrained family.
Examples
julia> fcb = FactorFamilyBasis(; fnm = ["industry"], fi = [[1, 3]], di = [2], ratios = reshape([0.5], 1, 1), K = 4);julia> PortfolioOptimisers.reduced_factor_count(fcb)3Related
PortfolioOptimisers.raw_to_reduced_index — Function
raw_to_reduced_index(
fcb::FactorFamilyBasis
) -> Vector{Int64}
Return the map from a raw-axis index to its reduced-axis index.
A dropped factor has no reduced-axis index, and the map holds 0 for it.
Arguments
fcb: A Factor Family Basis.
Returns
m::Vector{Int}: One entry per raw factor,0where the factor is dropped.
Related
PortfolioOptimisers.family_retained_indices — Function
family_retained_indices(
fcb::FactorFamilyBasis,
j::Integer
) -> Tuple{Vector{Int64}, Vector{Int64}, Vector{Int64}}
Return the raw-axis indices, the reduced-axis indices and the ratios columns of one constrained family.
The three vectors are aligned. Entry p of each names the same retained member of family j, in the raw axis, in the reduced axis and in ratios.
Arguments
fcb: A Factor Family Basis.j::Integer: Position of the family infcb.fnm.
Returns
raw::Vector{Int}: Raw-axis indices of the retained members.red::Vector{Int}: Reduced-axis indices of the same members.col::Vector{Int}: Columns offcb.ratiosthat hold their ratios.
Related
PortfolioOptimisers.factor_basis_slice — Function
factor_basis_slice(fcb::Nothing, i) -> nothing
factor_basis_slice(fcb::FactorFamilyBasis, i) -> FactorFamilyBasisReturn the basis restricted to a selection of observations.
The ratios keep the rows that i selects, and every other field is copied. So a caller reads the basis on a window of observations without building it again. A fit that constrains no Factor Family has no basis, and the method on Nothing gives no basis for every selection.
Arguments
fcb: A Factor Family Basis, ornothing.i: Indices of the observations to select.
Returns
fcb::Option{<:FactorFamilyBasis}: A new basis whoseratioshold only the selected observations, ornothing.
Examples
julia> fcb = FactorFamilyBasis(; fnm = ["industry"], fi = [[1, 2]], di = [2], ratios = reshape([0.5, 0.4, 0.3], 3, 1), K = 3);julia> PortfolioOptimisers.factor_basis_slice(fcb, 2:3).ratios2×1 Matrix{Float64}: 0.4 0.3Related
PortfolioOptimisers.append_passthrough_factors — Function
append_passthrough_factors(fcb::Nothing, n::Integer) -> nothing
append_passthrough_factors(fcb::FactorFamilyBasis, n::Integer) -> FactorFamilyBasisExtend a Factor Family Basis with n factors that it passes through unchanged.
The new factors take the last n positions of the raw axis, and they belong to no constrained family. So the basis keeps them on the reduced axis, after every retained factor, and it never re-bases them: their row of the change of basis is an identity row. The families, the dropped members and the ratios do not change. The observed factors of a CrossSectionalFactorPrior, such as its Currency Factors, join the basis this way, because their returns are observed and the zero-sum condition of a family does not reach them.
A prior that constrains no Factor Family has no basis, and the method over Nothing takes that case. Its raw axis is its reduced axis, so a pass-through factor needs no basis there.
Algorithm
- Refuse a negative
n. fcbisnothing: returnnothing.nis zero: returnfcbitself.- Otherwise build the basis again with
K = fcb.K + n, which runs every check of the constructor.
Arguments
fcb: A Factor Family Basis, ornothing.n: Number of pass-through factors to append.
Validation
n >= 0. Raises aDomainError.
Returns
fcb::Option{<:FactorFamilyBasis}: The extended basis, ornothing.
Examples
julia> fcb = FactorFamilyBasis(; fnm = ["industry"], fi = [[2, 3]], di = [2], ratios = reshape([0.5], 1, 1), K = 3);julia> fcb2 = PortfolioOptimisers.append_passthrough_factors(fcb, 2);julia> fcb2.K, PortfolioOptimisers.retained_factor_indices(fcb2)(5, [1, 2, 4, 5])Related
PortfolioOptimisers.dropped_factor_names — Function
dropped_factor_names(
fcb::FactorFamilyBasis,
nf::AbstractVector{<:AbstractString}
) -> Vector{String}
Return the name of the factor each constrained family drops.
Arguments
fcb: A Factor Family Basis.nf::VecStr: Names of the raw factor axis, of lengthfcb.K.
Validation
length(nf) == fcb.K.
Returns
nm::Vector{String}: One dropped factor name per constrained family, in family order.
Related
PortfolioOptimisers.weighted_family_exposures — Function
weighted_family_exposures(
Ms::AbstractArray{<:Union{Number, AbstractJuMPScalar}, 3},
bw::AbstractMatrix{<:Union{Number, AbstractJuMPScalar}},
Tf::Type{<:Real}
) -> Any
Return the benchmark-weighted exposure of every raw factor at every observation.
Algorithm
- Read a non-finite benchmark weight as zero, and refuse a finite negative one.
- Normalise each observation's weights to sum to one, and refuse an observation whose sum is not positive.
- Read a non-finite exposure as zero, and take the weighted sum across the assets.
Arguments
Ms::Arr3Num: Exposure history,assets × factors × observations.bw::MatNum: Benchmark weight history,observations × assets.Tf::Type{<:Real}: Element type of the answer.
Validation
- Every finite entry of
bwis non-negative. - Every observation's benchmark weights sum to a strictly positive number, once the non-finite ones are read as zero.
Returns
c::Matrix{<:Real}: The benchmark-weighted exposures,observations × factors.
Related
PortfolioOptimisers.resolve_dropped_member — Function
resolve_dropped_member(
drop::AbstractString,
nm::AbstractString,
idx::AbstractVector{<:Integer},
nf::AbstractVector{<:AbstractString},
_::AbstractMatrix{<:Union{Number, AbstractJuMPScalar}}
) -> Int64
Return the position within a family of the member the re-basis drops.
Arguments
drop: Name of the member to drop, ornothingfor the automatic choice.nm::AbstractString: Label of the family, used in the messages.idx::AbstractVector{<:Integer}: Raw-axis indices of the family's members.nf::VecStr: Names of the raw factor axis.c::MatNum: Benchmark-weighted exposures,observations × factors.
Validation
- A stated
dropappears innf, and belongs to the family that names it.
Returns
d::Int: Position withinidxof the dropped member. The automatic choice takes the member with the largest sum of absolute benchmark-weighted exposures over the observations, and the first such member on a tie.
Related
PortfolioOptimisers.assert_factor_axis_length — Function
assert_factor_axis_length(
got::Integer,
want::Integer,
sym::Union{AbstractString, Symbol}
)
Refuse an argument whose factor axis is the wrong length.
Arguments
got::Integer: Length the argument carries.want::Integer: Length the basis needs.sym::Sym_Str: Name of the argument, used in the message.
Validation
got == want, otherwise aDimensionMismatch.
Returns
nothing.
Related
PortfolioOptimisers.assert_factor_basis_obs — Function
assert_factor_basis_obs(
got::Integer,
fcb::FactorFamilyBasis,
sym::Union{AbstractString, Symbol}
)
Refuse a time-varying argument whose observation axis does not match the basis.
Arguments
got::Integer: Number of observations the argument carries.fcb: A Factor Family Basis.sym::Sym_Str: Name of the argument, used in the message.
Validation
got == size(fcb.ratios, 1), otherwise aDimensionMismatchthat namesfactor_basis_slice.
Returns
nothing.
Related