Allocation Set programme
set_allocation_set_constraints! adds the constraints of a ProgrammeAllocationSet to a JuMP model, in the order a JuMP optimiser adds them. The model is the projection of a raw step onto the set of allowed weights. A follow-the-leader rule adds the same constraints to the optimisation it solves again at each period, through a private function that registers them under other names, so the rule keeps its own constraints and gains those of the set. When the projection does not solve, the rule keeps the weights it had after the price moves of the period, so it trades nothing in that period. set_divergence_objective! sets the objective of a projection programme, and a deviation of your own for a JuMPWeightFinaliser calls it.
mask_reads_returns answers whether the investable mask of a prior reads only the returns and the active mask of the panel. A restart of a first-order rule on a RiskLoss then skips the fit of the prior on rows with no gap. A moment estimator of a user that reads another input adds a method that returns false.
PortfolioOptimisers.set_allocation_set_constraints! — Function
set_allocation_set_constraints!(model::JuMP.Model, set::BoundedAllocationSet, w::AbstractVector, X, pr = nothing)
set_allocation_set_constraints!(model::JuMP.Model, set::BoundedAllocationSet, cbr::Nothing)
set_allocation_set_constraints!(model::JuMP.Model, set::ProgrammeAllocationSet, w::AbstractVector, X, pr = allocation_set_prior(set, X))
set_allocation_set_constraints!(model::JuMP.Model, set::ProgrammeAllocationSet, cbr::ResolvedConstraintBlock)Adds the constraints of a resolved Allocation Set to the bare projection model.
The model must already hold w, k, the two scales and the observation count. On both kinds of set the function adds the weight bounds and the budget of one. On a ProgrammeAllocationSet the projection is the owner of the model, and the set is the owner of its block. The projection writes the budget of one, and the block builder set_block_constraints! adds every kind of the block, which a JuMP optimiser adds through the same builder. The bounds builder set_allocation_risk_return_bounds! adds the risk ceilings and the return floor of the set between the two phases of the block.
The projection programme of project calls the three-argument form. It resolves the block of the set through the shared entry of a bare head, resolve_projection_entry, and gives the set viewed at the Investable Mask and the Result of its block. The four-argument and the five-argument forms are the direct call. They resolve the step themselves, on a model that already holds the width of w, so they cannot drop an asset. A direct call refuses an asset that the prior cannot price, with assert_set_prior_priced, and a distance reader of the set that refuses an asset raises its DistanceReaderRefusalError. A JuMP head does not call this function. The leader re-solve of FollowTheLeader passes the set as a second block of the entry of the head, and assemble_jump_model! adds the block with the same builders under the namespace blk_2_.
Algorithm
- In the direct call on a programme set, the default of
prfits the set's prior onXwithallocation_set_prior. - In the direct call on a programme set, resolve the step with
resolve_allocation_set_step, which gives the set afterfactory(set, w)and the Resultcbrof its block, and call the three-argument form. - On a bounded set, add the weight bounds and the budget of one with
set_allocation_set_bounds!, and returnset.wbwith no block Result. - On a programme set, add the budget of one with
set_budget_constraints!. Add the block, the ceilings and the floor withadd_allocation_set_block!under the empty prefix. Return the bounds of the step andcbr.
Arguments
model::JuMP.Model: The JuMP optimisation model.set: The Allocation Set, resolved once per fold. In the three-argument form, the set afterfactory(set, w), viewed at the Investable Mask of the step.w: The Price-Adjusted Allocation the step trades from. It is the reference of the turnover ceilings and of a tracking benchmark that is not fixed.X: The rows the head holds through the period, aReturnsResult, ornothing.pr: The prior result that the slots which read the rows are built on,allocation_set_priorof the set onX, ornothingwhen the set reads no rows.cbr: TheResolvedConstraintBlockof the set at the step, ornothingfor a bounded set.
Validation
- A slot that reads the rows, with
X === nothing. The default ofprthrows anArgumentError, because a projection gets the rows only inside an Online Update. - In the direct call, a prior whose Investable Mask leaves out an asset the model trades.
assert_set_prior_pricedthrows anArgumentError.
Returns
(wb, cbr)::Tuple: The weight bounds of the step that the model holds, and theResolvedConstraintBlockof the set, ornothingfor a bounded set. The projection programme ofprojectreads the floor ofwbunder a barrier geometry.
Related
PortfolioOptimisers.set_divergence_objective! — Function
set_divergence_objective!(model::Model, div, so)
Sets the objective of a projection programme to the minimum of the divergence div plus the Objective Penalty, times the objective scale.
The projection of a programme Allocation Set and the programme of a JuMPWeightFinaliser call it. A deviation of your own for a JuMPWeightFinaliser gives its deviation to this function in its method of set_clustering_weight_finaliser_alg!, so that the penalties of the block join the objective.
The penalty holds the set's penalties, its custom objective terms and the p · tr(W) term of its semidefinite phylogeny. It enters through add_penalty_to_objective!, which every JuMP head's objective also uses. With no penalty the objective is the divergence alone, which is the plain projection of every published rule.
JuMP formulation
Expressions
obj_expr: $d + \pi$. The function registers $d$ first and then adds the model'sopwhen it holds one.
Objective
Min: $s_o$ timesobj_expr.
Where:
- $d$: The divergence
divof the geometry. - $\pi$: The Objective Penalty
op, zero when the model holds none. - $s_o$: Objective scale. It multiplies the objective, so a positive value leaves the argument of the optimum unchanged.
Arguments
model::JuMP.Model: The JuMP optimisation model.div: The divergence, an affine expression or a variable.so: The objective scale.
Returns
nothing.
Related
PortfolioOptimisers.project — Method
project(proj::AbstractProjectionGeometry, set::AbstractAllocationSet, q::AbstractVector, w::AbstractVector, imsk::Nothing)
project(proj::AbstractProjectionGeometry, set::AbstractAllocationSet, q::AbstractVector, w::AbstractVector, imsk::BitVector)Projects the raw step q onto the Allocation Set at the Investable Mask of the step, and gives a zero weight to every asset outside it.
A rule passes the mask when a reader of the step cannot price every asset: the loss of a first-order rule, or the forecaster of a rule that reads a forecast. The projection then leaves such an asset out, as a batch optimiser leaves out an asset that its prior cannot price, and its answer holds a zero there. A nothing mask is the projection over every asset.
The method serves every set that port_opt_view views at the assets of the mask. A ProgrammeAllocationSet has a method of its own, which intersects the mask with the mask of the prior of the set.
Algorithm
With a mask:
- Reduce the geometry and
qto the mask withinvestable_geometry_view, and view the set at it. - When the bounds of the set at the mask do not reach the budget, by
feasible_bounds, record a Held Step withrecord_held_step!, and return a copy ofw. Stop. - Project onto the reduced set, from
wcut to the mask and not renormalised. When the answer does not meet the budget, it is the Held Step of that projection, and the method returns a copy ofw. - Return the answer with a zero at every asset outside the mask, with
expand_investable_weights.
Arguments
proj: The geometry, over the full universe.set: The set, resolved over the full universe.q: The raw step over the full universe. The method does not read an entry outside the mask.w: The Price-Adjusted Allocation the step trades from, over the full universe. A Held Step returns it, so it trades nothing, also at an asset outside the mask.imsk: The Investable Mask of the step, ornothing.
Returns
w'::Vector: The projected allocation over the full universe, or a copy ofwon a Held Step.
Related
PortfolioOptimisers.project — Method
project(proj::AbstractProjectionGeometry, e::Tuple, q::AbstractVector,
w::AbstractVector, X::Option{<:ReturnsResult})Builds and solves the projection programme of one step at the Investable Mask imsk, from the entry e = (imsk, set, cbr) that the shared entry resolved for the step.
resolve_projection_entry gives the entry. The method takes the three values as one Tuple, so a bounded set always comes with no block Result and a programme set with its own block Result. The entry already dropped every asset that a distance reader of the set refuses, so the model is built once, at the final mask. The refused asset takes a zero weight at the step, as an asset that the prior cannot price does. The Investable Mask of the Recursion Result does not change, because it is the active mask of the last row.
Algorithm
- Reduce the geometry and
qto the mask withinvestable_geometry_view. - Make a bare model with the set's two scales and the row count of
X, zero when there are no rows. Registerk = 1, and the vectorwof weight variables. - Add the set's constraints with the three-argument form of
set_allocation_set_constraints!. This gives the weight boundswbof the step. - Refuse a floor of
wbthat the geometry does not admit, withassert_geometry_admits_bounds. - Add the set's custom objective terms with the block builder
set_block_objective_terms!, with the geometry as the objective and the set as the owner. The terms readcbr. - Set the objective with
set_projection_objective!. - Solve on
projection_solverwithsolve_projection_programme!. When the solve gives an allocation, take its answer on the mask withprogramme_answer, and return it with a zero at every asset outside the mask. Otherwise record the Held Step with the solver trials, and return a copy ofw.
JuMP formulation
Variables
w: created, with the base namew, one variable for each asset in the mask. It is registered in the Model State under the keyw.
Expressions
k: the constant one.
Where:
- $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
- $k$: Variable that scales the budget in the homogenised problem.
Arguments
proj: The geometry.e: The entry of the step,(imsk, set, cbr): the Investable Mask of the step, ornothingwhen every asset is investable; the set afterfactory(set, w), viewed at the mask; and the Result of the block of a programme set, ornothingfor a bounded set.q: The raw step.w: The Price-Adjusted Allocation the step trades from.X: The rows of the step, ornothing.
Validation
- The rules of
assert_geometry_admits_boundson the bounds of the step.
Returns
w'::Vector: The projected allocation, orwcopied on a Held Step.
Related
PortfolioOptimisers.mask_reads_returns — Function
mask_reads_returns(pe::AbstractPriorEstimator) -> Bool
mask_reads_returns(pe::EmpiricalPrior) -> Bool
mask_reads_returns(est::Union{AbstractEstimator, AbstractCovarianceEstimator}) -> Bool
mask_reads_returns(est::Union{ImpliedVolatility, PriorExpectedReturns, CustomValueExpectedReturns}) -> Bool
mask_reads_returns(v::AbstractVector) -> Bool
mask_reads_returns(p::Pair) -> Bool
mask_reads_returns(x) -> BoolReturns true when the Investable Mask of a prior reads only the finiteness of the returns and the active mask of the panel.
Such a prior prices every asset on rows with no gap, see window_without_gap. So loss_mask skips its fit there. A false answer is always safe, because the fit then answers the mask.
Algorithm
Each step is one method, and Julia selects the method from the type of the argument.
- A prior estimator returns
false. A factor prior reads the factor returns, and a cross-sectional prior reads the Panel Fields. - An
EmpiricalPriorreturnstruewhen it states nohorizon, and bothpe.meandpe.cereturntrue. A horizon takeslog(1 + x), which is not finite atx = -1. - An
ImpliedVolatility, aPriorExpectedReturnsand aCustomValueExpectedReturnsreturnfalse. They read the implied volatility surface, an inner prior, and a value of the user. - Each other estimator returns
truewhen each of its fields returnstrue. A covariance estimator subtypesStatsBase.CovarianceEstimatorand notAbstractEstimator, so the method takes both supertypes. - A vector returns
truewhen each of its entries returnstrue. APairreturns the result for its value. - Each other value returns
true.
Interfaces
A moment estimator of a user whose answer for an asset reads an input other than the returns and the panel masks implements mask_reads_returns(est::MyEstimator) = false.
Arguments
pe: A prior estimator, or a member or a field of one.
Returns
flag::Bool:truewhen the mask of the prior reads only the returns and the active mask.
Related