Near optimal centering (a)

PortfolioOptimisers.ConstrainedNearOptimalCentering — Type
struct ConstrainedNearOptimalCentering <: NearOptimalCenteringAlgorithm

Constrained Near Optimal Centering algorithm.

It selects the branch whose centring model holds every constraint of opt. The model is built by the shared assemble_jump_model!, so every setting of the JuMPOptimiser reaches it, and $\mathcal{W}$ of NearOptimalCentering is the whole feasible set. Use this variant when a setting must bind on the centring solve itself. UnconstrainedNearOptimalCentering lists the settings that the default variant does not read.

Related

source
PortfolioOptimisers.UnconstrainedNearOptimalCentering — Type
struct UnconstrainedNearOptimalCentering <: NearOptimalCenteringAlgorithm

Unconstrained Near Optimal Centering algorithm. This is the default alg of NearOptimalCentering.

It selects the branch whose centring model holds a part of the constraints of opt. The model holds the weight bounds and the budgets, the risk expression, the return expression and the fees that are not fixed. The other constraint and penalty builders do not run. "Unconstrained" names that omission.

The constructor reads and checks the omitted settings, and it does not refuse them. They still have an effect. The anchor of obj is a MeanRisk problem that builds every constraint, so an omitted setting changes that anchor, and through it the bounds of the region. The anchors of minimum risk and of maximum return solve with the same constraints, without the bounds of the risk measures and of the return terms. An omitted setting reaches no model at all only when w_min, w_opt and w_max are all given, because then no sub-problem runs.

Settings the centring model reads

pe, slv, wb, bgt, sbgt, gbgt, sc, so, sca, the part of fees that is not fixed, and ret. The model reads the copy of ret without bounds, see no_bounds_optimiser. It reads the convex form of bgt, convex_budget, so a BudgetCosts with xbgt = true keeps its ceiling and the floor of the invested weights, and not the floor that holds the cost.

Settings the centring model does not read

lcse, cte, card, gcarde, scard, sgcarde, smtx, sgmtx, slt, sst, sglt, sgst, lt, st, xbgt, ss, tn, tr, ple, l2c, lpc, linfc, l1, l2, linf, lp, ccnt, cobj, and the fixed part of fees. A fixed fee is charged for each position held, so it needs the binary variables of set_mip_constraints!.

cobj is the one omission that changes the objective and not the feasible set. set_near_optimal_objective_function! adds no Objective Penalty to the barrier, so a Custom Objective Term prices the anchor sub-problems and not the centring solve.

A block after the first

A block that reaches the head through the keyword blocks of its entry follows the same rule. The centring model holds the weight bounds wb and the short and gross budgets sbgt and gbgt of the block, as rows under the namespace of the block, and no other row. The barrier holds a term for each bound of opt.wb alone. The risk ceilings r and the return floor ret of the set do not reach the centring model, as the bounds of the risk measures and of the return terms of the head do not. Every anchor sub-problem holds every row of every block, the ceilings and the floor of the set among them.

Related

source
PortfolioOptimisers.NearOptimalCenteringResult — Type
struct NearOptimalCenteringResult{__T_jr, __T_w_min_retcode, __T_w_opt_retcode, __T_w_max_retcode, __T_noc_retcode, __T_fb} <: RiskJuMPOptimisationResult

Result type for Near Optimal Centering portfolio optimisation.

Fields

  • r: The risk measure the optimisation ran under, or a vector of them, stored resolved. Every Deferred Quantity in it is fitted, and every unstated slot holds the prior's field. A resolved measure is fitted state, not configuration, so it belongs on the Result. Pass it back as expected_risk(res.r, res.w, res.pr; sca = res.sca). The type of r is not a type parameter of the Result, so the Results of two risk measures have one type, and a verb that reads them compiles one time.
  • 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.
  • fb: The fallback chain that answered this result: the (estimator, result) pair of every attempt optimise made before this one, in the order they ran, or nothing when the estimator it was asked of answered (see FbChain).

A property that is a field of this type reads the field. Every other property, the weights w and the return code retcode included, reads the embedded JuMPOptimisationResult jr.

Related

source
PortfolioOptimisers.NearOptimalCentering — Type
struct NearOptimalCentering{__T_opt, __T_r, __T_obj, __T_bins, __T_w_min, __T_w_min_ini, __T_w_opt, __T_w_opt_ini, __T_w_max, __T_w_max_ini, __T_alg, __T_fb} <: RiskJuMPOptimisationEstimator

Finds the analytic centre of the near optimal region around the portfolio of an objective.

NearOptimalCentering solves three anchor portfolios as MeanRisk problems: the portfolio of minimum risk, the portfolio of maximum return, and the portfolio of obj. The anchors set a floor on the return and a ceiling on the risk. The portfolios that satisfy both bounds are the near optimal region. The result is the analytic centre of that region, the point that maximises the product of the margins of its inequalities.

Mathematical definition

The near optimal region holds the portfolios whose return is at least $\epsilon_{1}$ and whose risk is at most $\epsilon_{2}$:

\[\begin{align} \mathrm{ret} &\geq \epsilon_{1}\,, \\ R(\boldsymbol{w}) &\leq \epsilon_{2}\,, \\ \boldsymbol{w} &\in \mathcal{W}\,. \end{align}\]

The two bounds are the return and the risk of the anchor of obj, moved by one part in $m$ of the span of the other two anchors:

\[\begin{align} \epsilon_{1} &= \mathrm{ret}(\boldsymbol{w}_{\mathrm{opt}}) - \frac{\mathrm{ret}(\boldsymbol{w}_{\max}) - \mathrm{ret}(\boldsymbol{w}_{\min})}{m}\,, \\ \epsilon_{2} &= R(\boldsymbol{w}_{\mathrm{opt}}) + \frac{R(\boldsymbol{w}_{\max}) - R(\boldsymbol{w}_{\min})}{m}\,. \end{align}\]

The result minimises the logarithmic barrier of the region:

\[\begin{align} \underset{\boldsymbol{w}}{\min} \; &- \ln\left(\mathrm{ret} - \epsilon_{1}\right) - \ln\left(\epsilon_{2} - R(\boldsymbol{w})\right) - \sum_{i \in \mathcal{L}} \ln\left(w_{i} - w_{l,i}\right) - \sum_{i \in \mathcal{U}} \ln\left(w_{u,i} - w_{i}\right) \\ \text{s.t.} \quad &\boldsymbol{w} \in \mathcal{W}\,. \end{align}\]

Section 11.4 of [12] states the region for a book with $\boldsymbol{w} \geq \boldsymbol{0}$ and a unit budget, and its barrier holds the term $-\ln(w_{i})$ of the lower bound. Its Listing 11.13 also holds the term $-\ln(1 - w_{i})$ of the upper bound. The barrier above has one term for each finite weight bound, so it is the barrier of Section 8.5.3 of [188] for the bounds of opt.wb. With the default bounds $0$ and $1$, the two barriers are equal. An asset whose two bounds are equal has a fixed weight. That is an equality, so it has no term.

A positive scale of one inequality does not move its analytic centre. So the scale of the constraints, opt.sc, does not move the result, and the combination weight of a single risk measure does not move it either.

A Frontier in opt makes obj give one anchor $\boldsymbol{w}_{\mathrm{opt}}$ for each point of the sweep, and the result holds one centre for each point.

Where:

  • $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
  • $\mathcal{W}$: Feasible weight set, the portfolios that the constraints of the optimiser admit. UnconstrainedNearOptimalCentering and ConstrainedNearOptimalCentering state which constraints of opt it holds.
  • $R(\boldsymbol{w})$: Portfolio risk. The anchors read it with expected_risk.
  • $\mathrm{ret}$: Return expression of the model, the model's :ret. It is the sum of the scaled expressions of the return terms whose rte is true. The anchors read it with expected_return.
  • $\boldsymbol{w}_{\min}$, $\boldsymbol{w}_{\mathrm{opt}}$, $\boldsymbol{w}_{\max}$: The anchors of minimum risk, of obj, and of maximum return, the fields w_min, w_opt and w_max when they are given.
  • $m$: Number of bins, bins. The default is $T / N$, so a wider universe or a shorter history gives a wider region.
  • $w_{l,i}$, $w_{u,i}$: Lower and upper weight bounds of asset $i$, from opt.wb.
  • $\mathcal{L}$, $\mathcal{U}$: The assets whose lower bound, and whose upper bound, is finite and differs from the other bound, see barrier_weight_bounds.
  • $T$, $N$: Number of observations and number of assets.

Fields

  • opt: JuMP optimiser configuration.
  • r: Risk measure or vector of risk measures.
  • obj: Portfolio objective function.
  • bins: Number of bins $m$. The near optimal region extends one part in $m$ of the span of the anchors past the anchor of obj. If nothing, $m = T / N$.
  • w_min: Anchor portfolio of minimum risk. If nothing, a sub-problem solves it.
  • w_min_ini: Initial weights of the sub-problem of minimum risk.
  • w_opt: Anchor portfolio of the objective, or one for each point of a frontier sweep. If nothing, a sub-problem solves it.
  • w_opt_ini: Initial weights of the sub-problem of the objective.
  • w_max: Anchor portfolio of maximum return. If nothing, a sub-problem solves it.
  • w_max_ini: Initial weights of the sub-problem of maximum return.
  • fb: Fallback result or estimator.

Constructors

NearOptimalCentering(;    opt::JuMPOptimiser,    r::TD{<:RM_VecRM} = StandardDeviation(),    obj::TD_Option{<:ObjectiveFunction} = MinimumRisk(),    bins::Option{<:Number} = nothing,    w_min::TD_Option{<:VecNum} = nothing,    w_min_ini::TD_Option{<:VecNum} = nothing,    w_opt::TD_Option{<:VecNum_VecVecNum} = nothing,    w_opt_ini::TD_Option{<:VecNum_VecVecNum} = nothing,    w_max::TD_Option{<:VecNum} = nothing,    w_max_ini::TD_Option{<:VecNum} = nothing,    alg::NearOptimalCenteringAlgorithm = UnconstrainedNearOptimalCentering(),    fb::TDO_Option{<:OptE_Opt} = nothing) -> NearOptimalCentering

Keywords correspond to the struct's fields. A field of the type TD, TD_Option or TDO_Option can hold a TimeDependent schedule in place of a static value. The risk measures, the objective, the anchor weights, the initial weights and the fallback define the problem, so a cross-validation fold loop resolves them for each fold. An optimise outside a fold loop uses the static default of each field. bins and alg control the solve, and they stay static.

Validation

  • If r is a vector: !isempty(r).
  • If w_min is a vector: !isempty(w_min).
  • If w_min_ini is a vector: !isempty(w_min_ini).
  • If w_opt is a vector: !isempty(w_opt).
  • If w_opt_ini is a vector: !isempty(w_opt_ini).
  • If w_max is a vector: !isempty(w_max).
  • If w_max_ini is a vector: !isempty(w_max_ini).
  • If bins is a number: isfinite(bins) && bins > 0.
  • A schedule in fb: bind !== :nearest.
  • The constructor refuses a risk expression that is identically zero, and a return expression that is identically zero. The barrier reads both expressions, see assert_risk_measure_required and assert_return_term_required.
  • Each schedule, with the static defaults in the place of the other schedules, must build an estimator, see assert_time_dependent_substitution.
  • If r holds a DataBenchmarkTracking: opt.pe must not state x_src = ExcessSource(), see assert_data_benchmark_prior.
  • A risk measure whose expression is a JuMP.QuadExpr logs a warning, because the barrier needs an affine or a conic risk. The variance with SDP constraints is the trace of a matrix, which is affine, so it works.
  • A part that states no source and reads the raw returns, beside a part that states x_src = ExcessSource(), logs one warning that names its path, see warn_raw_readers. The constructor then builds the estimator as configured.

Propagated parameters

factory passes its arguments on to these @fprop fields:

  • opt: Recursively updated through factory.
  • r: Recursively updated through factory.
  • fb: Recursively updated through factory.

View parameters

NearOptimalCentering defines its own port_opt_view method. It does not derive one from the field tags.

  • The method reads the returns matrix X as its third argument. When opt.pe holds a prior result, the method uses opt.pe.X in place of X. So the views of the children read the observations of the prior, and not the matrix of the caller.
  • opt and r recurse through port_opt_view with that matrix.
  • fb recurses through view_child with that matrix.
  • The six weight vectors w_min, w_min_ini, w_opt, w_opt_ini, w_max and w_max_ini are sliced to the selected assets.
  • obj, bins and alg pass through unchanged.

Related

References

  • [241] D. Cajas. Robust portfolio selection with near optimal centering. Available at SSRN 3572435 (2019).
  • [242] T. de Graaf. Robust Mean-Variance Optimization. Master's Thesis, Leiden University (2016).
  • [12] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 11.4, Equations 11.30 to 11.32. The original source of this formulation was not found. The formulation follows this work and is not checked against the original.
  • [188] S. Boyd and L. Vandenberghe. Convex Optimization (Cambridge University Press, Cambridge, UK, 2004). Section 8.5.3, Problem 8.18.
source
PortfolioOptimisers.factory — Method
factory(a, args...; kwargs...) -> a
factory(a::AbstractArray{<:Union{Nothing, AbstractEstimator, AbstractAlgorithm,
                                 AbstractResult, StatsBase.CovarianceEstimator}},
        args...; kwargs...) -> AbstractArray

Rebuild an estimator, an algorithm or a result with runtime values. These two methods are the leaf and the array step of the traversal.

factory and port_opt_view are the two propagation mechanisms of this library. factory passes runtime values, such as prior moments, observation weights and previous portfolio weights, down a tree of composed structs. port_opt_view passes an index selection, a subset of the assets, down the same tree.

factory is a traversal, so it owns the identity on every leaf, as fmap in Functors.jl and adapt_structure in Adapt.jl do. A value that has no method of its own comes back with no change: a data field, a scalar, nothing, a set of observation weights and a covariance estimator of StatsBase. So a @propagatable struct sends each @fprop field to factory directly, whatever the field holds.

The array method is the one forwarding contract for every propagation field that holds an array of estimators, algorithms, results or covariance estimators. It applies factory to each element, and it forwards args... and kwargs... with no change. A family that accepts an array of them needs no method of its own. A family that needs more than the forward defines its own, more specific method. A concrete element type, through concrete_typed_array_if_abstract, is an example. An array of data, such as a vector of numbers, is a leaf, and it comes back with no change and with no copy.

Algorithm

The leaf method:

  1. Return a with no change, and drop args... and kwargs.... This method is the leaf of the recursion. Because of it, a call of the verb on a type with no tags returns the value and raises no error.

The array method:

  1. For each element ai of a, call factory on ai, and forward args... and kwargs... with no change.
  2. Collect the results into a new array of the shape of a, in the order of a, and return it.

A @propagatable struct always has a generated method that is more specific than the leaf method. If the struct has at least one @fprop or @wprop field, that method builds the struct again with its keyword constructor. It sends each @fprop field through factory and each @wprop field through _wprop. If the struct has no such field, that method returns x.

The leaf method does not fill a nothing field. A weights field that must take the incoming weights when it holds nothing carries @wprop, and it goes to _wprop.

Arguments

  • a: Any value, which the leaf method returns with no change. For the array method, an array of estimators, algorithms, results, covariance estimators or nothing, which it rebuilds one element at a time.
  • args...: Positional arguments. The leaf method ignores them, and the array method forwards them.
  • kwargs...: Keyword arguments. The leaf method ignores them, and the array method forwards them.

Returns

  • a: The input with no change, for the leaf method.
  • v::AbstractArray: The rebuilt elements, in an array of the shape of a, for the array method.

Examples

julia> factory(nothing, 1, 2; x = 3)julia> factory([1.0, 2.0], 1, 2; x = 3)2-element Vector{Float64}: 1.0 2.0julia> factory(MeanValue())MeanValue  w ┴ nothing

Related

source
factory(res::NonFiniteAllocationOptimisationResult, fb::Option{<:OptE_Opt_FbChain})

Rebuilds a continuous optimisation result with a new fallback record fb.

A concrete result can add its own method when a rebuild needs more than a new fb. optimise is the one caller, and it gives the FbChain of the attempts that failed.

Algorithm

  1. Read every field of res, in the order of the struct.
  2. Call the constructor of the type of res with every field except the last, and with fb as the last field.

Validation

  • fb is the last field of the type of res. Every concrete optimisation result obeys this rule, so the method checks nothing.

Related

source
factory(
    opt::Union{NonFiniteAllocationOptimisationEstimator, NonFiniteAllocationOptimisationResult},
    _
) -> EqualWeighted{_A, _B, _C, _D, _E, Bool} where {_A, _B, _C, _D, _E}

Returns opt unchanged.

This is the fallback factory of an optimisation estimator or result. An estimator whose parameters change at each step of an optimisation adds its own method. A precomputed result in a field of an estimator, for example in fb, reaches this method when factory gives the estimator the weights of the previous fold. A precomputed result does not change.

Related

source
PortfolioOptimisers.factory — Method
factory(a, args...; kwargs...) -> a
factory(a::AbstractArray{<:Union{Nothing, AbstractEstimator, AbstractAlgorithm,
                                 AbstractResult, StatsBase.CovarianceEstimator}},
        args...; kwargs...) -> AbstractArray

Rebuild an estimator, an algorithm or a result with runtime values. These two methods are the leaf and the array step of the traversal.

factory and port_opt_view are the two propagation mechanisms of this library. factory passes runtime values, such as prior moments, observation weights and previous portfolio weights, down a tree of composed structs. port_opt_view passes an index selection, a subset of the assets, down the same tree.

factory is a traversal, so it owns the identity on every leaf, as fmap in Functors.jl and adapt_structure in Adapt.jl do. A value that has no method of its own comes back with no change: a data field, a scalar, nothing, a set of observation weights and a covariance estimator of StatsBase. So a @propagatable struct sends each @fprop field to factory directly, whatever the field holds.

The array method is the one forwarding contract for every propagation field that holds an array of estimators, algorithms, results or covariance estimators. It applies factory to each element, and it forwards args... and kwargs... with no change. A family that accepts an array of them needs no method of its own. A family that needs more than the forward defines its own, more specific method. A concrete element type, through concrete_typed_array_if_abstract, is an example. An array of data, such as a vector of numbers, is a leaf, and it comes back with no change and with no copy.

Algorithm

The leaf method:

  1. Return a with no change, and drop args... and kwargs.... This method is the leaf of the recursion. Because of it, a call of the verb on a type with no tags returns the value and raises no error.

The array method:

  1. For each element ai of a, call factory on ai, and forward args... and kwargs... with no change.
  2. Collect the results into a new array of the shape of a, in the order of a, and return it.

A @propagatable struct always has a generated method that is more specific than the leaf method. If the struct has at least one @fprop or @wprop field, that method builds the struct again with its keyword constructor. It sends each @fprop field through factory and each @wprop field through _wprop. If the struct has no such field, that method returns x.

The leaf method does not fill a nothing field. A weights field that must take the incoming weights when it holds nothing carries @wprop, and it goes to _wprop.

Arguments

  • a: Any value, which the leaf method returns with no change. For the array method, an array of estimators, algorithms, results, covariance estimators or nothing, which it rebuilds one element at a time.
  • args...: Positional arguments. The leaf method ignores them, and the array method forwards them.
  • kwargs...: Keyword arguments. The leaf method ignores them, and the array method forwards them.

Returns

  • a: The input with no change, for the leaf method.
  • v::AbstractArray: The rebuilt elements, in an array of the shape of a, for the array method.

Examples

julia> factory(nothing, 1, 2; x = 3)julia> factory([1.0, 2.0], 1, 2; x = 3)2-element Vector{Float64}: 1.0 2.0julia> factory(MeanValue())MeanValue  w ┴ nothing

Related

source
factory(
    opt::Union{NonFiniteAllocationOptimisationEstimator, NonFiniteAllocationOptimisationResult},
    _
) -> EqualWeighted{_A, _B, _C, _D, _E, Bool} where {_A, _B, _C, _D, _E}

Returns opt unchanged.

This is the fallback factory of an optimisation estimator or result. An estimator whose parameters change at each step of an optimisation adds its own method. A precomputed result in a field of an estimator, for example in fb, reaches this method when factory gives the estimator the weights of the previous fold. A precomputed result does not change.

Related

source
PortfolioOptimisers.port_opt_view — Method
port_opt_view(
    noc::NearOptimalCentering,
    i,
    X::AbstractMatrix{<:Union{Number, AbstractJuMPScalar}},
    args...
) -> NearOptimalCentering

Return a copy of NearOptimalCentering for the assets i.

Algorithm

  1. If noc.opt.pe holds a prior result, replace X with its matrix noc.opt.pe.X.
  2. View opt and r through port_opt_view, and fb through view_child, with that matrix.
  3. Slice the six weight vectors w_min, w_min_ini, w_opt, w_opt_ini, w_max and w_max_ini to i.
  4. Build the estimator, with obj, bins and alg unchanged.

Related

source

References

[12]
D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025).
[188]
S. Boyd and L. Vandenberghe. Convex Optimization (Cambridge University Press, Cambridge, UK, 2004).
[241]
D. Cajas. Robust Portfolio Selection with Near Optimal Centering. Available at SSRN 3572435 (2019).
[242]
T. de Graaf. Robust Mean-Variance Optimization. Master's thesis, Leiden University (2016).