Schur Complement Hierarchical Risk Parity: private API
PortfolioOptimisers.Sd_Var — Type
const Sd_Var = Union{StandardDeviation, Variance}Groups the two risk measures that a Schur complement bundle accepts.
The allocation reads the risk of each half from the augmented covariance block of that half, so it accepts only a measure that is a function of a covariance matrix alone.
Related
StandardDeviationVarianceSchurComplementParamsnaive_portfolio_risk: Computes the risk of a block under either measure.
PortfolioOptimisers.VecScP — Type
const VecScP = AbstractVector{<:SchurComplementParams}Groups the vectors of Schur complement bundles.
A vector of bundles runs one allocation per bundle and blends the portfolios. The alias is the vector half of ScP_VecScP.
Related
PortfolioOptimisers.ScP_VecScP — Type
const ScP_VecScP = Union{SchurComplementParams, VecScP}Groups one Schur complement bundle and a vector of bundles.
The params field of the estimator takes either form, so its bound is this alias.
Related
PortfolioOptimisers.naive_portfolio_risk — Method
naive_portfolio_risk(r::Sd_Var, sigma::MatNum) -> NumberCompute 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
SchurComplementHierarchicalRiskParitywhensigmais the augmented block of a half $C$.
Arguments
r: Risk measure, which selects the case of the definition.sigma: Covariance block, usually the result ofschur_augmentation.
Returns
risk::Number: The risk $\tilde{\rho}$ underr.
Related
PortfolioOptimisers.symmetric_step_up_matrix — Method
symmetric_step_up_matrix(n1::Integer, n2::Integer) -> AbstractMatrixBuild 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: Ann1byn2matrix. It isLinearAlgebra.I(n1)whenn1 == n2.
Related
PortfolioOptimisers.schur_augmentation — Method
schur_augmentation(A::MatNum, B::MatNum, C::MatNum, gamma::Number) -> MatNumAugment 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
- When
gammais zero, or whenAorChas one row, returnAunchanged. - Compute
A_aug, the matrix $\mathbf{A}$, with a linear solve againstC. - Build
m, thesymmetric_step_up_matrixof the sizes ofAandC. - Compute
r, the matrix $\mathbf{R}$, with a linear solve against the transpose ofC. - 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 ofAalong 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 asA.
Related
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
w: Weight vector returned byschur_complement_weights, ornothing.gamma: The value ofgammathe allocation ran with.
Validation
!isnothing(w). Otherwise it throws anArgumentErrorthat namesgammaand the three remedies.
Returns
nothing.
Related
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) -> TupleBisect 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
- When
iterisnothing, derive the budgetmax(1, ceil(Int, log2((hgamma - lgamma) / tol) * 2 + 1)). - Keep the first
lgammaandlriskas the start of the bracket. - Evaluate
objectiveat the midpointmgamma, giving the weightsmwand the variancerisk. - When
mwexists andriskis not abovelrisk, probe the slope. Evaluateobjectiveatmax(0, mgamma - tol), or reuse the variance at the start when the probe is the start. Whenriskis not above that variance either, the variance still falls at the midpoint, somgamma,riskandmwbecome the incumbentlgamma,lriskandlw. Otherwisemgammabecomeshgamma. - Stop when the incumbent is above the start,
mwexists, and the bracket is at mosttolwide. Otherwise go back to step 3, at mostitertimes. - When the bracket is still wider than
tol, report it throughstrict_diagnostic. Returnlwandlgamma.
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).wisnothingandriskis 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 atlgamma, which a midpoint must not exceed.lw: The weights atlgamma.tol: Width at which the bracket is narrow enough, and the step of the one-sided slope test.iter: Budget of bisections.nothingderives one from the bracket andtol.strict: Whether a bracket that stays wider thantolthrows instead of a warning.
Validation
- With
strict = true, a bracket that stays wider thantolafteriterbisections throws anArgumentError. Withstrict = falseit 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
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