JuMP weight finaliser

The weight finaliser below moves weights into their bounds with a JuMP programme. It can hold a ConstraintBlock, so an optimiser with no solver of its own, such as HierarchicalRiskParity or EqualWeighted, takes the constraint kinds of a JuMPOptimiser.

PortfolioOptimisers.JuMPWeightFinaliser — Type
struct JuMPWeightFinaliser{__T_slv, __T_cbe, __T_sc, __T_so, __T_alg} <: WeightFinaliser

Moves the weights into their bounds, and into the feasible set of a ConstraintBlock, with the solution of a JuMP programme.

The programme keeps the sum of the input weights, holds every weight between its bounds, and holds every constraint of the block in cbe. The field alg selects the objective, the distance from the input that the programme minimises. So a clustering or naive optimiser, which has no solver of its own, takes every constraint kind of a JuMP optimiser.

Each slot of the block is a keyword and a property of the finaliser, as in JuMPOptimiser, so wf.card reads wf.cbe.card. The optimiser that holds the finaliser is the one source of the weight bounds wb and of the sets, and the block holds neither. The split of the optimiser, the finaliser and the result then read one set of bounds.

A finaliser with no slots solves no programme for weights that break no bound, and returns them. With a slot it solves the programme for every input, because it does not test the constraints on the input.

The block

The finaliser is the owner of its block. The head gives it its prior result, its returns data, its sets, its fees and its strict flag, and the block resolves in the two stages of a JuMP optimiser, resolve_constraint_block_names and resolve_constraint_block. These rules hold for the slots:

  • The net budget is the sum of the input weights. A long-short book takes sbgt, gbgt and xbgt.
  • A slot that reads a prior, such as tr, cte, an estimator in ple, an exposure row in lcse or a Calibration Rule, needs a head that fits one. EqualWeighted, RandomWeighted and BestConstantRebalancedPortfolio refuse it.
  • A turnover ceiling in tn takes the reference that the caller gives, and a fold loop replaces it with the weights of the previous fold, as in JuMPOptimiser.
  • A tracking error in tr reads the fees of the head. No other slot reads them.
  • The penalties l1, l2, lp and linf and the custom objective terms cobj add to the objective. A penalty weighs against the distance of alg. A norm keeps the answer at a feasible input while the dual norm of the gradient of the penalty is at most one. So a penalty has no effect there. Use a penalty with SquaredL2Norm, with EuclideanProjection or with another geometry.
  • No slot holds a TimeDependent schedule. The optimiser schedules the whole finaliser, wf = TimeDependent([...]).
  • The constraints that a risk measure states, such as a risk ceiling or a return floor, are not slots of the block.

The objective

A failed solve

The finaliser logs a warning and returns the weights of a default IterativeWeightFinaliser. With no slots, that repair meets every constraint that the finaliser holds, so finalise_weight_bounds tests it against the bounds. With a slot, the repair can break the slot, so the return code is an OptimisationFailure with the solver trials, and the fallback chain of the head runs.

Note

A mixed-integer slot makes each finalisation a mixed-integer programme, which needs a mixed-integer solver in slv. These slots are card, scard, gcarde, sgcarde, smtx and sgmtx, lt, st and the sub-group thresholds, conc, an integer phylogeny in ple, and xbgt. A fixed fee of the head does the same beside a tracking error. A clustering or naive head has no solve of its own, so the finaliser can be the whole cost of a fit. A cross-validation loop solves the programme once for each fold, and a meta head once for each inner optimisation that holds the finaliser.

Fields

  • slv: Solver or vector of solvers.
  • cbe: Constraint Block that holds the feasible set of the weights and the terms of the Objective Penalty, see ConstraintBlock. Its slots are flat keywords and properties of the owner. In a weight finaliser its wb and its sets are nothing, because the optimiser states both.
  • sc: Constraint scale factor.
  • so: Objective scale factor.
  • alg: Weight finaliser error formulation algorithm.

Constructors

JuMPWeightFinaliser(;    slv::Slv_VecSlv,    cbe::Option{<:ConstraintBlock} = nothing,    sc::Number = 1.0,    so::Number = 1.0,    alg::WfF_ProjG = ErrorWeightFinaliser(),    slots...) -> JuMPWeightFinaliser

Keywords correspond to the struct's fields and to the slots of ConstraintBlock, except wb and sets. slots... takes each keyword of the block with its type and its default, and the constructor builds the block in cbe from them. When the caller gives cbe, a flat keyword replaces that slot of the given block, see constraint_block. The default bounds of a ConstraintBlock are not nothing, so a block that the caller builds states wb = nothing. A name that is neither a field nor a slot raises a MethodError.

Validation

The constructor of ConstraintBlock checks each slot on its own.

  • If slv is a VecSlv: !isempty(slv).
  • sc > 0, so > 0.
  • cbe.wb and cbe.sets are nothing. An ArgumentError is thrown otherwise: state them on the optimiser.
  • No slot of cbe holds a TimeDependent. An ArgumentError is thrown otherwise.
  • A GramProjection in alg holds its matrix A. An ArgumentError is thrown otherwise.

Propagated parameters

factory passes its arguments on to these @fprop fields:

  • cbe: Recursively updated through factory.

View parameters

port_opt_view takes the view of these @vprop fields at the selected indices:

Observation weight parameters

obs_weights_view indexes these fields to the selected observations:

Examples

julia> wf = JuMPWeightFinaliser(; slv = Solver(; solver = nothing), card = 10);julia> wf.card10julia> wf.algErrorWeightFinaliser  alg ┼ L1Norm      │   ddof ┴ Int64: 0  dev ┴ RelativeWeightDeviation()

Related

source
PortfolioOptimisers.set_clustering_weight_finaliser_alg! — Function
set_clustering_weight_finaliser_alg!(model::JuMP.Model, alg::ErrorWeightFinaliser,
                                     wi::VecNum)
set_clustering_weight_finaliser_alg!(model::JuMP.Model,
                                     proj::AbstractProjectionGeometry, wi::VecNum)

Adds the objective of a JuMPWeightFinaliser to its programme.

opt_weight_bounds adds the weights w and the rows before it calls this function. A RelativeWeightDeviation divides by wi, so weight_deviation replaces each zero entry of a copy of wi with eps(eltype(wi)). It does not change wi. The method for a geometry is set_projection_objective!, which states its rows.

JuMP formulation

The rows of the method for an ErrorWeightFinaliser.

Variables

  • w: The weights, read from the model.
  • t: The bound on the deviation, created.

Constraints

  • The rows of set_norm_error_epigraph! for the norm alg.alg, which bound the norm of the residual $\boldsymbol{d}$ by $t$. They are unnamed.
  • An unnamed row, in place of these rows, for a SquaredL2Norm when the model holds an Objective Penalty: $(s_c t,\, s_c / 2,\, s_c \boldsymbol{d}) \in \mathcal{K}_{\mathrm{RSOC}}$, that is $t \geq \lVert \boldsymbol{d} \rVert_2^2$. Without a penalty the norm and its square have the same minimiser.

Objective

  • Min: $s_o (t + \pi)$. The objective pulls $t$ down, so $t$ equals the norm, or its square, at the optimum.

Where:

  • $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
  • $\boldsymbol{w}_{0}$: Portfolio weights vector $N \times 1$ that the optimisation produced, which the finaliser repairs.
  • $\boldsymbol{d}$: The residual of weight_deviation for alg.dev, $\boldsymbol{w} \oslash \tilde{\boldsymbol{w}}_{0} - \boldsymbol{1}$ for a RelativeWeightDeviation, and $\boldsymbol{w} - \boldsymbol{w}_{0}$ for an AbsoluteWeightDeviation.
  • $\tilde{\boldsymbol{w}}_{0}$: $\boldsymbol{w}_{0}$ with each zero entry replaced by eps(eltype(wi)), so that the division is defined.
  • $t$: Bound on the norm of the deviation, or on its square.
  • $\pi$: The Objective Penalty of the block, zero when the model holds none.
  • $\mathcal{K}_{\mathrm{RSOC}}$: Rotated second-order cone.
  • $s_c$: Constraint scale. It multiplies both sides of a row, so a positive value leaves the feasible set unchanged.
  • $s_o$: Objective scale. It multiplies the objective, so a positive value leaves the argument of the optimum unchanged.
  • $\oslash$: Element-wise division.
  • $\boldsymbol{1}$: Vector of ones.

Arguments

  • model: The JuMP model. It must already hold w and the two scales sc and so.
  • alg: The deviation and its norm.
  • proj: The Projection Geometry.
  • wi: The weights that the optimisation produced.

Returns

  • nothing.

Related

source