Factor Family Basis
Types
PortfolioOptimisers.FactorFamilyBasis — Type
struct FactorFamilyBasis{__T_fnm, __T_fi, __T_di, __T_ratios, __T_K} <: AbstractFactorFamilyBasisCompact change of basis between the raw factor axis and the reduced axis a re-based Factor Family is fitted in.
A Factor Family whose one-hot exposures are collinear with a global factor carries one redundant column. The re-basis drops one member of the family and rewrites the family in an equivalent basis of full column rank, in which the benchmark-weighted factor returns of the family sum to zero. The change of basis differs from one observation to the next. The result stores, for each observation, the ratio of the benchmark-weighted exposure of each retained member to that of the dropped member, and it never stores the dense basis matrix.
Mathematical definition
For each constrained Factor Family $\mathcal{F}$ that drops the member $k$, and at each observation $t$,
\[\begin{align} c_{t}(j) &= \left(\mathbf{B}_{t}^{\intercal} \bar{\boldsymbol{w}}_{t}\right)_{j}\,, \\ r_{t}(j) &= \frac{c_{t}(j)}{c_{t}(k)}\,, \quad j \in \mathcal{F} \setminus \{k\}\,, \\ \sum_{j \in \mathcal{F}} c_{t}(j) \, f^{\mathrm{raw}}_{t,j} &= 0\,, \\ f^{\mathrm{raw}}_{t,k} &= -\sum_{j \in \mathcal{F} \setminus \{k\}} r_{t}(j) \, f^{\mathrm{raw}}_{t,j}\,. \end{align}\]
The third line is the zero-sum condition, and the fourth line is the same condition solved for the return of the dropped factor. So the retained factor returns and the ratios fix the whole family, and the reduced axis holds one factor fewer for each family. A ratio is finite only where $c_{t}(k) \neq 0$.
Where:
- $\mathcal{F}$: Raw factors of one family.
- $c_{t}(j)$: Benchmark-weighted exposure of factor $j$ at observation $t$, with a non-finite exposure read as zero.
- $\mathbf{B}_{t}$: Exposure slice of observation $t$, $N \times K$, the exposures the factor returns of $t$ are read against.
- $\bar{\boldsymbol{w}}_{t}$: Normalised benchmark weights of observation $t$, $N \times 1$, with entry $\bar{w}_{t,i}$ for asset $i$. They are the benchmark weights of the observation over their sum, with a non-finite weight read as zero.
- $r_{t}(j) = c_{t}(j) / c_{t}(k)$: Ratio of the benchmark-weighted exposure of member $j$ of a constrained Factor Family to that of the member $k$ the family drops, at observation $t$.
- $\boldsymbol{f}^{\mathrm{raw}}_{t}$, $\boldsymbol{f}^{\mathrm{red}}_{t}$: Raw and reduced factor returns of observation $t$, $K \times 1$ and $K_{r} \times 1$. The entry of factor $j$ is $f^{\mathrm{raw}}_{t,j}$.
- $K_{r}$: Reduced factor count, $K$ less one factor for each constrained Factor Family.
Fields
fnm: Label of each constrained Factor Family, one entry per family, in the order the caller requested them. That order fixes the column order ofratios.
fi: Member indices of each constrained Factor Family in the raw factor axis, one vector per family. Two families never share a member.
di: Position withinfi[j]of the member familyjdrops, one entry per family. The dropped member is the one the zero-sum condition reconstructs.
ratios: Ratios of the benchmark-weighted exposures,observations × C, withC = sum(length(fi[j]) - 1). The block of familyjholds one column per retained member, in the member order offi[j]with the dropped position removed.
K: Number of factors on the raw axis. The reduced axis holdsK - length(fnm)of them.
Constructors
FactorFamilyBasis(; fnm::VecStr, fi::AbstractVector{<:AbstractVector{<:Integer}}, di::AbstractVector{<:Integer}, ratios::MatNum, K::Integer)Keywords correspond to the struct's fields.
Validation
K > 0and!isempty(fnm).fnm,fianddihave the same length, andfnmdoes not repeat a label.- Every family holds at least two members, its members are unique, and every member lies in
1:K. - No factor belongs to two families.
di[j]indexesfi[j].ratioshas one column per retained member of a constrained family,sum(length(fi[j]) - 1)in all.ratiosis not empty, and every entry of it is finite.- The reduced axis is not empty. The rules above imply it: the families are disjoint, each holds at least two members of
1:K, soKis at least twice the number of families, and no separate check is needed.
Examples
julia> FactorFamilyBasis(; fnm = ["industry"], fi = [[1, 2]], di = [2], ratios = reshape([0.5, 0.4], 2, 1), K = 3)FactorFamilyBasis fnm ┼ Vector{String}: ["industry"] fi ┼ 1-element Vector{Vector{Int64}} di ┼ Vector{Int64}: [2] ratios ┼ 2×1 Matrix{Float64} K ┴ Int64: 3Related
AbstractFactorFamilyBasisfactor_family_basisCrossSectionalFactorModelhas_family_rebasisreduce_factor_names: the names of the reduced axis.reduce_exposuresandreduce_loadings: exposures onto the reduced axis.reduce_factor_returns,reduce_factor_muandreduce_factor_covariance: the reduced-axis moments.expand_factor_returnsandexpand_factor_covariance: the raw-axis moments.project_factor_coordinates: raw coordinates, such as a factor exposure of a portfolio, into the reduced basis.dropped_factor_weights: the reduced-axis weights of the dropped factors.
Functions
PortfolioOptimisers.factor_family_basis — Function
factor_family_basis(families::AbstractVector{<:Pair}, Ms::Arr3Num, bw::MatNum,
nf::VecStr, fam::VecStr) -> FactorFamilyBasisBuild the compact change of basis of the requested constrained Factor Families.
The element type of the ratios is the promoted type of Ms and bw. So a Rational history gives exact ratios, and a Float32 history gives Float32 ratios. A dropped factor whose benchmark-weighted exposure is small but not zero gives large finite ratios. The builder accepts them, and they are ill-conditioned. To avoid them, state a dropped factor with a large exposure, or let the automatic choice pick one.
Mathematical definition
For each requested family $\mathcal{F}$, and at each observation $t$,
\[\begin{align} \bar{w}_{t,i} &= \frac{b_{t,i}}{\sum_{l=1}^{N} b_{t,l}}\,, \\ c_{t}(j) &= \left(\mathbf{B}_{t}^{\intercal} \bar{\boldsymbol{w}}_{t}\right)_{j}\,, \\ k &= \underset{j \in \mathcal{F}}{\arg\max} \sum_{t=1}^{T} \lvert c_{t}(j) \rvert\,, \\ r_{t}(j) &= \frac{c_{t}(j)}{c_{t}(k)}\,, \quad j \in \mathcal{F} \setminus \{k\}\,. \end{align}\]
The third line holds when the caller states no dropped factor. Otherwise $k$ is the stated factor. The automatic choice makes $\lvert c_{t}(k) \rvert$ large on average, so the ratios stay moderate.
Where:
- $b_{t,i}$: Benchmark weight of asset $i$ at observation $t$, with a non-finite weight read as zero.
- $\bar{\boldsymbol{w}}_{t}$: Normalised benchmark weights of observation $t$, $N \times 1$, with entry $\bar{w}_{t,i}$ for asset $i$. They are the benchmark weights of the observation over their sum, with a non-finite weight read as zero.
- $c_{t}(j)$: Benchmark-weighted exposure of factor $j$ at observation $t$, with a non-finite exposure read as zero.
- $\mathbf{B}_{t}$: Exposure slice of observation $t$, $N \times K$, the exposures the factor returns of $t$ are read against.
- $\mathcal{F}$: Raw factors of one family.
- $r_{t}(j) = c_{t}(j) / c_{t}(k)$: Ratio of the benchmark-weighted exposure of member $j$ of a constrained Factor Family to that of the member $k$ the family drops, at observation $t$.
- $N$: Number of assets.
- $T$: Number of observations.
Algorithm
- Check the axes of
Ms,bw,nfandfam. - Compute
c, the benchmark-weighted exposure of every raw factor at every observation, withweighted_family_exposures. - For each requested family, in the order of
families, find its membersidxinfam. - Resolve the position
dof the dropped member withresolve_dropped_member. On a tie of the automatic choice, the first member in the order offamwins. - Refuse the family when the dropped member's column of
cis zero at an observation. - Divide the columns of
cof the retained members by the column of the dropped member, giving the family's block of the ratios. - Build the
FactorFamilyBasisfrom the resolved families and the concatenated blocks, which runs every check of the constructor again.
Arguments
families: Pairs offamily label => dropped factor name, in the order the families take columns ofratios. Anothingon the right asks for the automatic choice of the dropped factor.Ms::Arr3Num: Exposure history,assets × factors × observations.bw::MatNum: Benchmark weight history,observations × assets.nf::VecStr: Names of the raw factor axis, of lengthsize(Ms, 2).fam::VecStr: Family label of each raw factor, of lengthsize(Ms, 2).
Validation
familiesandMsare not empty, and no family label appears twice.nfandfamare as long as the factor axis ofMs, andnfdoes not repeat a name.bwmatchesMson the observation and asset axes, and every finite weight is non-negative.- Every observation carries a strictly positive benchmark weight sum.
- Every requested family label appears in
fam, and holds at least two factors. - A stated dropped factor name appears in
nf, and belongs to the family that names it. - The benchmark-weighted exposure of each dropped factor is not zero at any observation, otherwise an
IsNonFiniteError, because the ratios would not be finite. - The rules of
FactorFamilyBasis.
Returns
fcb::FactorFamilyBasis: The compact change of basis.
Examples
julia> Ms = reshape([1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0], 2, 2, 2);julia> factor_family_basis(["ind" => nothing], Ms, [0.5 0.5; 0.5 0.5], ["ind=a", "ind=b"], ["ind", "ind"])FactorFamilyBasis fnm ┼ Vector{String}: ["ind"] fi ┼ 1-element Vector{Vector{Int64}} di ┼ Vector{Int64}: [1] ratios ┼ 2×1 Matrix{Float64} K ┴ Int64: 2Related