Hierarchical Equal Risk Contribution: private API
PortfolioOptimisers.herc_td_defaults — Function
herc_td_defaults(
) -> @NamedTuple{ri::Variance{RiskMeasureSettings{Float64, Nothing, Bool}, Nothing, Nothing, Nothing, SquaredSOCRiskExpr, EigenFallbackSquareRoot, SquareRootRatio, Nothing}, ro::Variance{RiskMeasureSettings{Float64, Nothing, Bool}, Nothing, Nothing, Nothing, SquaredSOCRiskExpr, EigenFallbackSquareRoot, SquareRootRatio, Nothing}, scai::Nothing, scao::Nothing}
Return the static defaults of the HierarchicalEqualRiskContribution fields that may hold a TimeDependent.
The constructor's substitution check and time_dependent_field_defaults both read it, so the file states the fold-less value of each field once. A field whose static default is nothing has no entry.
Related
PortfolioOptimisers.herc_unitary_risks — Function
herc_unitary_risks(r::OptimisationRiskMeasure, X::MatNum, fees::Option{<:Fees}) -> VecNum
herc_unitary_risks(rs::VecOptRM, X::MatNum, fees::Option{<:Fees}) -> VecVecNumReturn the risk of each asset held alone, once per measure.
The unitary risks do not depend on the cluster, so herc_risk computes them once for the whole universe, and every cluster reads its own entries.
Arguments
r,rs: A risk measure, or a vector of them, already resolved byfactory.X: Asset return matrix, observations by assets.fees: Fees, ornothing.
Returns
rku::VecNum: For one measure, the unitary risks fromunitary_expected_risks.rkus::VecVecNum: For a vector of measures, one vector of unitary risks per measure, in the order ofrs.
Related
PortfolioOptimisers.herc_intra_cluster_weights — Function
herc_intra_cluster_weights(sca::Option{<:Scalariser}, r::OptimisationRiskMeasure, rku::VecNum,
cl::VecInt) -> VecNum
herc_intra_cluster_weights(sca::Option{<:Scalariser}, rs::VecOptRM, rkus::VecVecNum,
cl::VecInt) -> VecNumReturn the shares that divide the weight of cluster cl between its assets.
One measure gives the naive risk parity weights inside the cluster, and ignores sca. A vector of measures gives the naive risk parity weights of each measure, and the scalariser combines them into one vector that sums to one.
Mathematical definition
\[\begin{align} v^{(k)}_i &= \frac{\rho_k(\{i\})^{-1}}{\sum_{l \in C} \rho_k(\{l\})^{-1}} \quad \forall\, i \in C\,,\\ u_i &= \begin{cases} \sum_{k} s_k \, v^{(k)}_i & \text{sum}\,,\\ v^{(k^\star)}_i,\; k^\star = \underset{k}{\arg\max} \sum_{l \in C} s_k \, \rho_k(\{l\}) & \text{max}\,,\\ v^{(k^\star)}_i,\; k^\star = \underset{k}{\arg\min} \sum_{l \in C} s_k \, \rho_k(\{l\}) & \text{min}\,,\\ \frac{1}{\gamma} \log \sum_{k} \exp\left(\gamma \, s_k \, v^{(k)}_i\right) & \text{log-sum-exp}\,, \end{cases}\\ v_i &= \frac{u_i}{\sum_{l \in C} u_l} \quad \forall\, i \in C\,. \end{align}\]
Where:
- $C$: The cluster
cl. - $\rho_k$: Risk measure $k$. One measure is the case of one $k$ with $s_k = 1$.
- $\rho_k(\{i\})$: Risk of asset $i$ held alone under $\rho_k$.
- $v^{(k)}_i$: Naive risk parity weight of asset $i$ inside $C$ under $\rho_k$.
- $s_k$:
scaleof the $k$-th risk measure of a vector, its weight in the combination. - $\gamma$: Smoothing parameter
gammaof aLogSumExpScalariser, positive. - $u_i$: The combined weight of asset $i$ before the normalisation.
- $v_i$: Share of asset $i$ in the weight of $C$.
The four cases are SumScalariser, MaxScalariser, MinScalariser and LogSumExpScalariser. nothing takes the sum. Under a sum, $\boldsymbol{v}$ is the average of the $\boldsymbol{v}^{(k)}$ weighted by $s_k$. A maximum or a minimum selects one measure by its total scaled unitary risk over $C$, and $\boldsymbol{v}$ is that measure's $\boldsymbol{v}^{(k)}$. The shares sum to one under every scalariser, so the cluster keeps the weight that the split factors give it.
Arguments
sca: Scalarisation strategy.r,rs: A risk measure, or a vector of them, already resolved byfactory.rku,rkus: The unitary risks ofr, or of each measure ofrs, fromherc_unitary_risks.cl: Asset indices of the cluster.
Returns
v::VecNum: The shares, of lengthlength(cl), in the order ofcl.
Related
PortfolioOptimisers.herc_cluster_risk — Function
herc_cluster_risk(sca::Option{<:Scalariser}, r::OptimisationRiskMeasure, rku::VecNum,
cl::VecInt, X::MatNum, fees::Option{<:Fees}) -> Number
herc_cluster_risk(sca::Option{<:Scalariser}, rs::VecOptRM, rkus::VecVecNum, cl::VecInt,
X::MatNum, fees::Option{<:Fees}) -> NumberReturn the risk of the naive risk parity sub-portfolio of cluster cl, the risk from which HERC forms its split factors.
One measure ignores sca. A vector of measures builds one sub-portfolio per measure, because the weights follow that measure's own unitary risks, and the scalariser combines their scaled risks into one number.
Mathematical definition
\[\begin{align} \tilde{w}^{(k)}_i(C) &= \frac{\rho_k(\{i\})^{-1}}{\sum_{l \in C} \rho_k(\{l\})^{-1}} \quad \forall\, i \in C\,,\\ p_k &= s_k \, \rho_k\left(\tilde{\boldsymbol{w}}^{(k)}(C)\right)\,,\\ \tilde{\rho}(C) &= \begin{cases} \sum_{k} p_k & \text{sum}\,,\\ \max_{k} p_k & \text{max}\,,\\ \min_{k} p_k & \text{min}\,,\\ \frac{1}{\gamma} \log \sum_{k} \exp\left(\gamma \, p_k\right) & \text{log-sum-exp}\,. \end{cases} \end{align}\]
Where:
- $C$: The cluster
cl. - $\rho_k$: Risk measure $k$. One measure is the case of one $k$, and its risk is not scaled, so $s_k = 1$.
- $\rho_k(\{i\})$: Risk of asset $i$ held alone under $\rho_k$.
- $\tilde{\boldsymbol{w}}^{(k)}(C)$: Naive risk parity weights of $\rho_k$ inside $C$, zero outside it.
- $s_k$:
scaleof the $k$-th risk measure of a vector, its weight in the combination. - $p_k$: The scaled risk of the sub-portfolio of $\rho_k$.
- $\gamma$: Smoothing parameter
gammaof aLogSumExpScalariser, positive. - $\tilde{\rho}(C)$: The combined risk of the cluster.
The risk of one measure carries no scale. Every cluster would carry the same scale, and a split factor is a ratio of cluster risks, so the scale would cancel.
Arguments
sca: Scalarisation strategy.r,rs: A risk measure, or a vector of them, already resolved byfactory.rku,rkus: The unitary risks ofr, or of each measure ofrs, fromherc_unitary_risks.cl: Asset indices of the cluster.X: Asset return matrix, observations by assets.fees: Fees, ornothing.
Returns
risk::Number: The combined risk of the cluster.
Related
PortfolioOptimisers.herc_risk — Function
herc_risk(hec::HierarchicalEqualRiskContribution, pr::AbstractPriorResult,
cls::VecVecInt, fees::Option{<:Fees}) -> TupleCompute the shares inside each cluster and the risk of each cluster that HERC allocates with.
Algorithm
- Resolve the inner measure
riagainstprandhec.opt.slv, withfactory. - Compute its unitary risks
riku, withherc_unitary_risks. - When
hec.rois the same object ashec.ri, takero = riandroku = riku. Otherwise resolveroand computerokuthe same way. - For each cluster
cl, under the executorhec.ex, write the shares ofherc_intra_cluster_weightsintow[cl], and the risk ofherc_cluster_riskinto the cluster's entry ofrkcl.
Arguments
hec: The optimiser. It gives the measures, the scalarisersscaiandscao, and the executorex.pr: Prior result. ItsXis the return matrix, and its moments resolve the measures.cls: Asset indices of each cluster, one entry per cluster.fees: Resolved fees, ornothing. The caller resolves them on its own universe and strips both liquidation charges,lqandflq, first, because a cluster-level risk prices no forced exit. The exiting asset is in no cluster, because its column isNaN.
Returns
(w, rkcl, ri, ro)::Tuple: The shares over the whole universe, the risk of each cluster, and the two resolved measures. The shares of each cluster sum to one, so the split factors still have to scale them.
Related
PortfolioOptimisers.bind_data_benchmark — Method
bind_data_benchmark(hec::HierarchicalEqualRiskContribution, rd::ReturnsResult)Bind every DataBenchmarkTracking of the inner measures ri and the outer measures ro to the benchmark of the rows that the optimiser fits on.
The optimiser calls it after investable_reduction, so the benchmark has the rows and the investable columns of the prior. The constructor already refused a data benchmark beside a prior that states x_src = ExcessSource(), see assert_data_benchmark_prior.
Algorithm
- Bind the inner measures
hec.ritordwithbind_data_benchmark, givingri. - Bind the outer measures
hec.rothe same way, givingro. - Return
hecitself whenri === hec.riandro === hec.ro. - Otherwise rebuild
hecwithriandrothrough its keyword constructor, withrebuild_struct.
Related