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}: 3

Related

source
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 4

Related

source
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 in fcb.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 of fcb.ratios that hold their ratios.

Related

source
PortfolioOptimisers.factor_basis_slice — Function
factor_basis_slice(fcb::Nothing, i) -> nothing
factor_basis_slice(fcb::FactorFamilyBasis, i) -> FactorFamilyBasis

Return 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, or nothing.
  • i: Indices of the observations to select.

Returns

  • fcb::Option{<:FactorFamilyBasis}: A new basis whose ratios hold only the selected observations, or nothing.

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.3

Related

source
PortfolioOptimisers.append_passthrough_factors — Function
append_passthrough_factors(fcb::Nothing, n::Integer) -> nothing
append_passthrough_factors(fcb::FactorFamilyBasis, n::Integer) -> FactorFamilyBasis

Extend 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

  1. Refuse a negative n.
  2. fcb is nothing: return nothing.
  3. n is zero: return fcb itself.
  4. Otherwise build the basis again with K = fcb.K + n, which runs every check of the constructor.

Arguments

  • fcb: A Factor Family Basis, or nothing.
  • n: Number of pass-through factors to append.

Validation

  • n >= 0. Raises a DomainError.

Returns

  • fcb::Option{<:FactorFamilyBasis}: The extended basis, or nothing.

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

source
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

  1. Read a non-finite benchmark weight as zero, and refuse a finite negative one.
  2. Normalise each observation's weights to sum to one, and refuse an observation whose sum is not positive.
  3. 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 bw is 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

source
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, or nothing for 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 drop appears in nf, and belongs to the family that names it.

Returns

  • d::Int: Position within idx of 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

source
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 a DimensionMismatch.

Returns

  • nothing.

Related

source
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

Returns

  • nothing.

Related

source