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 answers 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 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::FactorFamilyBasis,
i
) -> FactorFamilyBasis{var"#s185", var"#s1851", var"#s1852", <:AbstractMatrix{var"#s137"}, <:Integer} where {var"#s137"<:AbstractString, var"#s185"<:AbstractVector{var"#s137"}, var"#s1771"<:(AbstractVector{<:Integer}), var"#s1851"<:AbstractVector{var"#s1771"}, var"#s1769"<:Integer, var"#s1852"<:AbstractVector{var"#s1769"}, var"#s137"<:(Union{var"#s136", var"#s53"} where {var"#s136"<:Number, var"#s53"<:AbstractJuMPScalar})}
Return the basis restricted to a selection of observations.
Attribution reads the basis on the observations of a window, and it drops the lag by slicing the observation axis rather than by rebuilding the basis.
Arguments
fcb: A Factor Family Basis.i: Indices of the observations to select.
Returns
fcb::FactorFamilyBasis: A new basis whoseratioshold only the selected observations.
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.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{var"#s136", var"#s53"} where {var"#s136"<:Number, var"#s53"<:AbstractJuMPScalar}, 3},
bw::AbstractMatrix{<:Union{var"#s136", var"#s53"} where {var"#s136"<:Number, var"#s53"<: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,observations × assets × factors.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{var"#s136", var"#s53"} where {var"#s136"<:Number, var"#s53"<: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.
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