Base Constraint Generation

PortfolioOptimisers.AbstractConstraintResult — Type
abstract type AbstractConstraintResult <: AbstractResult

Abstract supertype for all constraint result types.

A subtype holds the output of a constraint generator. Most subtypes are assembled constraints, and a field of a JuMPOptimiser accepts them as precomputed values.

Interfaces

To make a new constraint result, subtype AbstractConstraintResult and put the assembled constraint in its fields. Each method below has a fallback for the whole library. A result that the fallback describes correctly implements neither method. A result that the fallback describes wrongly implements one or both.

Routing target

  • PortfolioOptimisers.implicit_constraint_target(res::AbstractConstraintResult) -> Option{Symbol}: The one routing target that a result of this type can go to, or nothing when the type names none.

The fallback returns nothing. add_constraint_result then puts the value in a TargetedConstraint, with the target that its step declared. Implement the method only when the type names exactly one field of a JuMPOptimiser. Only then can the pipeline put the value in that field without the wrapper.

Arguments

  • res: The constraint result.

Returns

Asset view

  • PortfolioOptimisers.port_opt_view(res::AbstractConstraintResult, i, args...) -> AbstractConstraintResult: A copy of the result over the selected assets.

The generic fallback slices an array, and returns a scalar, nothing, an estimator or an algorithm unchanged. It has no method for a result struct, and raises a MethodError on one. A result that a view can reach needs its own method. Tag each field that the view slices with @vprop, and @propagatable makes the method. Write the method by hand when the tags cannot state the view. LinearConstraint is that case. Its method reads neither the index nor the arguments after it, and the method states why the identity is correct.

Arguments

  • res: The constraint result.
  • i: The asset index the view keeps.

Returns

  • res::AbstractConstraintResult: The constraint over the selected assets.

Related

source
PortfolioOptimisers.AbstractConstraintEstimator — Type
abstract type AbstractConstraintEstimator <: AbstractEstimator

Abstract supertype for all constraint estimator types.

A subtype holds the configuration of one constraint family. The generation verb of the family turns the configuration into a constraint over a universe.

Interfaces

To make a new constraint family, subtype AbstractConstraintEstimator and put its parameters in the fields of the struct. Then implement the methods below.

Constraint generation

  • <family>_constraints(ce::AbstractConstraintEstimator, sets::UniverseSets): Assemble the constraint of the family over the declared universe.

Each family has its own verb, and the library has no shared verb name. The verbs are linear_constraints, weight_bounds_constraints, threshold_constraints, risk_budget_constraints, lot_unit_constraints, asset_sets_matrix, phylogeny_constraints and centrality_constraints. A family that fits its structure to data takes a ReturnsResult in place of the sets. A caller calls this method directly, and the pipeline step below calls it too.

Arguments

  • ce: The constraint estimator.
  • sets: The declared universe the names resolve against.

Returns

Pipeline step

Implement both methods, or neither. The fallback of pipe_constraint_targets is an empty tuple. That tuple declares that the family computes no value for the constraints slot, so the family is not a Pipeline step. resolve_constraint_target raises on the empty tuple before it reads the value. Two families take the fallback. JuMPConstraintEstimator configures the model and computes nothing from data. LotUnitEstimator reaches only a finite allocator, which is not a step of a pipeline.

  • PortfolioOptimisers.pipe_constraint_targets(ce::AbstractConstraintEstimator) -> Tuple: The routing targets that the result of the family can go to. With one target, the step places the value with no annotation. With more than one, the PipelineStep wrapper must name one.
  • PortfolioOptimisers.constraint_step_value(ce::AbstractConstraintEstimator, ctx::PipelineContext): The value that the step adds. The method calls the generation verb of the family to compute it.

pipe_reads and pipe_writes need no method. They return (:returns,) and :constraints for every subtype. A family that also reads a computed slot declares it with its own pipe_reads method, as ExposureConstraintEstimator does for :prior.

Arguments

  • ce: The constraint estimator.
  • ctx: The pipeline context.

Returns

  • res: The computed value, nothing, or a vector of either.

Related

source