Cross-Sectional Exposure Diagnostics

Functions

PortfolioOptimisers.exposure_correlation — Function
exposure_correlation(B::Arr3Num, w::Option{<:MatNum} = nothing) -> Matrix{<:Real}
exposure_correlation(csfm::CrossSectionalFactorModel;
                     weighting::Option{<:AbstractOrthogonalityMetric} = BenchmarkWeightMetric()) -> FactorDiagnosticResult

Return the time-averaged correlation between every pair of factor exposures.

Two exposures that correlate across the assets carry the same reading of the cross-section, so the pair is redundant and the design of the fit is collinear. This answer is the cross-sectional counterpart of the variance inflation factor, which reads the same collinearity off the design of one observation.

The verb correlates each pair one observation at a time, over the assets at which both exposures are finite and the weight is finite and positive, and then averages the answers over the observations at which the pair has one. A pair one of whose exposures is constant across the assets has no correlation, and it reads 0 by convention. A pair that never shares three such assets reads NaN. The diagonal is 1.

The block method answers on the raw factor axis, because the exposure history is what the panel recorded and not the design of the fit. It reads the unlagged history.

Mathematical definition

\[\begin{align} \mathbf{C}_{kl} &= \frac{1}{|\mathcal{T}_{kl}|} \sum_{t \in \mathcal{T}_{kl}} \rho \left( \mathbf{B}_{t \cdot k}, \mathbf{B}_{t \cdot l}, \boldsymbol{u}_{t} \right)\,. \end{align}\]

Where:

  • $\mathbf{C}_{kl}$: Time-averaged correlation of the exposures to factors $k$ and $l$.
  • $\mathbf{B}_{t \cdot k}$: Exposure cross-section of factor $k$ at observation $t$.
  • $\boldsymbol{u}_{t}$: Cross-sectional weights of observation $t$.
  • $\rho$: The weighted correlation of two cross-sections, over the assets at which both values are finite and the weight is finite and positive.
  • $\mathcal{T}_{kl}$: The observations at which the pair shares at least three assets and neither of its two cross-sections is constant over them.

Algorithm

  1. Resolve the weight history with exposure_weights.
  2. For each observation and each pair, accumulate the weighted sums over the assets at which both exposures are finite and the weight is finite and positive.
  3. Mark the pair as degenerate when either weighted variance falls to the tolerance of its own weighted square sum, and as insufficient when it shares fewer than three assets.
  4. Average the pairs that are neither over the observations. A pair that is degenerate at every observation it covers reads 0, and one that is never sufficient reads NaN.
  5. Write 1 on the diagonal.

Arguments

  • B: Exposure history assets × factors × observations, unlagged.
  • w: Cross-sectional weight history observations × assets, or nothing for equal weights.
  • csfm: A cross-sectional factor model block.
  • weighting: A member of AbstractOrthogonalityMetric, or nothing for equal weights. It names the weight history that the verb reads off the block, and cs_diagnostic_weights resolves it over the whole observation axis.

Validation

  • !isempty(B).
  • size(w) == (size(B, 3), size(B, 1)), when w is present.
  • csfm.Ms is not nothing. Otherwise the verb raises an IsNothingError that names Ms.
  • The field that weighting names is not nothing. Otherwise the verb raises an IsNothingError that names it.

Returns

  • C::Matrix{<:Real}: factors × factors, symmetric, with a diagonal of 1, on the method over histories.
  • r::FactorDiagnosticResult: On the block method, the same matrix in X, with the names and the family labels of the raw factor axis, and dims = (1, 2), so a view selects the rows and the columns of a sub-block together. The block method returned the bare matrix in earlier releases, so a caller that indexed it now reads r.X.

Related

source
PortfolioOptimisers.exposure_stability — Function
exposure_stability(B::Arr3Num, w::Option{<:MatNum} = nothing;
                   step::Integer = 21) -> Matrix{<:Real}
exposure_stability(csfm::CrossSectionalFactorModel; step::Integer = 21,
                   weighting::Option{<:AbstractOrthogonalityMetric} = BenchmarkWeightMetric()) -> FactorDiagnosticResult

Return the stability of every factor exposure, one row per pair of observations.

The stability is the correlation of the cross-section of an exposure against its own cross-section step observations later. An exposure that ranks the assets the same way from one month to the next reads near 1, and one that re-orders them reads near 0. A risk factor needs a stable exposure, because a turnover of the exposure is a turnover of the portfolio that holds it.

The block method answers on the raw factor axis, and it reads the unlagged history.

Mathematical definition

\[\begin{align} \mathrm{S}_{tk} &= \rho \left( \mathbf{B}_{t \cdot k}, \mathbf{B}_{t + s, \cdot k}, \boldsymbol{u}_{t} \right)\,. \end{align}\]

Where:

  • $\mathrm{S}_{tk}$: Stability of the exposure to factor $k$ from observation $t$.
  • $\mathbf{B}_{t \cdot k}$: Exposure cross-section of factor $k$ at observation $t$.
  • $\boldsymbol{u}_{t}$: Cross-sectional weights of observation $t$, the earlier of the two.
  • $\rho$: The weighted correlation of two cross-sections, over the assets at which both values are finite and the weight is finite and positive.
  • $s$: Number of observations between the two cross-sections.

Arguments

  • B: Exposure history assets × factors × observations, unlagged.
  • w: Cross-sectional weight history observations × assets, or nothing for equal weights.
  • step: Number of observations between the two cross-sections.
  • csfm: A cross-sectional factor model block.
  • weighting: A member of AbstractOrthogonalityMetric, or nothing for equal weights. It names the weight history that the verb reads off the block, and cs_diagnostic_weights resolves it over the whole observation axis.

Validation

  • !isempty(B).
  • step >= 1 and size(B, 3) > step.
  • csfm.Ms is not nothing. Otherwise the verb raises an IsNothingError that names Ms.

Returns

  • S::Matrix{<:Real}: (observations - step) × factors, on the method over histories.
  • r::FactorDiagnosticResult: On the block method, the same matrix in X, with the names and the family labels of the raw factor axis. The block method returned the bare matrix in earlier releases, so a caller that indexed it now reads r.X.

Related

source
PortfolioOptimisers.exposure_dispersion — Function
exposure_dispersion(B::Arr3Num, w::Option{<:MatNum} = nothing) -> Matrix{<:Real}
exposure_dispersion(csfm::CrossSectionalFactorModel;
                    weighting::Option{<:AbstractOrthogonalityMetric} = BenchmarkWeightMetric()) -> FactorDiagnosticResult

Return the weighted cross-sectional standard deviation of every factor exposure, one row per observation.

The level of the answer follows the standardisation that built the exposures, so read the series and not the level. A collapse is a data feed that stopped, and a jump is one asset with an extreme exposure. A constant exposure reads exactly 0. An observation at which the factor carries no weight reads NaN.

The block method answers on the raw factor axis, and it reads the unlagged history.

Mathematical definition

\[\begin{align} \mathrm{D}_{tk} &= \sqrt{\sum_{i} \tilde{u}_{tik} \left( B_{tik} - \sum_{j} \tilde{u}_{tjk} B_{tjk} \right)^{2}}\,. \end{align}\]

Where:

  • $\mathrm{D}_{tk}$: Dispersion of the exposure to factor $k$ at observation $t$.
  • $B_{tik}$: Exposure of asset $i$ to factor $k$ at observation $t$.
  • $\tilde{u}_{tik}$: Weight of asset $i$, zero where the exposure is not finite or the weight is not finite and positive, and normalised over the assets to sum to one.

Arguments

  • B: Exposure history assets × factors × observations, unlagged.
  • w: Cross-sectional weight history observations × assets, or nothing for equal weights.
  • csfm: A cross-sectional factor model block.
  • weighting: A member of AbstractOrthogonalityMetric, or nothing for equal weights. It names the weight history that the verb reads off the block, and cs_diagnostic_weights resolves it over the whole observation axis.

Validation

  • !isempty(B).
  • csfm.Ms is not nothing. Otherwise the verb raises an IsNothingError that names Ms.

Returns

  • D::Matrix{<:Real}: observations × factors, on the method over histories.
  • r::FactorDiagnosticResult: On the block method, the same matrix in X, with the names and the family labels of the raw factor axis. The block method returned the bare matrix in earlier releases, so a caller that indexed it now reads r.X.

Related

source
PortfolioOptimisers.exposure_coverage — Function
exposure_coverage(B::Arr3Num, w::Option{<:MatNum} = nothing) -> Vector{<:Real}
exposure_coverage(csfm::CrossSectionalFactorModel;
                  weighting::Option{<:AbstractOrthogonalityMetric} = RegressionWeightMetric()) -> FactorDiagnosticResult

Return the coverage of every factor exposure, one entry per factor.

The coverage is the share of the universe at which the exposure is finite, averaged over the observations. The universe of an observation is the assets that carry a finite positive weight, and it is every asset when the verb reads no weight history. A factor whose coverage falls has lost its panel field on part of the universe, and the fit of that observation then rests on fewer assets than the caller believes.

The block method answers on the raw factor axis, and it reads the unlagged history. By default it reads the regression weights, so the universe is the estimation universe of the fit, the assets of positive regression weight, and the answer is the coverage column of factor_model_summary. A block that carries no regression weights was fitted on every asset, so its universe is every asset. weighting = BenchmarkWeightMetric() reads the benchmark universe instead.

Mathematical definition

\[\begin{align} \mathrm{c}_{k} &= \frac{1}{T} \sum_{t=1}^{T} \frac{\left| \left\{ i \in \mathcal{U}_{t} : B_{tik} \text{ is finite} \right\} \right|}{\left| \mathcal{U}_{t} \right|}\,. \end{align}\]

Where:

  • $\mathrm{c}_{k}$: Coverage of the exposure to factor $k$.
  • $B_{tik}$: Exposure of asset $i$ to factor $k$ at observation $t$.
  • $\mathcal{U}_{t}$: Universe of observation $t$, the assets of finite positive weight. An observation whose universe is empty adds zero to the sum.
  • $T$: Number of observations.

Arguments

  • B: Exposure history assets × factors × observations, unlagged.
  • w: Cross-sectional weight history observations × assets, or nothing for every asset.
  • csfm: A cross-sectional factor model block.
  • weighting: A member of AbstractOrthogonalityMetric, or nothing for equal weights. It names the weight history that sets the universe, and exposure_coverage_weights resolves it over the whole observation axis.

Validation

  • !isempty(B).
  • csfm.Ms is not nothing. Otherwise the verb raises an IsNothingError that names Ms.
  • The field that weighting names is not nothing, except under RegressionWeightMetric. Otherwise the verb raises an IsNothingError that names the field.

Returns

  • c::Vector{<:Real}: One entry per factor, between 0 and 1, on the method over histories. An observation whose universe is empty contributes 0.
  • r::FactorDiagnosticResult: On the block method, the same vector in X, with the names and the family labels of the raw factor axis. The block method returned the bare vector in earlier releases, so a caller that indexed it now reads r.X.

Related

source
PortfolioOptimisers.exposure_vif — Function
exposure_vif(G::Arr3Num) -> Matrix{<:Real}
exposure_vif(B::Arr3Num, w::Option{<:MatNum}) -> Matrix{<:Real}
exposure_vif(csfm::CrossSectionalFactorModel) -> FactorDiagnosticResult

Return the variance inflation factor of every factor, one row per observation.

The factor measures how much the collinearity of the cross-sectional design inflates the variance of a factor return. A value of one says that the factor is orthogonal to the others of that observation, and a large value says that the factor is nearly a combination of them, so its estimated return is unstable rather than wrong.

The factor is $1 / (1 - R_{k}^{2})$, where $R_{k}^{2}$ is the uncentred coefficient of determination of the weighted column $k$ on the other columns, so it is at least one. On an exactly collinear slice the answer keeps that meaning. A column that the slice identifies gets its finite factor from the pseudo-inverse. A column that the other columns reproduce has $R_{k}^{2} = 1$, and its factor is Inf. A column of zeros has no $R_{k}^{2}$, and its factor is NaN. exposure_condition_number shows such a slice.

Mathematical definition

\[\mathrm{VIF}_{t,k} = (\mathbf{G}_{t})_{kk} \, (\mathbf{G}_{t}^{-1})_{kk}\]

Where:

  • $\mathbf{G}_{t}$: Gram matrix of observation $t$, which cs_gram defines.
  • $(\mathbf{G}_{t}^{-1})_{kk}$: Diagonal of the inverse of $\mathbf{G}_{t}$, which cs_gram_inverse_diagonal defines. It is Inf for a column the slice does not identify, so the product is Inf, or NaN when $(\mathbf{G}_{t})_{kk}$ is zero.
  • $\mathrm{VIF}_{t,k}$: Variance inflation factor of factor $k$ at observation $t$.

Algorithm

  1. On the method over a Gram history, take the diagonal of the inverse of every slice with cs_gram_inverse_diagonal, and multiply it entry by entry by the diagonal of the slice itself.
  2. On the methods that read a design, take the weighted design of every observation with cs_design_slice, the diagonal of its inverse Gram matrix with cs_inverse_diagonal! at the rank of the fit, and multiply it by the squared norm of each column. A Gram matrix formed in floating point squares the condition number of the design, so these methods do not form one, and they keep a factor that the fit keeps on a design whose condition number exceeds about $10^{8}$.
  3. On the methods that read a design, answer NaN at an observation whose eligible asset count does not exceed the factor count, because such a design determines no variance.

Arguments

  • G: Gram history factors × factors × observations, which cs_gram returns.
  • B: Exposure history assets × factors × observations, already lagged.
  • w: Regression weight history observations × assets, or nothing for equal weights.
  • csfm: A cross-sectional factor model block. The answer is on the reduced factor axis when the block carries a family re-basis. At an observation with an Unseen Member the answer reads the design that the fit regressed on, which cs_regression_design changes. An Unseen Member has a zero column there, and so has the member that carries the condition when the family drops an Unseen Member, so their factor is NaN.

Validation

  • !isempty(B), and size(w) == (size(B, 3), size(B, 1)) when w is present.
  • On the block method, csfm.Ms and csfm.csr are not nothing.

Returns

  • vif::Matrix{<:Real}: observations × factors, on the methods over histories.
  • r::FactorDiagnosticResult: On the block method, the same matrix in X, with the names and the family labels of the design axis. The block method returned the bare matrix in earlier releases, so a caller that indexed it now reads r.X.

Examples

julia> B = reshape([1.0, 0.0, 0.0, 1.0], 2, 2, 1);julia> exposure_vif(cs_gram(B))1×2 Matrix{Float64}: 1.0  1.0

Related

source
PortfolioOptimisers.exposure_condition_number — Function
exposure_condition_number(G::Arr3Num) -> Vector{<:Real}
exposure_condition_number(B::Arr3Num, w::Option{<:MatNum}) -> Vector{<:Real}
exposure_condition_number(csfm::CrossSectionalFactorModel) -> Vector{<:Real}

Return the two-norm condition number of the Gram matrix of the cross-sectional design, one entry per observation.

The condition number reads the whole design at once, where a variance inflation factor reads one factor of it. It is the square of the condition number of the weighted design. A value of one says that the columns of the weighted design are orthogonal and of equal norm, and a large value says that one direction of the factor space carries almost no weighted exposure, so the fit of that observation is sensitive to a small change in the returns. The methods that read a design square the condition number of the weighted design itself rather than form the Gram matrix, which would lose every condition number above about $10^{8}$ to rounding. An exactly collinear design answers Inf or a value near the reciprocal of the square of the machine epsilon, and which of the two it answers is a property of the singular value decomposition rather than of the design. The smallest singular value of a rank-deficient matrix rounds either to zero or to a value near the machine epsilon. Both answers say that the design of that observation is singular. The method over a Gram history answers Inf or a value near the reciprocal of the machine epsilon there.

Mathematical definition

\[\kappa_{t} = \frac{\sigma_{\max}(\mathbf{G}_{t})}{\sigma_{\min}(\mathbf{G}_{t})} = \left(\frac{\sigma_{\max}(\mathbf{D}_{t})}{\sigma_{\min}(\mathbf{D}_{t})}\right)^{2}\]

Where:

  • $\mathbf{G}_{t}$: Gram matrix of observation $t$, which cs_gram defines.
  • $\mathbf{D}_{t}$: Weighted design of observation $t$, which cs_design_slice defines, so $\mathbf{G}_{t} = \mathbf{D}_{t}^{\intercal} \mathbf{D}_{t}$.
  • $\sigma_{\max}$, $\sigma_{\min}$: Largest and smallest singular values.

Arguments

  • G: Gram history factors × factors × observations, which cs_gram returns.
  • B: Exposure history assets × factors × observations, already lagged.
  • w: Regression weight history observations × assets, or nothing for equal weights.
  • csfm: A cross-sectional factor model block. The answer is on the reduced factor axis when the block carries a family re-basis. At an observation with an Unseen Member the answer reads the design that the fit regressed on, which cs_regression_design changes.

Validation

  • !isempty(B), and size(w) == (size(B, 3), size(B, 1)) when w is present.
  • On the block method, csfm.Ms and csfm.csr are not nothing.

Returns

  • kappa::Vector{<:Real}: One entry per observation. The methods that read a design answer NaN at an observation whose eligible asset count does not exceed the factor count.

Examples

julia> B = reshape([1.0, 0.0, 0.0, 1.0], 2, 2, 1);julia> exposure_condition_number(cs_gram(B))1-element Vector{Float64}: 1.0

Related

source