Skip to content
18

Base JuMP Optimisation

PortfolioOptimisers.BaseJuMPOptimisationEstimator Type
julia
abstract type BaseJuMPOptimisationEstimator <: BaseOptimisationEstimator

Abstract supertype for base JuMP-based portfolio optimisation estimators.

These are configuration-level types (e.g., JuMPOptimiser) that define the optimisation problem setup for JuMP-based optimisers.

Related

source
PortfolioOptimisers.JuMPOptimisationEstimator Type
julia
abstract type JuMPOptimisationEstimator <: NonFiniteAllocationOptimisationEstimator

Abstract supertype for JuMP-based portfolio optimisation estimators.

JuMP optimisers formulate and solve portfolio optimisation problems using mathematical programming via the JuMP.jl framework.

Related

source
PortfolioOptimisers.RiskJuMPOptimisationEstimator Type
julia
abstract type RiskJuMPOptimisationEstimator <: JuMPOptimisationEstimator

Abstract supertype for risk-based JuMP portfolio optimisation estimators.

Subtype RiskJuMPOptimisationEstimator to implement optimisers that minimise or constrain risk measures as the primary objective.

Related

source
PortfolioOptimisers.ObjectiveFunction Type
julia
abstract type ObjectiveFunction <: AbstractEstimator

Abstract supertype for portfolio objective functions.

Subtype ObjectiveFunction to implement portfolio optimisation objectives such as minimum risk, maximum return, or maximum Sharpe ratio.

Related

source
PortfolioOptimisers.JuMPReturnsEstimator Type
julia
abstract type JuMPReturnsEstimator <: AbstractEstimator

Abstract supertype for JuMP-based returns estimators used in optimisation models.

JuMPReturnsEstimator types define how expected returns are incorporated into JuMP models.

Related

source
PortfolioOptimisers.JuMPConstraintEstimator Type
julia
abstract type JuMPConstraintEstimator <: AbstractConstraintEstimator

Abstract supertype for JuMP constraint estimators.

The extension point for user-defined constraints and objectives. Rather than subtyping this directly, subtype one of the two purpose-built children and implement its one contract method:

(The objective child subtypes AbstractEstimator directly — it is grouped here as the sibling extension point, not by type hierarchy.)

Related

source
PortfolioOptimisers.CustomJuMPConstraint Type
julia
abstract type CustomJuMPConstraint <: JuMPConstraintEstimator

Abstract supertype for custom JuMP constraint implementations.

Subtype this and implement add_custom_constraint! — the single method the type exists to make you define — to add custom constraints to the JuMP model. Pass the resulting estimator (or a vector of them) as the ccnt field of JuMPOptimiser.

Related

source
PortfolioOptimisers.VecJuMPConstr Type
julia
const VecJuMPConstr = AbstractVector{<:CustomJuMPConstraint}

Alias for a vector of JuMP constraint estimators.

Related

source
PortfolioOptimisers.JuMPConstr_VecJuMPConstr Type
julia
const JuMPConstr_VecJuMPConstr = Union{<:CustomJuMPConstraint, <:VecJuMPConstr}

Alias for a single JuMP constraint estimator or a vector of them.

Related

source
PortfolioOptimisers.CustomJuMPObjective Type
julia
abstract type CustomJuMPObjective <: AbstractEstimator

Abstract supertype for custom JuMP objective implementations.

Subtype this and implement add_custom_objective_term! — the single method the type exists to make you define — to add custom penalty or reward terms to the JuMP model objective. Pass the resulting estimator (or a vector of them) as the cobj field of JuMPOptimiser.

Related

source
PortfolioOptimisers.VecJuMPObj Type
julia
const VecJuMPObj = AbstractVector{<:CustomJuMPObjective}

Alias for a vector of JuMP objective estimators.

Related

source
PortfolioOptimisers.JuMPObj_VecJuMPObj Type
julia
const JuMPObj_VecJuMPObj = Union{<:CustomJuMPObjective, <:VecJuMPObj}

Alias for a single JuMP objective estimator or a vector of them.

Related

source
PortfolioOptimisers.needs_previous_weights Method
julia
needs_previous_weights(_::CustomJuMPConstraint) -> Bool

Return false: custom JuMP constraints never require previous portfolio weights.

source
PortfolioOptimisers.needs_previous_weights Method
julia
needs_previous_weights(_::CustomJuMPObjective) -> Bool

Return false: custom JuMP objectives never require previous portfolio weights.

source
PortfolioOptimisers.is_time_dependent Method
julia
is_time_dependent(opt::JuMPOptimisationEstimator) -> Any

Return true if the estimator's own problem-definition fields, the inner JuMP optimiser, or the fallback carry time-dependent constraints.

source
PortfolioOptimisers.reset_time_dependent_estimator Method
julia
reset_time_dependent_estimator(
    opt::JuMPOptimisationEstimator
) -> Any

Replace time-dependent constraints with their static defaults, both on the estimator's own fields and by recursing into the inner JuMP optimiser and fallback.

source
PortfolioOptimisers.JuMPOptimisationSolution Type
julia
struct JuMPOptimisationSolution{__T_w} <: OptimisationModelResult

Stores the solution (portfolio weights) from a JuMP optimisation model.

Fields

  • w: Portfolio weights vector assets × 1.

Constructors

julia
JuMPOptimisationSolution(; w::ArrNum) -> JuMPOptimisationSolution

Keywords correspond to the struct's fields.

Validation

  • !isempty(w).

Related

source
PortfolioOptimisers.VecJuMPOptSol Type
julia
const VecJuMPOptSol = AbstractVector{<:JuMPOptimisationSolution}

Alias for a vector of JuMP optimisation solutions.

Related

source
PortfolioOptimisers.JuMPOptSol_VecJuMPOptSol Type
julia
const JuMPOptSol_VecJuMPOptSol = Union{<:JuMPOptimisationSolution, <:VecJuMPOptSol}

Alias for a single JuMP optimisation solution or a vector of them.

Related

source
PortfolioOptimisers.BaseJuMPOptimisationResult Type
julia
abstract type BaseJuMPOptimisationResult <: AbstractResult

Abstract supertype for the embedded JuMP optimisation result core.

Mirrors BaseJuMPOptimisationEstimator: the factored-out struct holding the fields common to every JuMP-based optimisation result lives on this branch and is not part of the optimisation result hierarchy. The concrete core is JuMPOptimisationResult.

Related

source
PortfolioOptimisers.RiskJuMPOptimisationResult Type
julia
abstract type RiskJuMPOptimisationResult <: NonFiniteAllocationOptimisationResult

Abstract supertype for JuMP-based continuous optimisation results.

The JuMP half of the result split; mirrors RiskJuMPOptimisationEstimator. Concrete subtypes embed a JuMPOptimisationResult as their first field (jr) and add only their unique fields plus the trailing fb. The default getproperty resolves unique fields directly and delegates everything else (including :w and the pa fall-through) to jr; types with composed sub-result fields override it to forward into those first.

Related

source
Base.propertynames Method
julia
propertynames(r::RiskJuMPOptimisationResult) -> Tuple

Default property enumeration for RiskJuMPOptimisationResult: mirrors the default getproperty by unioning the receiver's own field names with everything forwarded from the embedded JuMPOptimisationResult jr (which itself forwards pa). Concrete subtypes that override getproperty (e.g. via @forward_properties) emit their own, more-specific propertynames.

source
Base.getproperty Method
julia
getproperty(
    r::RiskJuMPOptimisationResult,
    sym::Symbol
) -> Any

Default property access for RiskJuMPOptimisationResult: unique fields resolve directly; everything else delegates to the embedded JuMPOptimisationResult jr.

source
PortfolioOptimisers.NonJuMPOptimisationResult Type
julia
abstract type NonJuMPOptimisationResult <: NonFiniteAllocationOptimisationResult

Abstract supertype for non-JuMP continuous optimisation results.

Groups the results that do not carry a JuMP model (naive, clustering, and meta-optimiser results). Mirrors the JuMP/non-JuMP split on the result side; the JuMP half is RiskJuMPOptimisationResult.

Related

source
PortfolioOptimisers.add_custom_objective_term! Function
julia
add_custom_objective_term!(model::JuMP.Model, obj, cobj::Nothing, optimiser, attrs)
add_custom_objective_term!(model::JuMP.Model, obj, cobj::CustomJuMPObjective, optimiser, attrs)

Add a custom objective term to the JuMP model.

Implement this for a subtype of CustomJuMPObjective to price a preference the library does not already name. Contribute the term with add_to_objective_penalty! rather than touching the objective expression: the accumulated penalty is folded in by add_penalty_to_objective! with the sign factor matching the objective's optimisation sense, so a contribution always worsens the objective and a reward is a negative contribution. This is what makes a term correct under every objective, MaximumRatio included, without the implementer consulting the sense (ADR 0036).

add_to_objective_penalty! promotes an affine accumulator to a quadratic one as needed, so a quadratic term is safe on every configuration.

Terms that are not homogeneous of degree one in w must still multiply any constant by get_k: under a ratio objective the weights are solved in a rescaled space.

There is no no-op fallback for a CustomJuMPObjective — a subtype with no method of its own raises, so a mis-shaped or stale signature fails loudly instead of silently contributing nothing. nothing (no custom term configured) is the only no-op.

Arguments

  • model::JuMP.Model: JuMP optimisation model, mid-assembly.

  • obj: The ObjectiveFunction being built. During a Frontier sweep this differs from the objective the user declared — the endpoint sub-problems are built as MinimumRisk and MaximumReturn.

  • cobj: The custom objective estimator; the argument to dispatch on.

  • optimiser: The outer optimisation estimator (e.g. the MeanRisk itself); its opt field is the JuMPOptimiser.

  • attrs::ProcessedJuMPOptimiserAttributes: Processed problem data — attrs.pr (prior), attrs.ret (returns estimator), attrs.wb (bounds), and the rest.

Returns

  • nothing.

Related

source
julia
add_custom_objective_term!(model::JuMP.Model, obj, cobjs::VecJuMPObj, optimiser, attrs)

Apply each custom objective term in a vector, in order. Dispatches to the per-type add_custom_objective_term! for every element, so a cobj vector composes several custom terms into one objective — they accumulate additively in the shared objective penalty.

Related

source
PortfolioOptimisers.add_custom_constraint! Function
julia
add_custom_constraint!(model::JuMP.Model, ccnt::Nothing, optimiser, attrs)
add_custom_constraint!(model::JuMP.Model, ccnt::CustomJuMPConstraint, optimiser, attrs)

Add a custom constraint to the JuMP model.

Implement this for a subtype of CustomJuMPConstraint to mandate a preference the library does not already name. Two idioms keep a hand-written constraint correct (ADR 0008): scale it by get_constraint_scale, and multiply any constant bound by get_k, the homogenisation variable, so the bound is compared against unrescaled weights under a ratio objective.

There is no no-op fallback for a CustomJuMPConstraint — a subtype with no method of its own raises, so a mis-shaped or stale signature fails loudly instead of silently adding no constraint. nothing (no custom constraint configured) is the only no-op.

Arguments

  • model::JuMP.Model: JuMP optimisation model, mid-assembly.

  • ccnt: The custom constraint estimator; the argument to dispatch on.

  • optimiser: The outer optimisation estimator (e.g. the MeanRisk itself).

  • attrs::ProcessedJuMPOptimiserAttributes: Processed problem data.

Returns

  • nothing.

Related

source
julia
add_custom_constraint!(model::JuMP.Model, ccnts::VecJuMPConstr, optimiser, attrs)

Apply each custom constraint in a vector, in order. Dispatches to the per-type add_custom_constraint! for every element, so a ccnt vector adds several custom constraints to the same model.

Related

source
PortfolioOptimisers.process_model Function
julia
process_model(model, retcode)

Extract the solution from an optimised JuMP model based on the return code.

On success, extracts the optimised weights from the model. On failure, returns an empty solution.

Arguments

Returns

  • Solution object.

Related

source
PortfolioOptimisers.optimise_JuMP_model! Function
julia
optimise_JuMP_model!(model::JuMP.Model, slv::Slv_VecSlv)

Attempt to optimise a JuMP model using one or more configured solvers.

Tries each solver in order, applying settings and checking for solution feasibility. Returns a JuMPResult with trial errors and success status.

Arguments

  • model: JuMP model to optimise.

  • slv: Single Solver or vector of Solver objects.

Returns

  • res::JuMPResult: Result object containing trial errors and success flag.

Details

  • For each solver, sets the optimizer and attributes, runs JuMP.optimize!, and checks solution feasibility.

  • If a solver fails, records the error and tries the next.

  • Stops at the first successful solution.

Related

source
julia
optimise_JuMP_model!(
    model::Model,
    opt::JuMPOptimisationEstimator
) -> Tuple{Union{OptimisationFailure{Dict{Any, Any}}, OptimisationSuccess{Dict{Any, Any}}}, JuMPOptimisationSolution{<:AbstractArray{var"#s35", N}} where {var"#s35"<:(Union{var"#s34", var"#s33"} where {var"#s34"<:Number, var"#s33"<:AbstractJuMPScalar}), N}}
optimise_JuMP_model!(
    model::Model,
    opt::JuMPOptimisationEstimator,
    datatype::DataType
) -> Tuple{Union{OptimisationFailure{Dict{Any, Any}}, OptimisationSuccess{Dict{Any, Any}}}, JuMPOptimisationSolution{<:AbstractArray{var"#s35", N}} where {var"#s35"<:(Union{var"#s34", var"#s33"} where {var"#s34"<:Number, var"#s33"<:AbstractJuMPScalar}), N}}

Attempt to solve the JuMP model using each solver in opt.opt.slv in order.

Tries each solver sequentially, checking feasibility and finite non-zero weights. Returns a (retcode, solution) tuple where retcode is OptimisationSuccess or OptimisationFailure and solution is a JuMPOptimisationSolution.

Related

source
PortfolioOptimisers.set_model_scales! Function
julia
set_model_scales!(model::JuMP.Model, so::Number, sc::Number)

Register objective scale so and constraint scale sc as named expressions in the JuMP model.

Arguments

  • model::JuMP.Model: JuMP optimisation model.

  • so::Number: Objective scale factor.

  • sc::Number: Constraint scale factor.

Returns

  • nothing.

Related

source
PortfolioOptimisers.set_initial_w! Function
julia
set_initial_w!(args...)
set_initial_w!(w::VecNum, wi::VecNum)

Set initial (warm-start) values for portfolio weight variables in the JuMP model.

The no-op fallback does nothing when wi is not provided. The two-argument method sets JuMP start values for each weight variable.

Arguments

  • w::VecNum: Vector of JuMP weight variables.

  • wi::VecNum: Vector of initial weight values.

Returns

  • nothing.

Related

source
PortfolioOptimisers.set_w! Function
julia
set_w!(model::JuMP.Model, X::MatNum, wi::Option{<:VecNum_VecVecNum})

Create portfolio weight variables in the JuMP model and optionally set initial values.

Registers a vector of weight variables w of length size(X, 2) in the model. If wi is provided, sets the initial values via set_initial_w!.

Arguments

  • model::JuMP.Model: JuMP optimisation model.

  • X::MatNum: Asset returns matrix (shape: observations × assets).

  • wi: Optional initial weight values.

Returns

  • nothing.

Related

source
PortfolioOptimisers.set_portfolio_returns! Function
julia
set_portfolio_returns!(model::JuMP.Model, X::MatNum)

Compute and register portfolio returns expression X * w in the JuMP model.

If the expression already exists in the model, returns it directly (idempotent).

Arguments

  • model::JuMP.Model: JuMP optimisation model.

  • X::MatNum: Asset returns matrix.

Returns

  • The portfolio returns expression.

Related

source
PortfolioOptimisers.set_net_portfolio_returns! Function
julia
set_net_portfolio_returns!(model::JuMP.Model, X::MatNum)

Compute and register net portfolio returns (after fees) in the JuMP model.

Calls set_portfolio_returns! and subtracts fees if present.

Arguments

  • model::JuMP.Model: JuMP optimisation model.

  • X::MatNum: Asset returns matrix.

Returns

  • The net portfolio returns expression.

Related

source
PortfolioOptimisers.set_asset_returns_plus_one! Function
julia
set_asset_returns_plus_one!(model::JuMP.Model, X::MatNum)

Compute and register portfolio asset gross returns X .+ 1 in the JuMP model.

Used in drawdown and logarithmic return computations.

Arguments

  • model::JuMP.Model: JuMP optimisation model.

  • X::MatNum: Asset returns expression.

Returns

  • The gross asset returns expression X .+ 1.

Related

source
PortfolioOptimisers.set_asset_neg_returns_plus_one! Function
julia
set_asset_neg_returns_plus_one!(model::JuMP.Model, X::MatNum)

Compute and register negative asset gross returns -X .+ 1 in the JuMP model.

Used in drawdown and logarithmic return computations.

Arguments

  • model::JuMP.Model: JuMP optimisation model.

  • X::MatNum: Asset returns expression.

Returns

  • The negative gross asset returns expression -X .+ 1.

Related

source
PortfolioOptimisers.set_portfolio_drawdowns_plus_one! Function
julia
set_portfolio_drawdowns_plus_one!(model::JuMP.Model, X::MatNum)

Compute and register absolute drawdowns plus one in the JuMP model.

Computes absolute_drawdown_arr(X) .+ 1 and registers it in the model.

Arguments

  • model::JuMP.Model: JuMP optimisation model.

  • X::MatNum: Portfolio returns expression.

Returns

  • The drawdowns-plus-one expression.

Related

source
PortfolioOptimisers.set_risk_constraints! Function
julia
set_risk_constraints!(model, r, X, T, ...) -> nothing

Set risk constraints in the JuMP model for a given risk measure.

Generic function stub; concrete methods are defined in constraint and risk measure files. Each method configures the appropriate risk constraint expressions for a given risk measure type r.

Related

source
PortfolioOptimisers.get_constraint_scale Function
julia
get_constraint_scale(model::JuMP.Model)

Return the constraint scale expression model[:sc].

Asserts the scale has been registered (via set_model_scales!); errors otherwise.

Related

source
PortfolioOptimisers.has_Xap1 Function
julia
has_Xap1(model::JuMP.Model, prefix::Symbol = Symbol(""))

Return true if the gross portfolio returns model[Symbol(prefix, :Xap1)] have been registered (via set_asset_returns_plus_one!).

Related

source
PortfolioOptimisers.get_ret Function
julia
get_ret(model::JuMP.Model)

Return the portfolio expected-return expression model[:ret].

Asserts the return expression has been registered; errors otherwise.

Related

source
PortfolioOptimisers.get_net_X Function
julia
get_net_X(model::JuMP.Model, prefix::Symbol = Symbol(""))

Return the net portfolio returns expression model[Symbol(prefix, :net_X)].

Asserts it has been registered (via set_net_portfolio_returns!); errors otherwise.

Related

source
PortfolioOptimisers.get_ddap1 Function
julia
get_ddap1(model::JuMP.Model, prefix::Symbol = Symbol(""))

Return the drawdowns-plus-one expression model[Symbol(prefix, :ddap1)].

Asserts it has been registered (via set_portfolio_drawdowns_plus_one!); errors otherwise.

Related

source
PortfolioOptimisers.get_w Function
julia
get_w(model::JuMP.Model)

Return the portfolio weight variables model[:w].

Asserts the weights have been registered (via set_w!); errors otherwise.

Related

source
PortfolioOptimisers.get_objective_scale Function
julia
get_objective_scale(model::JuMP.Model)

Return the objective scale expression model[:so].

Asserts the scale has been registered (via set_model_scales!); errors otherwise.

Related

source
PortfolioOptimisers.get_k Function
julia
get_k(model::JuMP.Model)

Return the homogenisation variable model[:k].

k >= 0 is the auxiliary scaling variable used to homogenise fractional/ratio objectives (e.g. maximum ratio); recovered weights are w / k. Asserts :k has been registered; errors otherwise.

Related

source
PortfolioOptimisers.set_unit_budget! Function
julia
set_unit_budget!(model::JuMP.Model)

Record that the head normalised the model's budget scale to unit.

A head declares this when its own constraints make the formulation scale-invariant, so downstream builders may substitute the literal 1 for the homogenisation variable k. RiskBudgeting is the only such head: its log-barrier normalisation pins the scale, and the weights are renormalised after the solve. Note that k remains a free variable under this declaration — it is the budget scale that is unit, not k that is constant.

Related

source
PortfolioOptimisers.is_unit_budget Function
julia
is_unit_budget(model::JuMP.Model)

Return whether the head normalised the budget scale to unit (see set_unit_budget!).

Related

source
PortfolioOptimisers.effective_k Function
julia
effective_k(model::JuMP.Model)

Return the budget scale a builder should use: 1 under a unit budget, else model[:k].

Builders that multiply a bound by the budget want this rather than get_k, so a scale-invariant head is honoured without each builder re-deriving that fact for itself.

Related

source
PortfolioOptimisers.AbstractDecompositionContract Type
julia
abstract type AbstractDecompositionContract

Abstract supertype for the head's decomposition contract: how model[:w] relates to the long/short parts model[:lw] and model[:sw].

Heads build that relationship in one of two incompatible ways, and a builder that pins the decomposition needs to know which, because the two need different constraints to become exact. The head declares its own with set_decomposition_contract!; builders read it back with decomposition_contract and dispatch.

Related

source
PortfolioOptimisers.WeightsFromParts Type
julia
struct WeightsFromParts <: AbstractDecompositionContract

The head defines the weights from the parts: w = lw - sw is an identity, lw and sw being the primitive variables. Declared by set_rb_mip_w!.

Because the identity always holds, forcing the long-xor-short sign pattern is enough to pin the decomposition: with sw = 0 the identity leaves lw == w, and lw >= 0 makes that max(w, 0). No slack remains to close.

Related

source
PortfolioOptimisers.PartsBoundWeights Type
julia
struct PartsBoundWeights <: AbstractDecompositionContract

The head defines the parts as bounds on the weights: lw >= w, sw >= -w, lw, sw >= 0, w being the primitive variable. Declared by set_weight_constraints!.

The parts are only upper bounds on the true long/short exposures, so every budget built on them (bgt, sbgt, gbgt) bounds the realised exposure rather than pinning it. Forcing the sign pattern does not change that — the slack survives it — so pinning the decomposition under this contract needs two further constraints to close it.

Related

source
PortfolioOptimisers.set_decomposition_contract! Function
julia
set_decomposition_contract!(model::JuMP.Model, dc::AbstractDecompositionContract)

Record how the head related model[:w] to model[:lw]/model[:sw].

The first declaration wins: a head may run both builders (the mixed-integer RiskBudgeting head calls set_rb_mip_w!, then hands the same lw/sw to set_weight_constraints!, which re-states them as bounds). The identity is the stronger statement and still holds, so the bounds must not overwrite it.

Related

source
PortfolioOptimisers.decomposition_contract Function
julia
decomposition_contract(model::JuMP.Model)

Return the head's decomposition contract, or nothing when no head declared one.

nothing means the model has no short side — the weights are their own long part, lw is an alias for w and there is no sw, so there is no decomposition to pin.

Related

source
PortfolioOptimisers.get_Xap1 Function
julia
get_Xap1(model::JuMP.Model, prefix::Symbol = Symbol(""))

Return the gross portfolio returns expression model[Symbol(prefix, :Xap1)] (X .+ 1).

Asserts it has been registered (via set_asset_returns_plus_one!); errors otherwise.

Related

source
PortfolioOptimisers.has_ddap1 Function
julia
has_ddap1(model::JuMP.Model, prefix::Symbol = Symbol(""))

Return true if the drawdowns-plus-one model[Symbol(prefix, :ddap1)] have been registered (via set_portfolio_drawdowns_plus_one!).

Related

source
PortfolioOptimisers.has_net_X Function
julia
has_net_X(model::JuMP.Model, prefix::Symbol = Symbol(""))

Return true if the net portfolio returns model[Symbol(prefix, :net_X)] have been registered (via set_net_portfolio_returns!).

Related

source
PortfolioOptimisers.get_X Function
julia
get_X(model::JuMP.Model, prefix::Symbol = Symbol(""))

Return the portfolio returns expression model[Symbol(prefix, :X)].

Asserts it has been registered (via set_portfolio_returns!); errors otherwise.

Related

source
PortfolioOptimisers.get_risk Function
julia
get_risk(model::JuMP.Model)

Return the scalarised portfolio risk expression model[:risk].

Asserts the risk expression has been registered (via scalarise_risk_expression!); errors otherwise.

Related

source
PortfolioOptimisers.get_dd Function
julia
get_dd(model::JuMP.Model, prefix::Symbol = Symbol(""))

Return the cumulative-drawdown variables model[Symbol(prefix, :dd)].

Asserts they have been registered (via set_drawdown_constraints!); errors otherwise.

Related

source
PortfolioOptimisers.has_X Function
julia
has_X(model::JuMP.Model, prefix::Symbol = Symbol(""))

Return true if the portfolio returns model[Symbol(prefix, :X)] have been registered (via set_portfolio_returns!).

Related

source
PortfolioOptimisers.has_dd Function
julia
has_dd(model::JuMP.Model, prefix::Symbol = Symbol(""))

Return true if the cumulative-drawdown variables model[Symbol(prefix, :dd)] have been registered (via set_drawdown_constraints!).

Related

source
PortfolioOptimisers.SHARED_STATE Constant
julia
SHARED_STATE

The Model State entries deliberately shared bare across a nested risk build.

The complement of Per-Build Risk State: an entry belongs here iff it is not a function of the weights being optimised and not a build-scoped presence flag, so the inner and outer builds want the same object and prefixing it would break sharing rather than protect it (ADR 0005). shared_get and friends validate against this set, so the classification is enforced at run time rather than only by the seam-lock test (ADR 0037).

Each grouping records why those entries are shared. Adding a name here is a claim that a nested build may safely see the enclosing build's copy — check that claim before adding.

source
PortfolioOptimisers.assert_shared_state Function
julia
assert_shared_state(name::Symbol)

Assert name is a sanctioned bare Model State entry.

Guards the shared_get family so that reaching for a per-build entry without a prefix fails loudly at the call site, rather than silently aliasing the enclosing build's copy — the regression class that broke IndependentVariableTracking.

source
PortfolioOptimisers.shared_set! Function
julia
shared_set!(model::JuMP.Model, name::Symbol, val)

Register val as the sanctioned bare Model State entry name and return it.

The unprefixed counterpart of state_set!, for entries on SHARED_STATE.

Related

source
PortfolioOptimisers.shared_has Function
julia
shared_has(model::JuMP.Model, name::Symbol)

Return true if the sanctioned bare Model State entry name is registered.

source
PortfolioOptimisers.shared_get Function
julia
shared_get(model::JuMP.Model, name::Symbol)

Return the sanctioned bare Model State entry name, asserting it has been registered.

The unprefixed counterpart of state_get. Prefer a named accessor (get_w, get_k, get_ret, …) where one exists.

Related

source
PortfolioOptimisers.state_key Function
julia
state_key(prefix::Symbol, name::Symbol)

Resolve the Model State key for entry name under prefix.

Internal to the Model State interface: the single place the prefix-namespacing convention is spelled. Keeping it here is what lets the seam-lock test assert that no emitter builds a key by hand — emitters reach Model State through state_get, state_has, state_set! and state_build!. See ADR 0037.

Related

source
PortfolioOptimisers.state_set! Function
julia
state_set!(model::JuMP.Model, prefix::Symbol, name::Symbol, val)

Register val in the model under the prefixed Model State key and return it.

A nested risk build (e.g. risk tracking) passes a non-empty prefix so the shared infrastructure entries it creates (:X, :net_X, :W, :dd, …) do not collide with the outer model's; the default empty prefix reproduces the bare key. See ADR 0005.

Related

source
PortfolioOptimisers.state_has Function
julia
state_has(model::JuMP.Model, prefix::Symbol, name::Symbol)

Return true if Model State entry name is registered under prefix.

Related

source
PortfolioOptimisers.state_get Function
julia
state_get(model::JuMP.Model, prefix::Symbol, name::Symbol)

Return Model State entry name under prefix, asserting it has been registered.

Prefer a named accessor (get_X, get_net_X, get_dd, …) where one exists: those name the builder that produces the entry, so an out-of-order read reports which builder to call instead of a generic missing-entry error.

Related

source
PortfolioOptimisers.state_build! Function
julia
state_build!(f, model::JuMP.Model, prefix::Symbol, name::Symbol)

Return Model State entry name under prefix, building it with f() exactly once.

The memoise-on-prefixed-key idiom shared by every risk and constraint emitter: if the entry is already registered — an earlier measure in the same build produced it, or an outer build already did — it is returned untouched; otherwise f() runs and its value is registered under the prefixed key. Companion entries created inside f register with state_set!.

Because the key is resolved here rather than at the call site, a Model State entry added in future participates in the prefix discipline with no further work. That is what closes the residual hole ADR 0004 §2 accepted; see ADR 0037.

Related

source
PortfolioOptimisers.mark_state! Function
julia
mark_state!(model::JuMP.Model, prefix::Symbol, name::Symbol)

Record that this build has name present, idempotently.

A build-scoped presence flag: name carries no value beyond its own existence, and readers test it with state_has rather than reading it. Marking under prefix is what keeps a nested build's flags out of the enclosing build — the second half of Per-Build Risk State (ADR 0005), the half that is not weight-dependent.

Related

source
PortfolioOptimisers.nested_prefix Function
julia
nested_prefix(prefix::Symbol, tag::Symbol)
nested_prefix(prefix::Symbol, tag::Symbol, i)

Compose the Model State namespace a nested build threads down its own spine.

Distinct from a Model State key: this produces a prefix, not an entry name, so a nested build's entries cannot alias the enclosing build's. tag names the nesting kind (:tr_iv_, :tr_dv_, :te_ir_, :te_dr_, :gain_) and the optional i disambiguates the measure index, which is what makes tracking-nested-in-tracking collision-free. See ADR 0005.

Related

source