Skip to content
13

Base optimisation

PortfolioOptimisers.AbstractOptimisationEstimator Type
julia
abstract type AbstractOptimisationEstimator <: AbstractEstimator

Abstract supertype for all portfolio optimisation estimators in PortfolioOptimisers.jl.

All optimisers and optimisation components should subtype AbstractOptimisationEstimator to participate in the optimisation dispatch system.

Related

source
PortfolioOptimisers.BaseOptimisationEstimator Type
julia
abstract type BaseOptimisationEstimator <: AbstractOptimisationEstimator

Abstract supertype for base portfolio optimisation estimators.

BaseOptimisationEstimator is the parent for all internal optimiser components that configure the optimisation problem but are not directly invokable as top-level optimisers.

Related Types

source
PortfolioOptimisers.OptimisationEstimator Type
julia
abstract type OptimisationEstimator <: AbstractOptimisationEstimator

Abstract supertype for portfolio optimisation estimators that produce portfolio weights.

Subtype OptimisationEstimator to implement concrete portfolio optimisers. All optimisers that can be invoked with optimise should subtype this.

Related Types

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

Abstract supertype for portfolio optimisation estimators that produce continuous (non-integer) portfolio weights.

Related Types

source
PortfolioOptimisers.OptimisationAlgorithm Type
julia
abstract type OptimisationAlgorithm <: AbstractAlgorithm

Abstract supertype for optimisation algorithms used by portfolio optimisers.

Related Types

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

Abstract supertype for portfolio optimisation result types.

All concrete optimisation result types should subtype OptimisationResult.

Related Types

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

Abstract supertype for continuous (non-integer allocation) optimisation results.

Related Types

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

Abstract supertype for optimisation return codes.

Concrete subtypes indicate whether an optimisation succeeded or failed.

Related Types

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

Abstract supertype for intermediate optimisation model results.

Related Types

source
PortfolioOptimisers.OptimisationSuccess Type
julia
struct OptimisationSuccess{__T_res} <: OptimisationReturnCode

Indicates that a portfolio optimisation completed successfully.

Fields

  • res: Optional result or message from the solver (default: nothing).

Related

source
PortfolioOptimisers.OptimisationFailure Type
julia
struct OptimisationFailure{__T_res} <: OptimisationReturnCode

Indicates that a portfolio optimisation failed.

Fields

  • res: Optional error message or diagnostic information (default: nothing).

Related

source
PortfolioOptimisers.JuMPWeightFinaliserFormulation Type
julia
abstract type JuMPWeightFinaliserFormulation <: AbstractAlgorithm

Abstract supertype for JuMP-based weight finaliser formulations.

Defines the interface for norm types used when adjusting portfolio weights to satisfy bounds via a JuMP model.

Related Types

source
PortfolioOptimisers.RelativeErrorWeightFinaliser Type
julia
struct RelativeErrorWeightFinaliser <: JuMPWeightFinaliserFormulation

Minimises the L1 norm of relative weight deviations when enforcing weight bounds.

source
PortfolioOptimisers.SquaredRelativeErrorWeightFinaliser Type
julia
struct SquaredRelativeErrorWeightFinaliser <: JuMPWeightFinaliserFormulation

Minimises the L2 norm (squared) of relative weight deviations when enforcing weight bounds.

source
PortfolioOptimisers.AbsoluteErrorWeightFinaliser Type
julia
struct AbsoluteErrorWeightFinaliser <: JuMPWeightFinaliserFormulation

Minimises the L1 norm of absolute weight deviations when enforcing weight bounds.

source
PortfolioOptimisers.SquaredAbsoluteErrorWeightFinaliser Type
julia
struct SquaredAbsoluteErrorWeightFinaliser <: JuMPWeightFinaliserFormulation

Minimises the L2 norm (squared) of absolute weight deviations when enforcing weight bounds.

source
PortfolioOptimisers.WeightFinaliser Type
julia
abstract type WeightFinaliser <: AbstractAlgorithm

Abstract supertype for weight finaliser strategies.

A WeightFinaliser enforces weight bounds after the optimisation has produced unconstrained weights.

Related Types

source
PortfolioOptimisers.IterativeWeightFinaliser Type
julia
struct IterativeWeightFinaliser{__T_iter} <: WeightFinaliser

Iteratively projects weights into the feasible region defined by weight bounds.

IterativeWeightFinaliser repeatedly clips and redistributes portfolio weights until they satisfy the given lower and upper bounds, or the maximum number of iterations iter is reached.

Fields

  • iter: Maximum number of iterations.

Constructors

julia
IterativeWeightFinaliser(;
    iter::Integer = 100
) -> IterativeWeightFinaliser

Keywords correspond to the struct's fields.

Validation

  • iter > 0.

Examples

julia
julia> IterativeWeightFinaliser()
IterativeWeightFinaliser
  iter ┴ Int64: 100

Related

source
PortfolioOptimisers.JuMPWeightFinaliser Type
julia
struct JuMPWeightFinaliser{__T_slv, __T_sc, __T_so, __T_alg} <: WeightFinaliser

Uses a JuMP optimisation model to enforce weight bounds.

JuMPWeightFinaliser solves a small optimisation problem to find the closest feasible weights (in the sense of the chosen error formulation) that satisfy the given bounds. Falls back to IterativeWeightFinaliser if the JuMP model fails.

Fields

  • slv: Solver or vector of solvers for the JuMP model.

  • sc: Scale factor applied to constraints.

  • so: Scale factor applied to the objective.

  • alg: Error formulation (L1/L2 relative or absolute).

Constructors

julia
JuMPWeightFinaliser(;
    slv::Slv_VecSlv,
    sc::Number = 1.0,
    so::Number = 1.0,
    alg::JuMPWeightFinaliserFormulation = RelativeErrorWeightFinaliser()
) -> JuMPWeightFinaliser

Keywords correspond to the struct's fields.

Validation

  • If slv is a VecSlv: !isempty(slv).

  • sc > 0, so > 0.

Related

source
PortfolioOptimisers._optimise Function
julia
_optimise(opt, rd, args...; dims, str_names, save, kwargs...)

Internal dispatch function for portfolio optimisation.

Called by optimise to perform the actual optimisation. Each optimisation estimator type implements its own overload. Returns the estimator-specific result type.

Arguments

  • opt: Optimisation estimator (e.g. MeanRisk, RiskBudgeting, etc.).

  • rd::ReturnsResult: Returns data.

  • dims::Int: Observation dimension.

  • str_names::Bool: Whether to use string names in the JuMP model.

  • save::Bool: Whether to save the JuMP model in the result.

  • kwargs...: Additional keyword arguments.

Returns

  • Estimator-specific optimisation result.

Related

source
PortfolioOptimisers.optimise Method
julia
optimise(opt::OptimisationEstimator, args...; kwargs...) -> OptimisationResult
optimise(opt::OptimisationResult, args...; kwargs...) -> OptimisationResult

Run portfolio optimisation using the given estimator opt and return an OptimisationResult.

If opt returns an OptimisationFailure, the fallback estimator is tried automatically until either a successful result is obtained or all fallbacks are exhausted.

Passing an OptimisationResult directly returns it unchanged (pass-through method).

Arguments

  • opt: Optimisation estimator (e.g. a JuMPOptimisationEstimator subtype).

  • args: Additional positional arguments (ignored).

  • kwargs: Additional keyword arguments (ignored).

Returns

Related

source
PortfolioOptimisers.optimise Method
julia
optimise(
    opt::OptimisationEstimator,
    args...;
    kwargs...
) -> RiskBudgetingResult{__T_oe, __T_pa, __T_prb, __T_retcode, __T_sol, __T_model, Nothing} where {__T_oe<:Union{Type{RelaxedRiskBudgeting{var"#s2376", var"#s2375", var"#s2371", var"#s2370", Nothing}} where {var"#s2376", var"#s2375"<:FactorRiskBudgeting, var"#s2371", var"#s2370"}, Type{RelaxedRiskBudgeting{var"#s2376", var"#s2375", var"#s2371", var"#s2370", Nothing}} where {var"#s2376", var"#s2375"<:AssetRiskBudgeting, var"#s2371", var"#s2370"}}, __T_pa<:ProcessedJuMPOptimiserAttributes, __T_prb<:Union{ProcessedAssetRiskBudgetingAttributes, ProcessedFactorRiskBudgetingAttributes{_A, _B, __T_rr} where {_A, _B, __T_rr<:Regression}}, __T_retcode<:Union{OptimisationFailure{Dict{Any, Any}}, OptimisationSuccess{Dict{Any, Any}}}, __T_sol<:(JuMPOptimisationSolution{<:AbstractArray{var"#s20", N}} where {var"#s20"<:(Union{var"#s19", var"#s18"} where {var"#s19"<:Number, var"#s18"<:AbstractJuMPScalar}), N}), __T_model<:Union{Nothing, Model}}

High level optimisation function that wraps around estimator-specific optimisation functions. This takes care of fallback methods if the primary optimisation fails. It returns the first successful optimisation result but stores all fallback results in the fb field of the result.

Arguments

  • opt::OptimisationEstimator: The optimisation estimator to use.

  • args: Additional positional arguments passed to the optimisation function.

  • kwargs: Additional keyword arguments passed to the optimisation function.

source
PortfolioOptimisers.calc_net_returns Function

fees takes precedence over res.fees if both are provided

source
PortfolioOptimisers.assert_special_nco_requirements Method
julia
assert_special_nco_requirements(opt)

Assert that the optimiser meets special requirements for Nested Clustered Optimisation (NCO).

The default implementation does nothing. Overridden for estimators (e.g. Stacking) that have requirements which must be validated before NCO can proceed.

Arguments

  • opt: Optimisation estimator, result, or vector thereof.

Returns

  • nothing.

Related

source
PortfolioOptimisers.needs_previous_weights Method
julia
needs_previous_weights(opt)

Return true if the optimiser requires the previous period's weights.

The default returns false. Overridden for optimisers that contain turnover constraints, tracking error constraints, or other time-dependent components that require the previous optimisation's weights.

Arguments

  • opt: Optimisation estimator, result, risk measure, fee structure, or vector thereof.

Returns

  • Bool: true if previous weights are needed.

Related

source
PortfolioOptimisers.is_time_dependent Method
julia
is_time_dependent(opt)

Return true if the optimiser has time-dependent constraints or objectives.

The default returns false. Overridden for estimators that must be updated between periods (e.g. when constraints depend on the current time step).

Arguments

  • opt: Optimisation estimator, result, or vector thereof.

Returns

  • Bool: true if the estimator is time-dependent.

Related

source
PortfolioOptimisers.update_time_dependent_estimator Method
julia
update_time_dependent_estimator(opt, args...)

Update the estimator for the current time period.

The default returns the estimator unchanged. Overridden for estimators that need to be updated between periods (e.g. sliding window constraints, time-varying parameters).

Arguments

  • opt: Optimisation estimator or result.

  • args...: Additional arguments (e.g. current period index, returns data).

Returns

  • Updated estimator.

Related

source
PortfolioOptimisers.opt_weight_bounds Function
julia
opt_weight_bounds(wf, wb, w)

Compute optimised weight bounds from the finaliser, bounds, and current weights.

Adjusts the weight bounds based on the weight finaliser algorithm and the current weight allocation, used in hierarchical weight allocation.

Arguments

  • wf: Weight finaliser algorithm.

  • wb: Weight bounds.

  • w: Current portfolio weights.

Returns

  • Updated weight bounds.

Related

source
PortfolioOptimisers.finalise_weight_bounds Function
julia
finalise_weight_bounds(wf::WeightFinaliser, wb::WeightBounds, w::VecNum)

Apply weight finalisation to enforce bounds and determine the optimisation return code.

Runs opt_weight_bounds with the given finaliser and bounds, then returns a success or failure return code based on whether all weights are finite.

Arguments

  • wf::WeightFinaliser: Weight finaliser algorithm.

  • wb::WeightBounds: Weight bounds configuration.

  • w::VecNum: Portfolio weights to finalise.

Returns

  • (retcode, w): Tuple of return code and adjusted weights.

Related

source
PortfolioOptimisers.opt_view Method
julia
opt_view(opt, i, args...)

Return a view or subset of an optimisation estimator for a given cluster index i.

Default fallback returns the estimator unchanged. Overridden for composite estimators (e.g. JuMPOptimiser, HierarchicalRiskParity) to slice all sub-estimators for the i-th cluster.

Arguments

  • opt: Optimisation estimator or result.

  • i: Cluster or asset index.

  • args...: Additional arguments (e.g. asset returns matrix).

Returns

  • Sliced or unchanged optimisation estimator.

Related

source