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 of r, created with no key, only for an LpNorm of an order other than 2 and Inf.

Constraints

The rows that alg selects:

  • L1Norm: $(s_c t,\, s_c \boldsymbol{r}) \in \mathcal{K}_{1}$.
  • L2Norm and SquaredL2Norm: $(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 of L2Norm or of LInfNorm.

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 scale sc.
  • 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. csum and z are nothing off the power cone route.

Related

source
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

  1. Read the budget s as sum(w).
  2. Move w into the bounds with opt_weight_bounds.
  3. 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 is nothing for a head that fits no prior.
  • rd: The returns result to use.
  • sets: Sets used to map estimator values to assets. It is nothing when the head holds none.
  • fees: Optional fees structure.
  • strict: Whether to throw an error if sets does not contain the desired value in sets.dict[key].

Returns

  • (retcode, w): The return code and the moved weights.

Related

source
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

  1. Solve the programme with programme_finalised_weights, giving w and the result res of the solve.
  2. 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 an OptimisationFailure that holds the solver trials.
  3. Otherwise give the return code of weight_bounds_retcode.

Arguments

  • wf: The weight finaliser.
  • wb: The weight bounds. Either bound can be nothing.
  • wi: The weights that the optimisation produced.
  • pr: Prior result. It is nothing for a head that fits no prior.
  • rd: The returns result to use.
  • sets: Sets used to map estimator values to assets. It is nothing when the head holds none.
  • fees: Optional fees structure.
  • strict: Whether to throw an error if sets does not contain the desired value in sets.dict[key].

Returns

  • (retcode, w): The return code and the finalised weights.

Related

source
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

Related

source
PortfolioOptimisers.finaliser_readers — Function
finaliser_readers(wf::WeightFinaliser) -> Tuple
finaliser_readers(wf::JuMPWeightFinaliser) -> Tuple

Gives 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 of wf.

Related

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

Places 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, or nothing.
  • strict: Whether to throw an error if sets does not contain the desired value in sets.dict[key].
  • imsk: The Investable Mask of the head, or nothing when 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

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

Fits 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 if sets does not contain the desired value in sets.dict[key].

Returns

  • wf::WeightFinaliser: The finaliser, with the results of its readers in the slots cte and ple of its block.

Related

source
PortfolioOptimisers.assert_prior_free_finaliser — Function
assert_prior_free_finaliser(wf, head::Symbol) -> Nothing
assert_prior_free_finaliser(wf::JuMPWeightFinaliser, head::Symbol) -> Nothing

Refuses 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 wf reads a prior. An IsNothingError is thrown otherwise.

Returns

  • nothing.

Related

source