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

  1. In the direct call on a programme set, the default of pr fits the set's prior on X with allocation_set_prior.
  2. In the direct call on a programme set, resolve the step with resolve_allocation_set_step, which gives the set after factory(set, w) and the Result cbr of its block, and call the three-argument form.
  3. On a bounded set, add the weight bounds and the budget of one with set_allocation_set_bounds!, and return set.wb with no block Result.
  4. On a programme set, add the budget of one with set_budget_constraints!. Add the block, the ceilings and the floor with add_allocation_set_block! under the empty prefix. Return the bounds of the step and cbr.

Arguments

  • model::JuMP.Model: The JuMP optimisation model.
  • set: The Allocation Set, resolved once per fold. In the three-argument form, the set after factory(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, a ReturnsResult, or nothing.
  • pr: The prior result that the slots which read the rows are built on, allocation_set_prior of the set on X, or nothing when the set reads no rows.
  • cbr: The ResolvedConstraintBlock of the set at the step, or nothing for a bounded set.

Validation

  • A slot that reads the rows, with X === nothing. The default of pr throws an ArgumentError, 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_priced throws an ArgumentError.

Returns

  • (wb, cbr)::Tuple: The weight bounds of the step that the model holds, and the ResolvedConstraintBlock of the set, or nothing for a bounded set. The projection programme of project reads the floor of wb under a barrier geometry.

Related

source
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's op when it holds one.

Objective

  • Min: $s_o$ times obj_expr.

Where:

  • $d$: The divergence div of 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

source
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:

  1. Reduce the geometry and q to the mask with investable_geometry_view, and view the set at it.
  2. When the bounds of the set at the mask do not reach the budget, by feasible_bounds, record a Held Step with record_held_step!, and return a copy of w. Stop.
  3. Project onto the reduced set, from w cut 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 of w.
  4. 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, or nothing.

Returns

  • w'::Vector: The projected allocation over the full universe, or a copy of w on a Held Step.

Related

source
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

  1. Reduce the geometry and q to the mask with investable_geometry_view.
  2. Make a bare model with the set's two scales and the row count of X, zero when there are no rows. Register k = 1, and the vector w of weight variables.
  3. Add the set's constraints with the three-argument form of set_allocation_set_constraints!. This gives the weight bounds wb of the step.
  4. Refuse a floor of wb that the geometry does not admit, with assert_geometry_admits_bounds.
  5. 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 read cbr.
  6. Set the objective with set_projection_objective!.
  7. Solve on projection_solver with solve_projection_programme!. When the solve gives an allocation, take its answer on the mask with programme_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 of w.

JuMP formulation

Variables

  • w: created, with the base name w, one variable for each asset in the mask. It is registered in the Model State under the key w.

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, or nothing when every asset is investable; the set after factory(set, w), viewed at the mask; and the Result of the block of a programme set, or nothing for a bounded set.
  • q: The raw step.
  • w: The Price-Adjusted Allocation the step trades from.
  • X: The rows of the step, or nothing.

Validation

Returns

  • w'::Vector: The projected allocation, or w copied on a Held Step.

Related

source
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) -> Bool

Returns 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.

  1. A prior estimator returns false. A factor prior reads the factor returns, and a cross-sectional prior reads the Panel Fields.
  2. An EmpiricalPrior returns true when it states no horizon, and both pe.me and pe.ce return true. A horizon takes log(1 + x), which is not finite at x = -1.
  3. An ImpliedVolatility, a PriorExpectedReturns and a CustomValueExpectedReturns return false. They read the implied volatility surface, an inner prior, and a value of the user.
  4. Each other estimator returns true when each of its fields returns true. A covariance estimator subtypes StatsBase.CovarianceEstimator and not AbstractEstimator, so the method takes both supertypes.
  5. A vector returns true when each of its entries returns true. A Pair returns the result for its value.
  6. 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: true when the mask of the prior reads only the returns and the active mask.

Related

source