Factor Family Basis: private API

Functions

PortfolioOptimisers.dropped_factor_indicesFunction
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_indicesFunction
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_indicesFunction
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 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_sliceFunction
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 whose ratios hold 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.3

Related

source
PortfolioOptimisers.weighted_family_exposuresFunction
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

  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, observations × assets × factors.
  • 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_memberFunction
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, 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.

Related

source
PortfolioOptimisers.assert_factor_axis_lengthFunction
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_obsFunction
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