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

source
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}) -> VecVecNum

Return 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 by factory.
  • X: Asset return matrix, observations by assets.
  • fees: Fees, or nothing.

Returns

  • rku::VecNum: For one measure, the unitary risks from unitary_expected_risks.
  • rkus::VecVecNum: For a vector of measures, one vector of unitary risks per measure, in the order of rs.

Related

source
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) -> VecNum

Return 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$: scale of the $k$-th risk measure of a vector, its weight in the combination.
  • $\gamma$: Smoothing parameter gamma of a LogSumExpScalariser, 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 by factory.
  • rku, rkus: The unitary risks of r, or of each measure of rs, from herc_unitary_risks.
  • cl: Asset indices of the cluster.

Returns

  • v::VecNum: The shares, of length length(cl), in the order of cl.

Related

source
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}) -> Number

Return 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$: scale of 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 gamma of a LogSumExpScalariser, 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 by factory.
  • rku, rkus: The unitary risks of r, or of each measure of rs, from herc_unitary_risks.
  • cl: Asset indices of the cluster.
  • X: Asset return matrix, observations by assets.
  • fees: Fees, or nothing.

Returns

  • risk::Number: The combined risk of the cluster.

Related

source
PortfolioOptimisers.herc_risk — Function
herc_risk(hec::HierarchicalEqualRiskContribution, pr::AbstractPriorResult,
          cls::VecVecInt, fees::Option{<:Fees}) -> Tuple

Compute the shares inside each cluster and the risk of each cluster that HERC allocates with.

Algorithm

  1. Resolve the inner measure ri against pr and hec.opt.slv, with factory.
  2. Compute its unitary risks riku, with herc_unitary_risks.
  3. When hec.ro is the same object as hec.ri, take ro = ri and roku = riku. Otherwise resolve ro and compute roku the same way.
  4. For each cluster cl, under the executor hec.ex, write the shares of herc_intra_cluster_weights into w[cl], and the risk of herc_cluster_risk into the cluster's entry of rkcl.

Arguments

  • hec: The optimiser. It gives the measures, the scalarisers scai and scao, and the executor ex.
  • pr: Prior result. Its X is the return matrix, and its moments resolve the measures.
  • cls: Asset indices of each cluster, one entry per cluster.
  • fees: Resolved fees, or nothing. The caller resolves them on its own universe and strips both liquidation charges, lq and flq, first, because a cluster-level risk prices no forced exit. The exiting asset is in no cluster, because its column is NaN.

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

source
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

  1. Bind the inner measures hec.ri to rd with bind_data_benchmark, giving ri.
  2. Bind the outer measures hec.ro the same way, giving ro.
  3. Return hec itself when ri === hec.ri and ro === hec.ro.
  4. Otherwise rebuild hec with ri and ro through its keyword constructor, with rebuild_struct.

Related

source