Skip to content
13

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.

Subtype JuMPConstraintEstimator to implement custom constraints or objectives for JuMP-based portfolio optimisers.

Related

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

Abstract supertype for custom JuMP constraint implementations.

Implement add_custom_constraint! to define custom JuMP model constraints.

Related

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

Abstract supertype for custom JuMP objective implementations.

Implement add_custom_objective_term! to add custom terms to the JuMP model objective.

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.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.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.JuMPOptimisationResult Type
julia
struct JuMPOptimisationResult{__T_oe, __T_pa, __T_retcode, __T_sol, __T_model} <: BaseJuMPOptimisationResult

Shared field core for JuMP-based optimisation results.

Holds the fields common to every JuMP optimisation result. Embedded as the first field (jr) of each concrete JuMP result, analogous to how JuMPOptimiser is embedded as opt in each JuMP optimiser. The concrete result keeps only its unique fields plus the trailing fb.

Fields

  • oe: Type of the optimisation estimator that produced this result.

  • pa: Processed optimisation attributes.

  • retcode: Optimisation return code.

  • sol: Optimisation solution.

  • model: :JuMP.Model`: The JuMP optimisation model.

Related

source
Base.getproperty Method
julia
getproperty(jr::JuMPOptimisationResult, sym::Symbol) -> Any

Access properties of JuMPOptimisationResult. Virtual property :w extracts portfolio weights from sol; unknown properties forward to pa.

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.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!(args...; kwargs...)

Add a custom objective term to the JuMP model.

No-op fallback. Override this method for subtypes of CustomJuMPObjective to add custom penalty or reward terms to the JuMP model objective.

Arguments

  • args...: JuMP model and custom objective type (ignored in fallback).

  • kwargs...: Additional keyword arguments.

Returns

  • nothing.

Related

source
PortfolioOptimisers.add_custom_constraint! Function
julia
add_custom_constraint!(args...; kwargs...)

Add a custom constraint to the JuMP model.

No-op fallback. Override this method for subtypes of CustomJuMPConstraint to add custom constraints to the JuMP model.

Arguments

  • args...: JuMP model and custom constraint type (ignored in fallback).

  • kwargs...: Additional keyword arguments.

Returns

  • nothing.

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"#s21", N}} where {var"#s21"<:(Union{var"#s20", var"#s19"} where {var"#s20"<:Number, var"#s19"<:AbstractJuMPScalar}), N}}
optimise_JuMP_model!(
    model::Model,
    opt::JuMPOptimisationEstimator,
    datatype::DataType
) -> Tuple{Union{OptimisationFailure{Dict{Any, Any}}, OptimisationSuccess{Dict{Any, Any}}}, JuMPOptimisationSolution{<:AbstractArray{var"#s21", N}} where {var"#s21"<:(Union{var"#s20", var"#s19"} where {var"#s20"<:Number, var"#s19"<: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_portfolio_returns_plus_one! Function
julia
set_portfolio_returns_plus_one!(model::JuMP.Model, X::MatNum)

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

Used in drawdown and logarithmic return computations.

Arguments

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

  • X::MatNum: Portfolio returns expression.

Returns

  • The gross 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_portfolio_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.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_portfolio_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.preg! Function
julia
preg!(model::JuMP.Model, prefix::Symbol, name::Symbol, val)

Register val in the model under the prefixed key Symbol(prefix, name) and return it.

The single place the model-state namespacing convention lives: a nested risk build (e.g. risk tracking) passes a non-empty prefix so the shared infrastructure keys it creates (:X, :net_X, :W, :dd, …) do not collide with the outer model's; the default empty prefix reproduces the bare key. Pairs with the prefixed read accessors. See ADR 0004.

Related

source