Hierarchical Risk Parity: private API

PortfolioOptimisers.hierarchical_risk_parity_td_defaults — Function
hierarchical_risk_parity_td_defaults(

) -> @NamedTuple{r::Variance{RiskMeasureSettings{Float64, Nothing, Bool}, Nothing, Nothing, Nothing, SquaredSOCRiskExpr, EigenFallbackSquareRoot, SquareRootRatio, Nothing}, sca::Nothing}

Return the static defaults of the HierarchicalRiskParity 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.split_factor_weight_constraints — Method
split_factor_weight_constraints(alpha::Number, wb::WeightBounds, w::VecNum,
                                lc::VecNum, rc::VecNum) -> Number

Clamp a bisection split factor so that neither half of the split leaves its weight bounds.

The recursion scales the left half by alpha and the right half by 1 - alpha. Both halves carry the weight of their part before the split, so the bounds on each half's total are bounds on the factor. HierarchicalRiskParity and SchurComplementHierarchicalRiskParity both call it.

Mathematical definition

\[\begin{align} L(C) &= \sum_{i \in C} l_i\,,\\ U(C) &= \sum_{i \in C} u_i\,,\\ \alpha_1 &= \min\left(\frac{U(C_1)}{W(C)}, \max\left(\frac{L(C_1)}{W(C)}, \alpha\right)\right)\,,\\ \hat{\alpha} &= 1 - \min\left(\frac{U(C_2)}{W(C)}, \max\left(\frac{L(C_2)}{W(C)}, 1 - \alpha_1\right)\right)\,. \end{align}\]

Where:

  • $l_i$, $u_i$: Lower and upper weight bounds of asset $i$, with $l_i \leq u_i$.
  • $L(C)$, $U(C)$: Lower and upper bounds on the total weight of part $C$.
  • $C_1$, $C_2$: Halves of a part of the dendrogram's leaf order. $C_1$ holds the first $\lfloor n/2 \rfloor$ of the part's $n$ leaves, and $C_2$ holds the rest.
  • $W(C)$: Weight of the part $C$ before the split, with $W(C) > 0$.
  • $\alpha$: Split factor, the fraction of the part's weight that goes to $C_1$. $C_2$ receives $1 - \alpha$.
  • $\alpha_1$: The factor clamped to the bounds of $C_1$.
  • $\hat{\alpha}$: The factor clamped to the bounds of $C_1$, then to the bounds of $C_2$.

The clamp to the bounds of $C_2$ comes last. When the bounds of the two halves cannot both hold, those of $C_2$ hold and those of $C_1$ do not. When $L(C) \leq W(C) \leq U(C)$, the two intervals of the factor meet, and $\hat{\alpha}$ lies in both. The root part has $W = 1$, so when $\sum_i l_i \leq 1 \leq \sum_i u_i$ every part keeps its total inside its bounds, and every asset holds its own bounds at the last split.

Algorithm

  1. Read the weight of the part, c, from the first member of the left half. The recursion scales every member of a part by the same factors, so each member carries the part's weight.
  2. When c is zero, return alpha unchanged. The weights of the two halves are zero whatever the factor, and the bounds divided by c are not defined.
  3. Clamp alpha to the bounds of the left half, $\alpha_1$.
  4. Clamp 1 - alpha to the bounds of the right half, and return its complement, $\hat{\alpha}$.

Arguments

  • alpha: The unclamped split factor, the left half's share of the part's weight.
  • wb: Resolved weight bounds. wb.lb and wb.ub must be vectors over the whole universe, which is what weight_bounds_constraints returns.
  • w: The current weight vector, before this split.
  • lc: Asset indices of the left half.
  • rc: Asset indices of the right half.

Returns

  • alpha::Number: The clamped split factor, a scalar.

Related

source
PortfolioOptimisers.hrp_scalarised_risk — Function
hrp_scalarised_risk(sca::Option{<:Scalariser}, wu::MatNum, rkus::VecVecNum, lc::VecNum,
                    rc::VecNum, rs::VecOptRM, X::MatNum,
                    fees::Option{<:Fees}) -> Tuple

Combine several risk measures into the one left and one right risk that a bisection step needs.

Each measure builds its own naive risk parity sub-portfolio for the two halves, because the weights follow that measure's own unitary risks. The scalariser then combines the pairs of the measures into a single pair.

Mathematical definition

\[\begin{align} \tilde{w}^{(k)}_i(C) &= \frac{\rho_k(\{i\})^{-1}}{\sum_{j \in C} \rho_k(\{j\})^{-1}} \quad \forall\, i \in C\,,\\ \boldsymbol{p}_k &= s_k \left(\rho_k\left(\tilde{\boldsymbol{w}}^{(k)}(C_1)\right), \rho_k\left(\tilde{\boldsymbol{w}}^{(k)}(C_2)\right)\right)\,,\\ \left(\tilde{\rho}(C_1), \tilde{\rho}(C_2)\right) &= \begin{cases} \sum_{k} \boldsymbol{p}_k & \text{sum}\,,\\ \boldsymbol{p}_{k^\star},\; k^\star = \underset{k}{\arg\max}\, \boldsymbol{1}^\intercal \boldsymbol{p}_k & \text{max}\,,\\ \boldsymbol{p}_{k^\star},\; k^\star = \underset{k}{\arg\min}\, \boldsymbol{1}^\intercal \boldsymbol{p}_k & \text{min}\,,\\ \frac{1}{\gamma} \log \sum_{k} \exp\left(\gamma \, \boldsymbol{p}_k\right) & \text{log-sum-exp}\,. \end{cases} \end{align}\]

Where:

  • $\rho_k$: Risk measure $k$ of rs.
  • $\rho_k(\{i\})$: Risk of asset $i$ held alone under $\rho_k$, the entry $i$ of rkus[k].
  • $\tilde{\boldsymbol{w}}^{(k)}(C)$: Naive risk parity weights of $\rho_k$ inside part $C$, zero outside it.
  • $s_k$: scale of the $k$-th risk measure of a vector, its weight in the combination.
  • $\boldsymbol{p}_k$: The scaled pair of risks of the two halves under $\rho_k$.
  • $C_1$, $C_2$: Halves of a part of the dendrogram's leaf order. $C_1$ holds the first $\lfloor n/2 \rfloor$ of the part's $n$ leaves, and $C_2$ holds the rest.
  • $\gamma$: Smoothing parameter gamma of a LogSumExpScalariser, positive. The logarithm and the exponential act on each entry of the pair.

The four cases are SumScalariser, MaxScalariser, MinScalariser and LogSumExpScalariser. A maximum or a minimum selects one measure by the total of its pair and returns that measure's own pair. It does not take the maximum or the minimum of each entry.

Arguments

  • sca: Scalarisation strategy.
  • wu: Scratch weight matrix, of size size(X, 2) by two. It is refilled per measure.
  • rkus: The unitary risks of each measure, from unitary_expected_risks. rkus[k] belongs to rs[k], and has length size(X, 2).
  • lc: Asset indices of the left half.
  • rc: Asset indices of the right half.
  • rs: Vector of risk measures, already resolved by factory.
  • X: Asset return matrix, observations by assets.
  • fees: Fees, or nothing.

Returns

  • (lrisk, rrisk)::Tuple: The combined left and right risk.

Related

source
PortfolioOptimisers.bind_data_benchmark — Method
bind_data_benchmark(hrp::HierarchicalRiskParity, rd::ReturnsResult)

Bind every DataBenchmarkTracking of the risk measures r 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 measures hrp.r to rd with bind_data_benchmark, giving r.
  2. Return hrp itself when r === hrp.r.
  3. Otherwise rebuild hrp with r through its keyword constructor, with rebuild_struct.

Related

source