Risk budgeting: private API
PortfolioOptimisers.AbstractResolvedRiskBudgeting — Type
abstract type AbstractResolvedRiskBudgeting <: AbstractResolvedAbstract supertype of the values that set_risk_budgeting_constraints! returns.
A RiskBudgetingResult holds one of them in its field rbr, so a caller can read the budget that the model used.
Related
PortfolioOptimisers.RiskBudgetingFormulation — Type
abstract type RiskBudgetingFormulation <: OptimisationAlgorithmAbstract supertype of the formulations of the risk budgeting condition that AssetRiskBudgeting selects.
The # Mathematical definition of RiskBudgeting states each formulation, and set_risk_budgeting_constraints! states the rows of each.
Related
PortfolioOptimisers.RiskBudgetingAlgorithm — Type
abstract type RiskBudgetingAlgorithm <: OptimisationAlgorithmAbstract supertype of the choice between a budget over the assets and a budget over the factors.
Related
PortfolioOptimisers.ResolvedFactorRiskBudgeting — Type
struct ResolvedFactorRiskBudgeting{__T_rkb, __T_b1, __T_rr} <: AbstractResolvedRiskBudgetingHolds the factor budget, the factor basis and the loadings of a RiskBudgeting solve with FactorRiskBudgeting.
Fields
rkb: TheRiskBudgetof the factors, one entry for each column ofrr.L.
b1: The factor basis $(\mathbf{B}^\intercal)^{+}$, of size $N \times N_{f}$. The asset weights areb1 * w1, plus the off-factor block whenflag = true.
rr: The loadings regression thatb1comes from. ItsLis $\mathbf{B}$.
Constructors
ResolvedFactorRiskBudgeting(; rkb::RiskBudget, b1::MatNum, rr::AbstractLoadingsRegressionResult) -> ResolvedFactorRiskBudgetingKeywords correspond to the struct's fields.
Related
PortfolioOptimisers.ResolvedAssetRiskBudgeting — Type
struct ResolvedAssetRiskBudgeting{__T_rkb} <: AbstractResolvedRiskBudgetingHolds the asset budget of a RiskBudgeting solve with AssetRiskBudgeting.
Fields
rkb: TheRiskBudgetof the assets, one entry for each asset.
Constructors
ResolvedAssetRiskBudgeting(; rkb::RiskBudget) -> ResolvedAssetRiskBudgetingKeywords correspond to the struct's fields.
Related
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
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, ornothingto usesets.xkey.
Related
PortfolioOptimisers.risk_budgeting_scale_floor — Function
risk_budgeting_scale_floor(rb::RiskBudgeting) -> NumberReturn 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
kminof the optimiser or a size that the model derives. It is not negative, and zero turns the floor off. A statedrb.kminreplaces the formula. - $b_{g}^{+}$: The upper bound of the budget
rb.opt.bgt, frombudget_upper_bound.
Arguments
rb::RiskBudgeting: The optimiser, whosekminoverrides the size above.
Returns
kmin::Number: The lower bound of $k$.
Related
PortfolioOptimisers._set_risk_budgeting_constraints! — Method
_set_risk_budgeting_constraints!(model::JuMP.Model, rb::RiskBudgeting,
w::VecJuMPScalar; strict::Bool = false) -> RiskBudgetAdd 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}$ fromrisk_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 ofw.
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
kminof 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 torisk_budget_constraints.
Validation
- The budget has one entry for each entry of
w. Otherwise aDimensionMismatchnames both lengths.
Returns
rkb::RiskBudget: The budget that the row reads.
Related
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
w: $\boldsymbol{y}$, registered byset_w!forLogRiskBudgeting.lw,sw: $\boldsymbol{y}^{+}$, $\boldsymbol{y}^{-}$, registered byset_rb_mip_w!forMixedIntegerRiskBudgeting.wis then the expression $\boldsymbol{y}^{+} - \boldsymbol{y}^{-}$.w1,w2: $\boldsymbol{y}_{f}$, $\tilde{\boldsymbol{y}}_{af}$, registered byset_factor_risk_contribution_constraints!forFactorRiskBudgeting.wis then an expression of them.
Constraints
- The rows of
_set_risk_budgeting_constraints!, on $\boldsymbol{y}$ forLogRiskBudgetingwith no orthant vector, on $\boldsymbol{z} \odot \boldsymbol{y}$ with an orthant vector, on $\boldsymbol{y}^{+} + \boldsymbol{y}^{-}$ forMixedIntegerRiskBudgeting, and on $\boldsymbol{y}_{f}$ forFactorRiskBudgeting. orthcrkb: $\boldsymbol{z} \odot \boldsymbol{y} \geq \boldsymbol{0}$, forLogRiskBudgetingwith an orthant vector.- For
MixedIntegerRiskBudgeting, the binary variables and the rows $\boldsymbol{y}^{+} \leq M \boldsymbol{g}$ and $\boldsymbol{y}^{-} \leq M (\boldsymbol{1} - \boldsymbol{g})$ come later, fromset_mip_constraints!, which reads theWeightsFromPartscontract thatset_rb_mip_w!records.
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 thatFactorRiskBudgetingreads when it fits the loadings. The asset methods do not read it.
Validation
LogRiskBudgetingwith no orthant vector: no weight bound is negative. Otherwiseassert_long_only_weight_boundsthrows anArgumentError. This is the one method that readswb.LogRiskBudgetingwith an orthant vector:zhas one entry for each asset. Otherwise aDimensionMismatchnames both lengths.
Returns
ResolvedAssetRiskBudgetingforAssetRiskBudgeting, andResolvedFactorRiskBudgetingforFactorRiskBudgeting.
Related
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
PortfolioOptimisers.reader_frames — Method
reader_frames(rba::FactorRiskBudgeting, path::AbstractString, refit::Bool) -> ReturnsFramesReturn 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:truewhen a regression reader atx_src = nothingin the group fits its regression on the raw returns data.refits_regressionfinds the value.
Returns
fr::ReturnsFrames: The frames ofrba.re.
Related