Near optimal centering (b): private API
PortfolioOptimisers.assemble_near_optimal_centering_model! — Method
assemble_near_optimal_centering_model!(alg, model, noc, setup, rd; blocks = ())Run the model-assembly middle of the Near Optimal Centering variant alg.
The two variants share a head and a Result, and differ only in the middle and in the solve. This is the middle. ConstrainedNearOptimalCentering delegates to the shared assemble_jump_model!, whose block builder adds every block, the weight bounds and the budgets among them. UnconstrainedNearOptimalCentering adds the weight bounds and the budgets of opt with set_weight_constraints!, and the weight bounds and the budgets of each block after the first with set_block_weight_constraints!. It adds no other row of a block. It then runs the four steps of that sequence it needs — non-fixed fees, risk, scalarisation, return — and then the same assert_frontier_sweep_cap tail.
set_non_fixed_fees! runs before the risk build, as it does in assemble_jump_model!. It is what makes the model's return expression net of fees, and the barrier compares that expression against the noc_rt target, which near_optimal_centering_setup computes net of fees as well. A fixed fee still does not apply: it needs the cardinality binaries set_mip_constraints! produces, and that builder belongs to the middle this variant does not run.
UnconstrainedNearOptimalCentering lists every opt setting the resulting model reads and every setting it does not.
The unconstrained variant reads setup.opt, which near_optimal_centering_setup has already replaced with the no_bounds_optimiser copy. So opt.ret is the bound-free return estimator, and opt.pe, opt.fees and opt.sca are the processed values setup.attrs carries. The phylogeny argument is nothing because the variant applies no phylogeny constraints.
Arguments
alg: NOC algorithm variant (UnconstrainedNearOptimalCenteringorConstrainedNearOptimalCentering).model::JuMP.Model: The JuMP optimisation model.noc::NearOptimalCentering: Dispatch object for the risk and custom constraint builders.setup::NearOptimalSetup: Setup bundle fromnear_optimal_centering_setup.rd: The returns result to use.blocks: The blocks after the block ofnoc.opt, asassemble_jump_model!takes them.
Returns
nothing. Mutatesmodelin place.
Related
PortfolioOptimisers.anchor_cone_scale — Function
anchor_cone_scale(delta::Num_VecNum, anchor::Num_VecNum)Return the scale that divides the slack of an anchor cone of the barrier of NearOptimalCentering.
The scale is the width delta of the near optimal region, which is the slack of the cone at the anchor of the objective. When the width is negligible against the bound anchor, the scale is one, and the cone keeps its slack in the units of the bound. The anchors of a degenerate region are one portfolio, so its width is of the order of the rounding error. A slack divided by that width puts the tolerance of the solver at the scale of the rounding error, and the solve stops without progress. The width can also be negative by a rounding error, so the bound sits outside the region by that error. A scale below one makes the error larger. With the anchors of the factor exposure test of test_02, a width of -1.1e-13 and a risk bound of 0.0073, the slack divided by the bound stopped at NUMERICAL_ERROR under --check-bounds=yes and coverage, and the slack in the units of the bound solved.
Algorithm
- Compute $s = \max_{i} |\delta_{i}|$ and $m$, the
bound_scaleofanchor. - Return $1$ when
isapprox(m + s, m), and $s$ otherwise.
Arguments
delta::Num_VecNum: The width,rk_deltaorrt_deltaofNearOptimalSetup.anchor::Num_VecNum: The bound of the cone,rk_optorrt_opt, or one for each point of a sweep.
Returns
- The scale, a positive number.
Related
PortfolioOptimisers.solve_near_optimal_centering! — Method
solve_near_optimal_centering!(alg, model, noc, setup)Run the solve tail of the Near Optimal Centering variant alg.
Reads the arguments each solve_noc! overload needs off setup, so the two variants share one _optimise head. The constrained variant sweeps both frontier registries, so it passes the two Val flags that select the sweeping overload; the unconstrained variant registers no frontier bound and passes neither. Both variants pass the anchor_cone_scale of the widths rk_delta and rt_delta of the near optimal region, which divide the anchor cones of the barrier.
Arguments
alg: NOC algorithm variant (UnconstrainedNearOptimalCenteringorConstrainedNearOptimalCentering).model::JuMP.Model: The JuMP optimisation model.noc::NearOptimalCentering: NOC estimator configuration.setup::NearOptimalSetup: Setup bundle fromnear_optimal_centering_setup.
Returns
(retcode, sol)or(retcodes, sols), assolve_noc!returns.
Related
PortfolioOptimisers.get_overall_retcode — Function
get_overall_retcode(w_min_retcode::OptimisationReturnCode, w_opt_retcode::OptimisationReturnCode, w_max_retcode::OptimisationReturnCode, noc_retcode::OptimisationReturnCode)
get_overall_retcode(w_min_retcode::OptimisationReturnCode, w_opt_retcode::OptRetCode_VecOptRetCode, w_max_retcode::OptimisationReturnCode, noc_retcode::VecOptRetCode)Combine the return codes of the three anchors and of the centring solve into the return code of a NearOptimalCentering.
A frontier sweep solves the centring once for each point, so it has one combined code for each point. The anchor of obj can have one code for each point too. The anchors of minimum risk and of maximum return have one code, which stands for every point.
Algorithm
- For one centring solve, write one line of
msgfor each code that is anOptimisationFailure, in the orderw_min,w_opt,w_max,noc_opt. - Return an
OptimisationSuccesswhenmsgis empty. Otherwise warn, and return anOptimisationFailurewhoseresis(; msg, w_min, w_opt, w_max, noc_opt). Each return code keeps its own diagnostics. - For a sweep, do steps 1 and 2 for each point, on the code of the point that
member_retcodereads.
Arguments
w_min_retcode: Return code of the sub-problem of minimum risk.w_opt_retcode: Return code of the sub-problem of the objective, or one for each point of a frontier sweep.w_max_retcode: Return code of the sub-problem of maximum return.noc_retcode: Return code of the centring solve, or one for each point of a frontier sweep.
Returns
retcode::OptRetCode_VecOptRetCode: The combined return code, or one for each point of a frontier sweep.
Related
PortfolioOptimisers.compute_risk_ubs — Method
compute_risk_ubs(model::JuMP.Model, noc::NearOptimalCentering{<:Any, <:Any, <:Any, <:Any, <:Any, <:Any, <:Any, <:Any, <:Any, <:Any, <:ConstrainedNearOptimalCentering}, pr::AbstractPriorResult, fees::Option{<:Fees}, w_min::VecNum, w_max::VecNum, args...)Compute risk upper bounds for a constrained NearOptimalCentering frontier sweep.
Identifies risk frontier entries that are not yet resolved (i.e. not concrete weight vectors) and rebuilds them using the minimum and maximum portfolio weights.
Arguments
model::JuMP.Model: JuMP optimisation model containingrisk_frontier.noc::NearOptimalCentering{..., <:ConstrainedNearOptimalCentering}: Constrained Near Optimal Centering optimiser.pr::AbstractPriorResult: Prior result with asset moments.fees::Option{<:Fees}: Optional fees configuration.w_min::VecNum: Minimum-risk portfolio weights.w_max::VecNum: Maximum-risk (maximum-return) portfolio weights.
Returns
- Updated risk frontier vector of
(keys, vals)pairs.
Related