Schur Complement Hierarchical Risk Parity: private API

PortfolioOptimisers.naive_portfolio_risk — Method
naive_portfolio_risk(r::Sd_Var, sigma::MatNum) -> Number

Compute the risk of the naive risk parity portfolio of a covariance block.

The weights are the inverse variances of the block for both measures, and the measure changes only what the function does with the quadratic form. So the weights match the naive weights of HierarchicalRiskParity under a Variance measure, and differ from its inverse volatility weights under a StandardDeviation measure. sigma is usually an augmented block, so its diagonal is not a plain asset variance.

Mathematical definition

\[\begin{align} \tilde{w}_i &= \frac{\Sigma_{ii}^{-1}}{\sum_{j} \Sigma_{jj}^{-1}}\,,\\ \tilde{\rho} &= \begin{cases} \tilde{\boldsymbol{w}}^\intercal \mathbf{\Sigma} \tilde{\boldsymbol{w}} & \textrm{for a variance}\,,\\ \sqrt{\tilde{\boldsymbol{w}}^\intercal \mathbf{\Sigma} \tilde{\boldsymbol{w}}} & \textrm{for a standard deviation}\,. \end{cases} \end{align}\]

Where:

  • $\mathbf{\Sigma}$: The block sigma, with entries $\Sigma_{ij}$.
  • $\tilde{\boldsymbol{w}}$: Naive risk parity weights of a block, the inverses of its diagonal entries divided by their sum.
  • $\tilde{\rho}$: The risk that the function returns, the $\tilde{\rho}(C)$ of SchurComplementHierarchicalRiskParity when sigma is the augmented block of a half $C$.

Arguments

  • r: Risk measure, which selects the case of the definition.
  • sigma: Covariance block, usually the result of schur_augmentation.

Returns

  • risk::Number: The risk $\tilde{\rho}$ under r.

Related

source
PortfolioOptimisers.symmetric_step_up_matrix — Method
symmetric_step_up_matrix(n1::Integer, n2::Integer) -> AbstractMatrix

Build the matrix that carries a Schur complement between two halves of nearly equal size.

The augmentation subtracts a term that the other half shapes, so the result must come back to the size of the half that is augmented. This matrix is that map.

Mathematical definition

\[\begin{align} \mathbf{M}_{n_1, n_2} &= \begin{cases} \mathbf{I}_{n_1} & n_1 = n_2\,,\\ \dfrac{1}{n_1} \sum_{k=1}^{n_1} \mathbf{E}_k & n_1 = n_2 + 1\,,\\ \dfrac{n_1}{n_2} \mathbf{M}_{n_2, n_1}^\intercal & n_1 = n_2 - 1\,,\end{cases}\\ \mathbf{E}_k &= \begin{pmatrix} \boldsymbol{e}_1 & \cdots & \boldsymbol{e}_{k-1} & \frac{1}{n_2} \mathbf{1} & \boldsymbol{e}_k & \cdots & \boldsymbol{e}_{n_2} \end{pmatrix}^\intercal\,. \end{align}\]

Where:

  • $\mathbf{M}_{n_1, n_2}$: Symmetric step-up matrix of $n_1$ rows and $n_2$ columns.
  • $n_1$, $n_2$: Sizes of the half that is augmented and of the other half.
  • $\mathbf{E}_k$: The identity matrix of size $n_2$ with a uniform row inserted at row $k$.
  • $\boldsymbol{e}_j$: The $j$-th unit vector of length $n_2$.
  • $\mathbf{1}$: The vector of $n_2$ ones.

$\mathbf{M}_{n_1, n_2}$ averages the $n_1$ positions that an extra uniform row can take. Every row of it sums to one in all three cases, so $\mathbf{M}_{n_1, n_2} \mathbf{1} = \mathbf{1}$.

Arguments

  • n1: Size of the half that is augmented, and the number of rows.
  • n2: Size of the other half, and the number of columns.

Validation

  • abs(n1 - n2) <= 1. A bisection makes halves that differ by at most one, so no other shape reaches this method from the recursion.

Returns

  • m::AbstractMatrix: An n1 by n2 matrix. It is LinearAlgebra.I(n1) when n1 == n2.

Related

source
PortfolioOptimisers.schur_augmentation — Method
schur_augmentation(A::MatNum, B::MatNum, C::MatNum, gamma::Number) -> MatNum

Augment the covariance block of one half with the information of the cross block.

The result is not always positive definite. schur_complement_weights repairs it or abandons the allocation, as SchurComplementParams.flag selects. When either half holds one asset, the function returns $\mathbf{\Sigma}_{11}$ unchanged and does not apply the formula below.

Mathematical definition

\[\begin{align} \mathbf{A} &= \mathbf{\Sigma}_{11} - \gamma \, \mathbf{\Sigma}_{12} \mathbf{\Sigma}_{22}^{-1} \mathbf{\Sigma}_{21}\,,\\ \mathbf{R} &= \mathbf{I} - \gamma \, \mathbf{\Sigma}_{12} \mathbf{\Sigma}_{22}^{-1} \mathbf{M}^\intercal\,,\\ \hat{\mathbf{\Sigma}}_{11} &= \frac{1}{2}\left(\mathbf{R}^{-1}\mathbf{A} + \left(\mathbf{R}^{-1}\mathbf{A}\right)^\intercal\right)\,. \end{align}\]

Where:

  • $\mathbf{\Sigma}_{11}$, $\mathbf{\Sigma}_{12}$, $\mathbf{\Sigma}_{21}$, $\mathbf{\Sigma}_{22}$: Blocks of the covariance matrix of a part, with the rows and the columns of $C_1$ first and those of $C_2$ second.
  • $\gamma$: Schur complement parameter, in $[0, 1]$. At $\gamma = 0$ every augmented block equals the plain block.
  • $\mathbf{A}$: Scaled Schur complement of $\mathbf{\Sigma}_{22}$. At $\gamma = 1$ it is the Schur complement of $\mathbf{\Sigma}_{22}$ in the covariance matrix of the part.
  • $\mathbf{M}$: Symmetric step-up matrix of size $|C_1| \times |C_2|$, see symmetric_step_up_matrix.
  • $\mathbf{I}$: Identity matrix.
  • $\mathbf{R}$: Step-up correction, the matrix that carries the augmentation back to the size of $C_1$.
  • $\hat{\mathbf{\Sigma}}_{11}$: Augmented block of $C_1$, made symmetric. $\hat{\mathbf{\Sigma}}_{22}$ follows when $C_1$ and $C_2$ exchange their roles.

Algorithm

  1. When gamma is zero, or when A or C has one row, return A unchanged.
  2. Compute A_aug, the matrix $\mathbf{A}$, with a linear solve against C.
  3. Build m, the symmetric_step_up_matrix of the sizes of A and C.
  4. Compute r, the matrix $\mathbf{R}$, with a linear solve against the transpose of C.
  5. Solve r \ A_aug, and return the mean of the solution and its transpose.

Arguments

  • A: Covariance block $\mathbf{\Sigma}_{11}$ of the half that is augmented.
  • B: Cross block $\mathbf{\Sigma}_{12}$ of the two halves, with the assets of A along the rows.
  • C: Covariance block $\mathbf{\Sigma}_{22}$ of the other half.
  • gamma: Schur complement parameter in [0, 1].

Returns

  • A_aug::MatNum: The augmented block $\hat{\mathbf{\Sigma}}_{11}$. It is symmetric, and of the same size as A.

Related

source
PortfolioOptimisers.assert_schur_weights — Method
assert_schur_weights(
    w::Union{Nothing, AbstractVector{<:Union{Number, AbstractJuMPScalar}}},
    gamma::Number
)

Assert that schur_complement_weights produced a weight vector.

A SchurComplementParams with flag = false does not repair an augmented block that is not positive definite. The recursion then abandons the allocation and returns nothing, which the monotonic search reads as a failure. A caller that keeps the weights gets the reason as an error instead.

Arguments

Validation

  • !isnothing(w). Otherwise it throws an ArgumentError that names gamma and the three remedies.

Returns

  • nothing.

Related

source
PortfolioOptimisers.schur_complement_binary_search — Method
schur_complement_binary_search(objective::Function, lgamma::Number, hgamma::Number,
                               lrisk::Number, lw::Option{<:VecNum},
                               tol::Number = 1e-4,
                               iter::Option{<:Integer} = nothing,
                               strict::Bool = false) -> Tuple

Bisect a bracket that holds the turning point of the portfolio variance in $\gamma$.

The scan of MonotonicSchurComplement gives a bracket in which the portfolio variance stops falling. This method halves the bracket until it is at most tol wide. The returned weights are always the weights of the returned value of $\gamma$, because a midpoint that the test rejects never replaces the weights of the incumbent.

Algorithm

  1. When iter is nothing, derive the budget max(1, ceil(Int, log2((hgamma - lgamma) / tol) * 2 + 1)).
  2. Keep the first lgamma and lrisk as the start of the bracket.
  3. Evaluate objective at the midpoint mgamma, giving the weights mw and the variance risk.
  4. When mw exists and risk is not above lrisk, probe the slope. Evaluate objective at max(0, mgamma - tol), or reuse the variance at the start when the probe is the start. When risk is not above that variance either, the variance still falls at the midpoint, so mgamma, risk and mw become the incumbent lgamma, lrisk and lw. Otherwise mgamma becomes hgamma.
  5. Stop when the incumbent is above the start, mw exists, and the bracket is at most tol wide. Otherwise go back to step 3, at most iter times.
  6. When the bracket is still wider than tol, report it through strict_diagnostic. Return lw and lgamma.

Step 5 does not stop before a midpoint passes, so a narrow bracket still halves towards its start. A decrease of the variance just above the start is still a decrease, and a turning point below tol is found above the start. Step 5 also does not stop at a midpoint that fails, so the bisection moves to the largest value at which the allocation exists. When no midpoint passes the test of step 4, the answer is the first lgamma. The scan measured that the variance falls up to that value.

Arguments

  • objective: Takes a value of $\gamma$ and returns (w, risk). w is nothing and risk is the largest value of its type when the allocation fails.
  • lgamma: Lower end of the bracket, and the incumbent.
  • hgamma: Upper end of the bracket.
  • lrisk: The variance at lgamma, which a midpoint must not exceed.
  • lw: The weights at lgamma.
  • tol: Width at which the bracket is narrow enough, and the step of the one-sided slope test.
  • iter: Budget of bisections. nothing derives one from the bracket and tol.
  • strict: Whether a bracket that stays wider than tol throws instead of a warning.

Validation

  • With strict = true, a bracket that stays wider than tol after iter bisections throws an ArgumentError. With strict = false it logs a warning. The derived budget always narrows the bracket, because each bisection halves it.

Returns

  • (w, gamma)::Tuple: The lower end of the last bracket, and the weights at it.

Related

source
PortfolioOptimisers.schur_complement_hrp_td_defaults — Function
schur_complement_hrp_td_defaults(

) -> @NamedTuple{params::SchurComplementParams{Variance{RiskMeasureSettings{Float64, Nothing, Bool}, Nothing, Nothing, Nothing, SquaredSOCRiskExpr, EigenFallbackSquareRoot, SquareRootRatio, Nothing}, Float64, Posdef{UnionAll, @NamedTuple{}}, MonotonicSchurComplement{Int64, Float64, Nothing, Bool}, Bool}}

Return the static defaults of the SchurComplementHierarchicalRiskParity fields that may hold a TimeDependent.

The substitution check of the constructor, assert_time_dependent_substitution, and time_dependent_field_defaults both read it, so the code declares the value of a field outside a fold once. The tuple leaves out a field whose static default is nothing.

Related

source