Risk budgeting: private API

PortfolioOptimisers.ResolvedFactorRiskBudgeting — Type
struct ResolvedFactorRiskBudgeting{__T_rkb, __T_b1, __T_rr} <: AbstractResolvedRiskBudgeting

Holds the factor budget, the factor basis and the loadings of a RiskBudgeting solve with FactorRiskBudgeting.

Fields

  • rkb: The RiskBudget of the factors, one entry for each column of rr.L.
  • b1: The factor basis $(\mathbf{B}^\intercal)^{+}$, of size $N \times N_{f}$. The asset weights are b1 * w1, plus the off-factor block when flag = true.
  • rr: The loadings regression that b1 comes from. Its L is $\mathbf{B}$.

Constructors

ResolvedFactorRiskBudgeting(;    rkb::RiskBudget, b1::MatNum, rr::AbstractLoadingsRegressionResult) -> ResolvedFactorRiskBudgeting

Keywords correspond to the struct's fields.

Related

source
PortfolioOptimisers.risk_budgeting_td_defaults — Function
risk_budgeting_td_defaults(

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

Return the static defaults of the RiskBudgeting fields that can hold a TimeDependent.

The constructor reads these defaults when it checks each schedule with assert_time_dependent_substitution, and time_dependent_field_defaults returns them. So the value of each field outside a fold loop is declared once. A field whose static default is nothing is not in the result.

Returns

  • (; r = Variance(), rba = AssetRiskBudgeting()).

Related

source
PortfolioOptimisers.risk_budget_universe_key — Function
risk_budget_universe_key(rba::RiskBudgetingAlgorithm,
                         N::Integer) -> Option{<:AbstractString}

Return the key of the universe a named risk budget resolves against, or nothing for the asset frame.

The budget has one entry for each variable that it is over, so the algorithm, and not the sets, decides the universe that names it. AssetRiskBudgeting budgets the asset weights and takes the default axis. FactorRiskBudgeting budgets the factor weights w1 and takes the factor axis that its re names, which factor_axis_key reads.

The method reads the axis only when rba.rkb is a RiskBudgetEstimator. A RiskBudget holds its own vector and resolves no names, so the method does not check an axis that it does not read. Every other reader of the declared axis does the same. When the method reads the axis, factor_universe checks it against N, the number of factor weights, which is size(rr.L, 2). Under a DimensionReductionRegression that is the size of the reduced basis, not the number of columns of F. So the method refuses a budget that names the original factors, before the solve meets a DimensionMismatch.

Arguments

  • rba: Risk budgeting algorithm.
  • N: Number of budgeted variables, length(w) at the call site.

Returns

  • key::Option{<:AbstractString}: The universe key, or nothing to use sets.xkey.

Related

source
PortfolioOptimisers.risk_budgeting_scale_floor — Function
risk_budgeting_scale_floor(rb::RiskBudgeting) -> Number

Return the lower bound $k_{\min}$ of the variable $k$ that scales the weights of a RiskBudgeting: rb.kmin when the caller states it, and a size derived from the budget of rb.opt otherwise.

The floor closes the collapse of the scale. A positive budget fixes $\boldsymbol{1}^\intercal \boldsymbol{y} = b_{g} k$. In an orthant whose solution has a negative sum, the solve then drives $k$ toward zero, and the weights $\boldsymbol{w} = \boldsymbol{y} / k$ grow without bound. A finite weight bound or a finite short budget stops the collapse. Without them only the tolerance of the solver stops it. On the floor, the weights miss the budget, and a $k$ on the floor is the signal of that case.

$1 / b_{g}^{+}$ is the floor of a long-only book. The row of the logarithm and the weighted inequality of the arithmetic and the geometric means give $\boldsymbol{1}^\intercal \boldsymbol{y} \geq 1$, so no long-only model can fix $k$ below it. A long-short book, or the factor form, has no such bound, so the factor $10^{-4}$ is a margin with two limits. It must be below the smallest scale that a well-posed model fixes, which is $0.46 / b_{g}^{+}$ as measured over the risk budgeting tests. It must be above the scale where the solver stops on a collapse, measured at $2.2 \times 10^{-6}$. It is the margin of the floor of MaximumRatio.

With no budget, or a budget with no upper bound, no row ties $k$ to the sum of the weights, and $b_{g}^{+} = \infty$ gives $k_{\min} = 0$. A zero budget does not read $k$, and it also gives $k_{\min} = 0$.

Mathematical definition

\[\begin{align} k_{\min} &= \begin{cases} 10^{-4} / \lvert b_{g}^{+} \rvert & \text{if } 0 < \lvert b_{g}^{+} \rvert < \infty\,, \\ 0 & \text{otherwise}\,. \end{cases} \end{align}\]

Where:

  • $k_{\min}$: Lower bound on the homogenisation variable $k$, the field kmin of the optimiser or a size that the model derives. It is not negative, and zero turns the floor off. A stated rb.kmin replaces the formula.
  • $b_{g}^{+}$: The upper bound of the budget rb.opt.bgt, from budget_upper_bound.

Arguments

  • rb::RiskBudgeting: The optimiser, whose kmin overrides the size above.

Returns

  • kmin::Number: The lower bound of $k$.

Related

source
PortfolioOptimisers._set_risk_budgeting_constraints! — Method
_set_risk_budgeting_constraints!(model::JuMP.Model, rb::RiskBudgeting,
                                 w::VecJuMPScalar; strict::Bool = false) -> RiskBudget

Add the row of the logarithm, $\boldsymbol{b}^\intercal \ln(\boldsymbol{x}) \geq 0$, and the variable $k$, to the model of a RiskBudgeting.

Every method of set_risk_budgeting_constraints! calls it, with the vector $\boldsymbol{x}$ that its formulation reads. The row fixes the scale of the weights, so the function also records a unit budget with set_unit_budget!. A builder that reads effective_k then uses 1 in place of $k$, so it bounds the unscaled weights whose risk the model minimises.

JuMP formulation

Variables

  • k: $k \geq k_{\min} \geq 0$, with $k_{\min}$ from risk_budgeting_scale_floor. A row of $\boldsymbol{y} \in k\, \mathcal{W}$ such as $\boldsymbol{a}^\intercal \boldsymbol{y} \leq c\, k$ states $\boldsymbol{a}^\intercal \boldsymbol{w} \leq c$ only when $k > 0$. A negative $k$ reverses every such row.
  • log_w: $\boldsymbol{t}$, one entry for each entry of w.

Constraints

  • clog_w[i]: $(t_{i}, 1, x_{i}) \in \mathcal{K}_{\exp}$, which is $t_{i} \leq \ln x_{i}$ with $x_{i} > 0$.
  • crkb: $\boldsymbol{b}^\intercal \boldsymbol{t} \geq 0$.

Where:

  • $\boldsymbol{x}$: The vector w.
  • $\boldsymbol{t}$: Lower bounds of the logarithms of $\boldsymbol{x}$.
  • $\boldsymbol{b}$: The budget, resolved from rb.rba.rkb.
  • $\mathcal{K}_{\exp} = \mathrm{cl}\,\{(a,b,c) : b\, e^{a/b} \leq c,\, b > 0\}$: Exponential cone.
  • $k_{\min}$: Lower bound on the homogenisation variable $k$, the field kmin of the optimiser or a size that the model derives. It is not negative, and zero turns the floor off.

Arguments

  • model::JuMP.Model: The JuMP optimisation model.
  • rb: The optimiser.
  • w: The vector that the logarithm reads: the weights, the weights times the orthant vector, the sum of the long and short parts, or the factor weights.
  • strict: Passed on to risk_budget_constraints.

Validation

  • The budget has one entry for each entry of w. Otherwise a DimensionMismatch names both lengths.

Returns

  • rkb::RiskBudget: The budget that the row reads.

Related

source
PortfolioOptimisers.set_risk_budgeting_constraints! — Function
set_risk_budgeting_constraints!(model, rb, pr, wb, args...)
set_risk_budgeting_constraints!(model, rb, pr, wb, rd::ReturnsResult)

Add the weights and the row of the logarithm of a RiskBudgeting to the model.

The method dispatches on the formulation of rb.rba. Each method registers the weights and calls _set_risk_budgeting_constraints! with the vector that its formulation reads. The weight bounds and the budgets come next, in phase 1 of the block of the head, set_block_constraints!, which assemble_jump_model! runs. The # Mathematical definition of RiskBudgeting states each programme.

JuMP formulation

Variables

Constraints

Where:

  • $\boldsymbol{y}$: Unscaled weights.
  • $\boldsymbol{z}$: Orthant vector rb.rba.alg.z.
  • $\boldsymbol{y}^{+}$, $\boldsymbol{y}^{-}$: Long and short parts of $\boldsymbol{y}$.
  • $\boldsymbol{y}_{f}$, $\tilde{\boldsymbol{y}}_{af}$: Factor exposures and off-factor weights.
  • $\boldsymbol{g}$: Binary vector of the long gates.
  • $M$: Big-M constant, rb.opt.ss.

Arguments

  • model::JuMP.Model: The JuMP optimisation model.
  • rb: The optimiser.
  • pr: Prior result.
  • wb::WeightBounds: Weight bound specification containing lower and upper bounds.
  • rd: Returns data that FactorRiskBudgeting reads when it fits the loadings. The asset methods do not read it.

Validation

Returns

Related

source
PortfolioOptimisers.set_rb_mip_w! — Function
set_rb_mip_w!(model::JuMP.Model, X::MatNum)

Register the long and short parts of the weights of MixedIntegerRiskBudgeting, and the weights as their difference.

The weights are an expression of the parts, so the function records the WeightsFromParts contract with set_decomposition_contract!. set_mip_constraints! reads the contract, and gates the parts with one binary variable for each asset.

JuMP formulation

Variables

  • lw: $\boldsymbol{y}^{+} \geq \boldsymbol{0}$.
  • sw: $\boldsymbol{y}^{-} \geq \boldsymbol{0}$.

Expressions

  • w: $\boldsymbol{y}^{+} - \boldsymbol{y}^{-}$, the unscaled weights.
  • w_obj: $\boldsymbol{y}^{+} + \boldsymbol{y}^{-}$, the vector that the row of the logarithm reads.

Arguments

  • model::JuMP.Model: The model.
  • X::MatNum: Returns matrix. The function reads its number of columns.

Returns

  • nothing.

Related

source
PortfolioOptimisers.reader_frames — Method
reader_frames(rba::FactorRiskBudgeting, path::AbstractString, refit::Bool) -> ReturnsFrames

Return the frames of the regression reader of rba, at "path.re", for the frame walk of a RiskBudgeting head.

Arguments

  • rba: The factor risk budgeting algorithm.
  • path: The path of the value from the head, for example "pe", "cle" or "r[2].pe". A warning names a reader by its path.
  • refit: true when a regression reader at x_src = nothing in the group fits its regression on the raw returns data. refits_regression finds the value.

Returns

  • fr::ReturnsFrames: The frames of rba.re.

Related

source