Weight finalisers: private API
PortfolioOptimisers.set_norm_error_epigraph! — Function
set_norm_error_epigraph!(model::JuMP.Model, t, r::AbstractVector, alg::NormError)Adds the rows that bound the norm of r by t, $t \geq \lVert \boldsymbol{r} \rVert$, and returns them.
Every row is scaled by the constraint scale $s_c$ of model. The norm gives the order, and norm_epigraph! writes the rows.
JuMP formulation
Variables
z: One auxiliary variable for each entry ofr, created with no key, only for anLpNormof an order other than2andInf.
Constraints
The rows that alg selects:
L1Norm: $(s_c t,\, s_c \boldsymbol{r}) \in \mathcal{K}_{1}$.L2NormandSquaredL2Norm: $(s_c t,\, s_c \boldsymbol{r}) \in \mathcal{K}_{2}$.LInfNorm: $(s_c t,\, s_c \boldsymbol{r}) \in \mathcal{K}_{\infty}$.LpNorm: $(s_c z_{i},\, s_c t,\, s_c r_{i}) \in \mathcal{P}_{1/p}$ for each $i$, and $s_c (\boldsymbol{1}^\intercal \boldsymbol{z} - t) = 0$. At $p = 2$ and $p = \infty$ it is the row ofL2Normor ofLInfNorm.
Where:
- $t$: The bound on the norm.
- $\boldsymbol{r}$: The residual.
- $s_c$: Constraint scale. It multiplies both sides of a row, so a positive value leaves the feasible set unchanged.
- $\mathcal{K}_{q} = \{(t, \boldsymbol{x}) : t \geq \lVert \boldsymbol{x} \rVert_{q}\}$: Norm cone of order $q$. $\mathcal{K}_{2}$ is the second-order cone.
- $\mathcal{P}_{a}$: The power cone $\{(x, y, z) : x^{a} y^{1 - a} \geq \lvert z \rvert,\, x, y \geq 0\}$.
Arguments
model: The JuMP model. It must already hold the constraint scalesc.t: The bound on the norm.r: The residual.alg: The norm.
Returns
(cone, csum, z): The cone row or rows, the sum row and the auxiliary variables.csumandzarenothingoff the power cone route.
Related
PortfolioOptimisers.finalise_weight_bounds — Function
finalise_weight_bounds(wf::WeightFinaliser, wb::WeightBounds, w::VecNum, pr = nothing,
rd = nothing, sets = nothing, fees = nothing,
strict::Bool = false)Moves the weights into their bounds, and gives the return code that states whether the move succeeded.
A failure lets the fallback chain of optimise run. A set of bounds that cannot hold the budget, sum(lb) > sum(w) or sum(ub) < sum(w), always fails.
The arguments after w are the context of the head. A JuMPWeightFinaliser reads them to resolve its ConstraintBlock, and the other finalisers of the library read none of them. A head gives every one of them on the assets of w.
Algorithm
- Read the budget
sassum(w). - Move
winto the bounds withopt_weight_bounds. - Give the return code of
weight_bounds_retcode, together with the moved weights.
Arguments
wf::WeightFinaliser: The weight finaliser.wb::WeightBounds: The weight bounds.w::VecNum: The weights that the optimisation produced.pr: Prior result. It isnothingfor a head that fits no prior.rd: The returns result to use.sets: Sets used to map estimator values to assets. It isnothingwhen the head holds none.fees: Optional fees structure.strict: Whether to throw an error ifsetsdoes not contain the desired value insets.dict[key].
Returns
(retcode, w): The return code and the moved weights.
Related
finalise_weight_bounds(wf::JuMPWeightFinaliser, wb::WeightBounds, wi::VecNum,
pr = nothing, rd = nothing, sets = nothing, fees = nothing,
strict::Bool = false)Moves the weights into their bounds and into the feasible set of the block of wf, and gives the return code that states whether the move succeeded.
Algorithm
- Solve the programme with
programme_finalised_weights, givingwand the resultresof the solve. - When the block holds a slot and there was a solve, the solve decides. A solve that succeeds gives an
OptimisationSuccess, because the solver met every row to its own tolerance. A solve that fails gives anOptimisationFailurethat holds the solver trials. - Otherwise give the return code of
weight_bounds_retcode.
Arguments
wf: The weight finaliser.wb: The weight bounds. Either bound can benothing.wi: The weights that the optimisation produced.pr: Prior result. It isnothingfor a head that fits no prior.rd: The returns result to use.sets: Sets used to map estimator values to assets. It isnothingwhen the head holds none.fees: Optional fees structure.strict: Whether to throw an error ifsetsdoes not contain the desired value insets.dict[key].
Returns
(retcode, w): The return code and the finalised weights.
Related
PortfolioOptimisers.weight_bounds_retcode — Function
weight_bounds_retcode(
wf::WeightFinaliser,
wb::WeightBounds,
w::AbstractVector{<:Union{Number, AbstractJuMPScalar}},
s::Number
) -> Union{OptimisationSuccess{Nothing}, OptimisationFailure{String}}
Gives the return code of finalised weights, from a test of the bounds and the budget.
Arguments
wf: The weight finaliser.wb: The weight bounds.w: The finalised weights.s: The budget of the weights before the finaliser moved them.
Returns
retcode::OptimisationReturnCode: AnOptimisationSuccesswhen the weights meet the test ofweights_meet_bounds: they are finite, they lie in the bounds, and they sum tos, each to a tolerance. Otherwise anOptimisationFailurethat nameswfandwb.
Related
PortfolioOptimisers.finaliser_readers — Function
finaliser_readers(wf::WeightFinaliser) -> Tuple
finaliser_readers(wf::JuMPWeightFinaliser) -> TupleGives the distance readers of a weight finaliser, for the Investable Mask of its head.
A head composes its mask with the assets that its readers can read, see distance_reader_entry_mask. The readers of a JuMPWeightFinaliser are the slots ple and cte of its block. Every other finaliser has none.
Returns
readers::Tuple: The readers ofwf.
Related
PortfolioOptimisers.investable_finaliser — Function
investable_finaliser(wf::WeightFinaliser, sets, strict::Bool, imsk, X::MatNum) -> WeightFinaliser
investable_finaliser(wf::JuMPWeightFinaliser, sets, strict::Bool, imsk, X::MatNum) -> JuMPWeightFinaliserPlaces the weight finaliser of a head on the assets of the Investable Mask, as investable_fees_view places its fees.
A JuMPWeightFinaliser holds a ConstraintBlock with no sets of its own. So the head resolves the names of the block over its own sets, on the universe of the caller, before investable_reduction narrows them. The values then follow a view at the mask. This is stage 1 of the block, resolve_constraint_block_names, in the order of a JuMP head. The method for any other finaliser returns it unchanged.
Arguments
wf: The weight finaliser of the head, on the universe of the caller.sets: Sets used to map estimator values to assets. They are the sets of the head before the reduction, ornothing.strict: Whether to throw an error ifsetsdoes not contain the desired value insets.dict[key].imsk: The Investable Mask of the head, ornothingwhen every asset is investable.X: The returns matrix of the full universe. It gives the element type of the resolved values, and the tracking errors of the block view it.
Returns
wf::WeightFinaliser: The finaliser on the assets of the mask.
Related
PortfolioOptimisers.fit_finaliser_readers — Function
fit_finaliser_readers(wf::WeightFinaliser, pr, rd, strict::Bool) -> WeightFinaliser
fit_finaliser_readers(wf::JuMPWeightFinaliser, pr::AbstractPriorResult, rd::ReturnsResult, strict::Bool) -> JuMPWeightFinaliserFits the distance readers of a weight finaliser on the reduced prior and rows of its head.
A distance reader can refuse an asset that the prior keeps, see DistanceReaderRefusalError. A head calls this function through distance_reader_call before its own solve, so a refusal costs no solve, and the head fits again without the asset. The method for any other finaliser returns it unchanged.
Arguments
wf: The weight finaliser, on the assets of the mask.pr: Prior result.rd: The returns result to use.strict: Whether to throw an error ifsetsdoes not contain the desired value insets.dict[key].
Returns
wf::WeightFinaliser: The finaliser, with the results of its readers in the slotscteandpleof its block.
Related
PortfolioOptimisers.assert_prior_free_finaliser — Function
assert_prior_free_finaliser(wf, head::Symbol) -> Nothing
assert_prior_free_finaliser(wf::JuMPWeightFinaliser, head::Symbol) -> NothingRefuses a weight finaliser whose block reads a prior, in the constructor of a head that fits none.
EqualWeighted, RandomWeighted and BestConstantRebalancedPortfolio fit no prior, so a slot that reads one has no value there (block_reads_prior). The method for any other finaliser, and for a TimeDependent schedule, checks nothing. The constructor of the head runs again with each entry of a schedule.
Arguments
wf: The weight finaliser of the head.head: The name of the head, for the message.
Validation
- No slot of the block of
wfreads a prior. AnIsNothingErroris thrown otherwise.
Returns
nothing.
Related