JuMP weight finaliser: private API

PortfolioOptimisers.risk_contribution_constraints — Method
risk_contribution_constraints(r::Variance, wf::JuMPWeightFinaliser, pr)

Gives the risk contribution rows of a Variance that a tracking error of a weight finaliser tracks.

The finaliser holds no sets. set_finaliser_block! resolved the names of the rows over the sets of the head with resolve_tracked_risk_rows, so the rows are values.

Arguments

  • r: The variance.
  • wf: The weight finaliser.
  • pr: The prior result of the head.

Returns

  • rc::Option{<:LinearConstraint}: The rows, or nothing when r.rc is nothing.

Related

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

Walk the readers in the block of a JuMPWeightFinaliser, for the frame walk of the head that holds it.

Arguments

  • wf: The weight finaliser.
  • 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 the slots of the block.

Related

source
PortfolioOptimisers.programme_finalised_weights — Function
programme_finalised_weights(
    wf::JuMPWeightFinaliser,
    wb::WeightBounds,
    wi::AbstractVector{<:Union{Number, AbstractJuMPScalar}},
    pr::Union{Nothing, AbstractPriorResult},
    rd::Union{Nothing, ReturnsResult},
    sets::Union{Nothing, UniverseSets},
    fees::Union{Nothing, Fees},
    strict::Bool
) -> Union{Tuple{AbstractVector{<:Union{Number, AbstractJuMPScalar}}, Nothing}, Tuple{Any, JuMPResult{Dict{Union{AbstractString, Symbol}, AbstractDict{Symbol}}, Bool}}}

Builds and solves the programme of a JuMPWeightFinaliser.

opt_weight_bounds and finalise_weight_bounds both call it. The return code of the second reads the result of the solve.

Algorithm

  1. Return wi with no solve when an entry is not finite, or when the block holds no slot and wi breaks no bound.
  2. Refuse a slot that reads a prior when pr is nothing, with assert_prior_free_finaliser, and a lower bound that the geometry does not admit, with assert_geometry_admits_bounds.
  3. Build an empty model with the scales of wf, the row count of the prior, k = 1 and the weights w.
  4. With a slot, add the resolved block with set_finaliser_block!. With none, add the bounds and the budget with set_finaliser_bounds!.
  5. Add the objective of wf.alg with set_clustering_weight_finaliser_alg!.
  6. Solve with solve_projection_programme! on projection_solver. Return the answer of programme_answer when the solve succeeds.
  7. Else log a warning, and return the weights of a default IterativeWeightFinaliser for wi.

JuMP formulation

Variables

  • w: The weights, created.

Expressions

  • k: the constant one.
  • sc: $s_c$.
  • so: $s_o$.

Constraints

Where:

  • $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.

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

  • (w, res)::Tuple: The finalised weights, and the result of the solve, or nothing when there was none.

Related

source
PortfolioOptimisers.set_finaliser_block! — Function
set_finaliser_block!(
    model::Model,
    wf::JuMPWeightFinaliser,
    wb::WeightBounds,
    bgt::Number,
    pr::Union{Nothing, AbstractPriorResult},
    rd::Union{Nothing, ReturnsResult},
    sets::Union{Nothing, UniverseSets},
    fees::Union{Nothing, Fees},
    strict::Bool
)

Resolves the block of a JuMPWeightFinaliser, and adds its rows and its penalties to the programme.

Algorithm

  1. Refuse a gross budget that the net budget and the bounds do not admit, with assert_gross_budget_admissible.
  2. Expand a scalar or an absent bound to one bound for each asset. Put the bounds and the sets of the call into the block, and resolve both stages of it, giving cbr. A head already resolved the names on its full universe, with investable_finaliser, and a resolved slot comes back unchanged. Bind a data benchmark of the tracking slot to rd, and resolve the risk contribution rows of each tracked variance over sets, with resolve_tracked_risk_rows.
  3. When the bounds admit a short weight and the block states no sbgt, write the row of the net budget here, and give the block builder no net budget. The builder would pin the long part at the net budget, which forbids a short.
  4. Add both phases of the block with the block builder set_block_constraints!, with the finaliser as the owner. The builder gets the fees only beside a tracking error, so a fixed fee makes no other programme mixed-integer.
  5. Add the custom objective terms of the block with set_block_objective_terms!.

Arguments

  • model::JuMP.Model: The JuMP optimisation model.
  • wf: The weight finaliser.
  • wb: The weight bounds. Either bound can be nothing.
  • bgt: The net budget, the sum of the input weights.
  • 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

  • nothing.

Related

source
PortfolioOptimisers.set_finaliser_bounds! — Function
set_finaliser_bounds!(
    model::Model,
    wb::WeightBounds,
    bgt::Number
)

Adds the bounds and the budget of a JuMPWeightFinaliser with no slots to its programme.

It adds no long and short parts of the weights, because no row reads them.

JuMP formulation

Constraints

  • bgt: $s_c (\boldsymbol{1}^\intercal \boldsymbol{w} - \boldsymbol{1}^\intercal \boldsymbol{w}_{0}) = 0$.
  • w_lb, when wb.lb holds a finite bound: $s_c (\boldsymbol{w} - \boldsymbol{l}) \geq \boldsymbol{0}$.
  • w_ub, when wb.ub holds a finite bound: $s_c (\boldsymbol{w} - \boldsymbol{u}) \leq \boldsymbol{0}$.

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{l}$, $\boldsymbol{u}$: Lower and upper weight bounds. An absent bound is dropped from the programme rather than set to an infinity.
  • $s_c$: Constraint scale. It multiplies both sides of a row, so a positive value leaves the feasible set unchanged.
  • $\boldsymbol{1}$: Vector of ones.

Arguments

  • model::JuMP.Model: The JuMP optimisation model.
  • wb: The weight bounds. Either bound can be nothing.
  • bgt: The net budget, the sum of the input weights.

Returns

  • nothing.

Related

source
PortfolioOptimisers.finaliser_budget — Function
finaliser_budget(
    wi::AbstractVector{<:Union{Number, AbstractJuMPScalar}},
    gbgt::Union{Nothing, Number, BudgetEstimator}
) -> Any

Gives the net budget of the programme of a JuMPWeightFinaliser, the sum of the input weights.

The sum is a float, and it can pass the ceiling of a gross budget by a rounding error, such as 1 + eps beside gbgt = 1. The budget is then that ceiling, so assert_gross_budget_admissible does not refuse it.

Arguments

  • wi: The input weights.
  • gbgt: The gross budget of the block, or nothing.

Returns

  • bgt::Number: The net budget.

Related

source
PortfolioOptimisers.resolve_tracked_risk_rows — Function
resolve_tracked_risk_rows(tr, sets, strict::Bool, datatype::DataType)

Resolves the risk contribution rows of each Variance that a tracking error of a JuMPWeightFinaliser tracks, over the sets of the head.

A JuMP optimiser resolves these rows with its own sets, in risk_contribution_constraints. A finaliser holds no sets, so set_finaliser_block! resolves the rows here, with the sets of the head on the reduced universe, before the block builder reads them. The walk follows bind_data_benchmark: a vector maps over its entries, a RiskTrackingError resolves its risk measure, and any other value comes back unchanged.

Arguments

  • tr: The tracking slot of the block, a vector of them, or a risk measure inside one.
  • sets: Sets used to map estimator values to assets. It is nothing when the head holds none. The constructor of the head then refused a row keyed by name (name_keyed).
  • strict: Whether to throw an error if sets does not contain the desired value in sets.dict[key].
  • datatype: The element type of the rows.

Returns

  • tr: The slot with the rows of each tracked variance as a LinearConstraint, or the same object when nothing changes.

Related

source