Base optimisation
PortfolioOptimisers.AbstractOptimisationEstimator Type
abstract type AbstractOptimisationEstimator <: AbstractEstimatorAbstract 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
sourcePortfolioOptimisers.BaseOptimisationEstimator Type
abstract type BaseOptimisationEstimator <: AbstractOptimisationEstimatorAbstract 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
sourcePortfolioOptimisers.OptimisationEstimator Type
abstract type OptimisationEstimator <: AbstractOptimisationEstimatorAbstract 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
sourcePortfolioOptimisers.NonFiniteAllocationOptimisationEstimator Type
abstract type NonFiniteAllocationOptimisationEstimator <: OptimisationEstimatorAbstract supertype for portfolio optimisation estimators that produce continuous (non-integer) portfolio weights.
Related Types
sourcePortfolioOptimisers.OptimisationAlgorithm Type
abstract type OptimisationAlgorithm <: AbstractAlgorithmAbstract supertype for optimisation algorithms used by portfolio optimisers.
Related Types
sourcePortfolioOptimisers.OptimisationResult Type
abstract type OptimisationResult <: AbstractResultAbstract supertype for portfolio optimisation result types.
All concrete optimisation result types should subtype OptimisationResult.
Related Types
sourcePortfolioOptimisers.NonFiniteAllocationOptimisationResult Type
abstract type NonFiniteAllocationOptimisationResult <: OptimisationResultAbstract supertype for continuous (non-integer allocation) optimisation results.
Related Types
sourcePortfolioOptimisers.OptimisationReturnCode Type
abstract type OptimisationReturnCode <: AbstractResultAbstract supertype for optimisation return codes.
Concrete subtypes indicate whether an optimisation succeeded or failed.
Related Types
sourcePortfolioOptimisers.OptimisationModelResult Type
abstract type OptimisationModelResult <: AbstractResultAbstract supertype for intermediate optimisation model results.
Related Types
sourcePortfolioOptimisers.OptimisationSuccess Type
struct OptimisationSuccess{__T_res} <: OptimisationReturnCodeIndicates that a portfolio optimisation completed successfully.
Fields
res: Optional result or message from the solver (default:nothing).
Related
sourcePortfolioOptimisers.OptimisationFailure Type
struct OptimisationFailure{__T_res} <: OptimisationReturnCodeIndicates that a portfolio optimisation failed.
Fields
res: Optional error message or diagnostic information (default:nothing).
Related
sourcePortfolioOptimisers.JuMPWeightFinaliserFormulation Type
abstract type JuMPWeightFinaliserFormulation <: AbstractAlgorithmAbstract 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
PortfolioOptimisers.RelativeErrorWeightFinaliser Type
struct RelativeErrorWeightFinaliser <: JuMPWeightFinaliserFormulationMinimises the L1 norm of relative weight deviations when enforcing weight bounds.
sourcePortfolioOptimisers.SquaredRelativeErrorWeightFinaliser Type
struct SquaredRelativeErrorWeightFinaliser <: JuMPWeightFinaliserFormulationMinimises the L2 norm (squared) of relative weight deviations when enforcing weight bounds.
sourcePortfolioOptimisers.AbsoluteErrorWeightFinaliser Type
struct AbsoluteErrorWeightFinaliser <: JuMPWeightFinaliserFormulationMinimises the L1 norm of absolute weight deviations when enforcing weight bounds.
sourcePortfolioOptimisers.SquaredAbsoluteErrorWeightFinaliser Type
struct SquaredAbsoluteErrorWeightFinaliser <: JuMPWeightFinaliserFormulationMinimises the L2 norm (squared) of absolute weight deviations when enforcing weight bounds.
sourcePortfolioOptimisers.WeightFinaliser Type
abstract type WeightFinaliser <: AbstractAlgorithmAbstract supertype for weight finaliser strategies.
A WeightFinaliser enforces weight bounds after the optimisation has produced unconstrained weights.
Related Types
sourcePortfolioOptimisers.IterativeWeightFinaliser Type
struct IterativeWeightFinaliser{__T_iter} <: WeightFinaliserIteratively 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
IterativeWeightFinaliser(;
iter::Integer = 100
) -> IterativeWeightFinaliserKeywords correspond to the struct's fields.
Validation
iter > 0.
Examples
julia> IterativeWeightFinaliser()
IterativeWeightFinaliser
iter ┴ Int64: 100Related
sourcePortfolioOptimisers.JuMPWeightFinaliser Type
struct JuMPWeightFinaliser{__T_slv, __T_sc, __T_so, __T_alg} <: WeightFinaliserUses 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
JuMPWeightFinaliser(;
slv::Slv_VecSlv,
sc::Number = 1.0,
so::Number = 1.0,
alg::JuMPWeightFinaliserFormulation = RelativeErrorWeightFinaliser()
) -> JuMPWeightFinaliserKeywords correspond to the struct's fields.
Validation
If
slvis aVecSlv:!isempty(slv).sc > 0,so > 0.
Related
sourcePortfolioOptimisers._optimise Function
_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
sourcePortfolioOptimisers.optimise Method
optimise(opt::OptimisationEstimator, args...; kwargs...) -> OptimisationResult
optimise(opt::OptimisationResult, args...; kwargs...) -> OptimisationResultRun 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. aJuMPOptimisationEstimatorsubtype).args: Additional positional arguments (ignored).kwargs: Additional keyword arguments (ignored).
Returns
OptimisationResult: The optimisation result.
Related
sourcePortfolioOptimisers.optimise Method
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.
PortfolioOptimisers.calc_net_returns Function
fees takes precedence over res.fees if both are provided
sourcePortfolioOptimisers.assert_special_nco_requirements Method
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
sourcePortfolioOptimisers.needs_previous_weights Method
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:trueif previous weights are needed.
Related
sourcePortfolioOptimisers.is_time_dependent Method
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:trueif the estimator is time-dependent.
Related
sourcePortfolioOptimisers.update_time_dependent_estimator Method
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
sourcePortfolioOptimisers.opt_weight_bounds Function
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
sourcePortfolioOptimisers.finalise_weight_bounds Function
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
sourcePortfolioOptimisers.opt_view Method
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