Base JuMP Optimisation
PortfolioOptimisers.BaseJuMPOptimisationEstimator Type
abstract type BaseJuMPOptimisationEstimator <: BaseOptimisationEstimatorAbstract 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
sourcePortfolioOptimisers.JuMPOptimisationEstimator Type
abstract type JuMPOptimisationEstimator <: NonFiniteAllocationOptimisationEstimatorAbstract supertype for JuMP-based portfolio optimisation estimators.
JuMP optimisers formulate and solve portfolio optimisation problems using mathematical programming via the JuMP.jl framework.
Related
sourcePortfolioOptimisers.RiskJuMPOptimisationEstimator Type
abstract type RiskJuMPOptimisationEstimator <: JuMPOptimisationEstimatorAbstract supertype for risk-based JuMP portfolio optimisation estimators.
Subtype RiskJuMPOptimisationEstimator to implement optimisers that minimise or constrain risk measures as the primary objective.
Related
sourcePortfolioOptimisers.ObjectiveFunction Type
abstract type ObjectiveFunction <: AbstractEstimatorAbstract supertype for portfolio objective functions.
Subtype ObjectiveFunction to implement portfolio optimisation objectives such as minimum risk, maximum return, or maximum Sharpe ratio.
Related
sourcePortfolioOptimisers.JuMPReturnsEstimator Type
abstract type JuMPReturnsEstimator <: AbstractEstimatorAbstract supertype for JuMP-based returns estimators used in optimisation models.
JuMPReturnsEstimator types define how expected returns are incorporated into JuMP models.
Related
sourcePortfolioOptimisers.JuMPConstraintEstimator Type
abstract type JuMPConstraintEstimator <: AbstractConstraintEstimatorAbstract 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:
CustomJuMPConstraint⇒ implementadd_custom_constraint!, supply viaJuMPOptimiser'sccnt.CustomJuMPObjective⇒ implementadd_custom_objective_term!, supply viaJuMPOptimiser'scobj.
(The objective child subtypes AbstractEstimator directly — it is grouped here as the sibling extension point, not by type hierarchy.)
Related
sourcePortfolioOptimisers.CustomJuMPConstraint Type
abstract type CustomJuMPConstraint <: JuMPConstraintEstimatorAbstract 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
add_custom_constraint!— the method to implementCustomJuMPObjective/add_custom_objective_term!— the objective-side analogueJuMPOptimiser— itsccntfield is where a custom constraint is supplied
PortfolioOptimisers.VecJuMPConstr Type
const VecJuMPConstr = AbstractVector{<:CustomJuMPConstraint}Alias for a vector of JuMP constraint estimators.
Related
sourcePortfolioOptimisers.JuMPConstr_VecJuMPConstr Type
const JuMPConstr_VecJuMPConstr = Union{<:CustomJuMPConstraint, <:VecJuMPConstr}Alias for a single JuMP constraint estimator or a vector of them.
Related
sourcePortfolioOptimisers.CustomJuMPObjective Type
abstract type CustomJuMPObjective <: AbstractEstimatorAbstract 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
add_custom_objective_term!— the method to implementCustomJuMPConstraint/add_custom_constraint!— the constraint-side analogueJuMPOptimiser— itscobjfield is where a custom objective is supplied
PortfolioOptimisers.VecJuMPObj Type
const VecJuMPObj = AbstractVector{<:CustomJuMPObjective}Alias for a vector of JuMP objective estimators.
Related
sourcePortfolioOptimisers.JuMPObj_VecJuMPObj Type
const JuMPObj_VecJuMPObj = Union{<:CustomJuMPObjective, <:VecJuMPObj}Alias for a single JuMP objective estimator or a vector of them.
Related
sourcePortfolioOptimisers.needs_previous_weights Method
needs_previous_weights(_::CustomJuMPConstraint) -> BoolReturn false: custom JuMP constraints never require previous portfolio weights.
PortfolioOptimisers.needs_previous_weights Method
needs_previous_weights(_::CustomJuMPObjective) -> BoolReturn false: custom JuMP objectives never require previous portfolio weights.
PortfolioOptimisers.is_time_dependent Method
is_time_dependent(opt::JuMPOptimisationEstimator) -> AnyReturn true if the estimator's own problem-definition fields, the inner JuMP optimiser, or the fallback carry time-dependent constraints.
PortfolioOptimisers.reset_time_dependent_estimator Method
reset_time_dependent_estimator(
opt::JuMPOptimisationEstimator
) -> AnyReplace time-dependent constraints with their static defaults, both on the estimator's own fields and by recursing into the inner JuMP optimiser and fallback.
sourcePortfolioOptimisers.JuMPOptimisationSolution Type
struct JuMPOptimisationSolution{__T_w} <: OptimisationModelResultStores the solution (portfolio weights) from a JuMP optimisation model.
Fields
w: Portfolio weights vectorassets × 1.
Constructors
JuMPOptimisationSolution(; w::ArrNum) -> JuMPOptimisationSolutionKeywords correspond to the struct's fields.
Validation
!isempty(w).
Related
sourcePortfolioOptimisers.VecJuMPOptSol Type
const VecJuMPOptSol = AbstractVector{<:JuMPOptimisationSolution}Alias for a vector of JuMP optimisation solutions.
Related
sourcePortfolioOptimisers.JuMPOptSol_VecJuMPOptSol Type
const JuMPOptSol_VecJuMPOptSol = Union{<:JuMPOptimisationSolution, <:VecJuMPOptSol}Alias for a single JuMP optimisation solution or a vector of them.
Related
sourcePortfolioOptimisers.BaseJuMPOptimisationResult Type
abstract type BaseJuMPOptimisationResult <: AbstractResultAbstract 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
sourcePortfolioOptimisers.RiskJuMPOptimisationResult Type
abstract type RiskJuMPOptimisationResult <: NonFiniteAllocationOptimisationResultAbstract 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
sourceBase.propertynames Method
propertynames(r::RiskJuMPOptimisationResult) -> TupleDefault 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.
Base.getproperty Method
getproperty(
r::RiskJuMPOptimisationResult,
sym::Symbol
) -> AnyDefault property access for RiskJuMPOptimisationResult: unique fields resolve directly; everything else delegates to the embedded JuMPOptimisationResult jr.
PortfolioOptimisers.NonJuMPOptimisationResult Type
abstract type NonJuMPOptimisationResult <: NonFiniteAllocationOptimisationResultAbstract 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
PortfolioOptimisers.add_custom_objective_term! Function
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: TheObjectiveFunctionbeing built. During aFrontiersweep this differs from the objective the user declared — the endpoint sub-problems are built asMinimumRiskandMaximumReturn.cobj: The custom objective estimator; the argument to dispatch on.optimiser: The outer optimisation estimator (e.g. theMeanRiskitself); itsoptfield is theJuMPOptimiser.attrs::ProcessedJuMPOptimiserAttributes: Processed problem data —attrs.pr(prior),attrs.ret(returns estimator),attrs.wb(bounds), and the rest.
Returns
nothing.
Related
add_to_objective_penalty!— how to contribute a termadd_custom_constraint!— the constraint-side analogue
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
sourcePortfolioOptimisers.add_custom_constraint! Function
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. theMeanRiskitself).attrs::ProcessedJuMPOptimiserAttributes: Processed problem data.
Returns
nothing.
Related
add_custom_objective_term!— the objective-side analogue
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
sourcePortfolioOptimisers.process_model Function
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
model: Optimised JuMP model.retcode: Optimisation return code (OptimisationSuccessorOptimisationFailure).
Returns
- Solution object.
Related
sourcePortfolioOptimisers.optimise_JuMP_model! Function
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: SingleSolveror vector ofSolverobjects.
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
sourceoptimise_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
sourcePortfolioOptimisers.set_model_scales! Function
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
sourcePortfolioOptimisers.set_initial_w! Function
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
sourcePortfolioOptimisers.set_w! Function
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
sourcePortfolioOptimisers.set_portfolio_returns! Function
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
sourcePortfolioOptimisers.set_net_portfolio_returns! Function
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
sourcePortfolioOptimisers.set_asset_returns_plus_one! Function
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
sourcePortfolioOptimisers.set_asset_neg_returns_plus_one! Function
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
sourcePortfolioOptimisers.set_portfolio_drawdowns_plus_one! Function
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
sourcePortfolioOptimisers.set_risk_constraints! Function
set_risk_constraints!(model, r, X, T, ...) -> nothingSet 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
sourcePortfolioOptimisers.get_constraint_scale Function
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
sourcePortfolioOptimisers.has_Xap1 Function
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
sourcePortfolioOptimisers.get_ret Function
get_ret(model::JuMP.Model)Return the portfolio expected-return expression model[:ret].
Asserts the return expression has been registered; errors otherwise.
Related
sourcePortfolioOptimisers.get_net_X Function
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
sourcePortfolioOptimisers.get_ddap1 Function
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
sourcePortfolioOptimisers.get_w Function
get_w(model::JuMP.Model)Return the portfolio weight variables model[:w].
Asserts the weights have been registered (via set_w!); errors otherwise.
Related
sourcePortfolioOptimisers.get_objective_scale Function
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
sourcePortfolioOptimisers.get_k Function
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
sourcePortfolioOptimisers.set_unit_budget! Function
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
sourcePortfolioOptimisers.is_unit_budget Function
is_unit_budget(model::JuMP.Model)Return whether the head normalised the budget scale to unit (see set_unit_budget!).
Related
sourcePortfolioOptimisers.effective_k Function
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
sourcePortfolioOptimisers.AbstractDecompositionContract Type
abstract type AbstractDecompositionContractAbstract 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
sourcePortfolioOptimisers.WeightsFromParts Type
struct WeightsFromParts <: AbstractDecompositionContractThe 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
sourcePortfolioOptimisers.PartsBoundWeights Type
struct PartsBoundWeights <: AbstractDecompositionContractThe 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
sourcePortfolioOptimisers.set_decomposition_contract! Function
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
sourcePortfolioOptimisers.decomposition_contract Function
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
sourcePortfolioOptimisers.get_Xap1 Function
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
sourcePortfolioOptimisers.has_ddap1 Function
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
sourcePortfolioOptimisers.has_net_X Function
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
sourcePortfolioOptimisers.get_X Function
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
sourcePortfolioOptimisers.get_risk Function
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
sourcePortfolioOptimisers.get_dd Function
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
sourcePortfolioOptimisers.has_X Function
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
sourcePortfolioOptimisers.has_dd Function
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
sourcePortfolioOptimisers.SHARED_STATE Constant
SHARED_STATEThe 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.
sourcePortfolioOptimisers.assert_shared_state Function
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.
PortfolioOptimisers.shared_set! Function
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
sourcePortfolioOptimisers.shared_has Function
shared_has(model::JuMP.Model, name::Symbol)Return true if the sanctioned bare Model State entry name is registered.
PortfolioOptimisers.shared_get Function
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
sourcePortfolioOptimisers.state_key Function
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
sourcePortfolioOptimisers.state_set! Function
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
sourcePortfolioOptimisers.state_has Function
state_has(model::JuMP.Model, prefix::Symbol, name::Symbol)Return true if Model State entry name is registered under prefix.
Related
sourcePortfolioOptimisers.state_get Function
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
sourcePortfolioOptimisers.state_build! Function
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
sourcePortfolioOptimisers.mark_state! Function
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
sourcePortfolioOptimisers.nested_prefix Function
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