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, ornothingwhenr.rcisnothing.
Related
PortfolioOptimisers.reader_frames — Method
reader_frames(wf::JuMPWeightFinaliser, path::AbstractString, refit::Bool) -> ReturnsFramesWalk 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: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 of the slots of the block.
Related
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
- Return
wiwith no solve when an entry is not finite, or when the block holds no slot andwibreaks no bound. - Refuse a slot that reads a prior when
prisnothing, withassert_prior_free_finaliser, and a lower bound that the geometry does not admit, withassert_geometry_admits_bounds. - Build an empty model with the scales of
wf, the row count of the prior,k = 1and the weightsw. - With a slot, add the resolved block with
set_finaliser_block!. With none, add the bounds and the budget withset_finaliser_bounds!. - Add the objective of
wf.algwithset_clustering_weight_finaliser_alg!. - Solve with
solve_projection_programme!onprojection_solver. Return the answer ofprogramme_answerwhen the solve succeeds. - Else log a warning, and return the weights of a default
IterativeWeightFinaliserforwi.
JuMP formulation
Variables
w: The weights, created.
Expressions
k: the constant one.sc: $s_c$.so: $s_o$.
Constraints
- The rows of
set_finaliser_block!or ofset_finaliser_bounds!.
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 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
(w, res)::Tuple: The finalised weights, and the result of the solve, ornothingwhen there was none.
Related
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
- Refuse a gross budget that the net budget and the bounds do not admit, with
assert_gross_budget_admissible. - 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, withinvestable_finaliser, and a resolved slot comes back unchanged. Bind a data benchmark of the tracking slot tord, and resolve the risk contribution rows of each tracked variance oversets, withresolve_tracked_risk_rows. - 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. - 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. - 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 benothing.bgt: The net budget, the sum of the input weights.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
nothing.
Related
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, whenwb.lbholds a finite bound: $s_c (\boldsymbol{w} - \boldsymbol{l}) \geq \boldsymbol{0}$.w_ub, whenwb.ubholds 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 benothing.bgt: The net budget, the sum of the input weights.
Returns
nothing.
Related
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, ornothing.
Returns
bgt::Number: The net budget.
Related
PortfolioOptimisers.holds_block_slot — Function
holds_block_slot(cbe::ConstraintBlock) -> Bool
Tells whether a block holds a slot other than the bounds, the names and the settings.
A JuMPWeightFinaliser with no such slot has the programme of its bounds alone.
Arguments
cbe: The block.
Returns
flag::Bool:truewhen a slot other thanwb,sets,ssandxbgtis notnothing, or whenxbgtistrue.
Related
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 isnothingwhen the head holds none. The constructor of the head then refused a row keyed by name (name_keyed).strict: Whether to throw an error ifsetsdoes not contain the desired value insets.dict[key].datatype: The element type of the rows.
Returns
tr: The slot with the rows of each tracked variance as aLinearConstraint, or the same object when nothing changes.
Related