Skip to content
18

Risk budgeting

PortfolioOptimisers.RiskBudgetingResult Type
julia
struct RiskBudgetingResult{__T_jr, __T_prb, __T_fb} <: RiskJuMPOptimisationResult

Result type for Risk Budgeting portfolio optimisation.

Fields

  • jr: Shared JuMP result core, see JuMPOptimisationResult.

  • prb: Processed risk budgeting configuration.

  • fb: Fallback result or estimator.

Property access delegates to the embedded JuMPOptimisationResult; unknown properties forward to prb first, then through jr (including the virtual :w and the pa fall-through).

Constructors

julia
RiskBudgetingResult(;
    jr::JuMPOptimisationResult,
    prb::Union{ProcessedAssetRiskBudgetingAttributes,
               ProcessedFactorRiskBudgetingAttributes},
    fb::Option{<:OptE_Opt}
) -> RiskBudgetingResult

Keywords correspond to the struct's fields.

Related

source
PortfolioOptimisers.factory Method
julia
factory(a::Union{Nothing, <:AbstractEstimator, <:AbstractAlgorithm,
                 <:AbstractResult}, args...; kwargs...) -> a

No-op factory function for constructing objects with a uniform interface.

Defining methods which dispatch on the first argument allows for a consistent factory interface across different types.

factory and port_opt_view are the two propagation mechanisms in this library. They are duals: factory threads runtime values (prior moments, observation weights, previous portfolio weights) down through a composed struct tree; port_opt_view threads an index selection (a subset of assets or observations) down through the same tree.

Arguments

  • a: Indicates no object should be constructed.

  • args...: Arbitrary positional arguments (ignored).

  • kwargs...: Arbitrary keyword arguments (ignored).

Returns

  • a: The input unchanged.

Examples

julia
julia> factory(nothing, 1, 2; x = 3)

julia> factory(MeanValue())
MeanValue
  w ┴ nothing

Related

source
julia
factory(res::NonFiniteAllocationOptimisationResult, fb::Option{<:OptE_Opt})

Rebuild a continuous optimisation result with an updated fallback optimiser fb.

Every optimisation result carries fb as its last field, so the generic rebuild copies all fields unchanged except the trailing fb. Concrete result types may override this method when rebuilding requires more than swapping fb.

Related

source
julia
factory(
    opt::Union{NonFiniteAllocationOptimisationEstimator, NonFiniteAllocationOptimisationResult},
    _
) -> SubsetResamplingResult

Return opt unchanged.

Default pass-through factory for optimisation estimators and results. Overridden for estimators that carry parameters requiring update at each optimisation step.

Related

source
PortfolioOptimisers.risk_budgeting_td_defaults Function
julia
risk_budgeting_td_defaults(

) -> @NamedTuple{r::Variance{RiskMeasureSettings{Float64, Nothing, Bool}, Nothing, Nothing, Nothing, SquaredSOCRiskExpr}, rba::AssetRiskBudgeting{Nothing, Nothing, LogRiskBudgeting{Nothing}}}

Return the static defaults of the RiskBudgeting fields that may hold a TimeDependent.

Shared by the constructor's test-substitution pass and time_dependent_field_defaults, so the fold-less value of a field is declared once. Fields whose static default is nothing are omitted.

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.ProcessedRiskBudgetingAttributes Type
julia
abstract type ProcessedRiskBudgetingAttributes <: ProcessedAttributes

Abstract supertype for processed risk budgeting attributes. Every collection of processed risk budgeting attributes should subtype this.

Related

source
PortfolioOptimisers.ProcessedFactorRiskBudgetingAttributes Type
julia
struct ProcessedFactorRiskBudgetingAttributes{__T_rkb, __T_b1, __T_rr} <: ProcessedRiskBudgetingAttributes

Processed factor risk budgeting attributes for intermediate computations.

Fields

  • rkb: Processed risk budget constraints vector.

  • b1: Factor-level risk budget vector.

  • rr: Regression result used for factor loading estimation.

Related

source
PortfolioOptimisers.ProcessedAssetRiskBudgetingAttributes Type
julia
struct ProcessedAssetRiskBudgetingAttributes{__T_rkb} <: ProcessedRiskBudgetingAttributes

Processed asset risk budgeting attributes for intermediate computations.

Fields

  • rkb: Processed asset risk budget constraints vector.

Related

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

Abstract supertype for risk budgeting optimisation formulations.

Related Types

source
PortfolioOptimisers.port_opt_view Method
julia
port_opt_view(::RiskBudgetingFormulation, args...) -> nothing

Default fallback for risk budgeting formulation view. Returns nothing for formulations that do not require view slicing.

source
PortfolioOptimisers.port_opt_view Method
julia
port_opt_view(x, i, args...; kwargs...) -> nothing_scalar_array_view(x, i)

Sub-select an estimator, result, or algorithm to the asset/observation index i.

port_opt_view is the index-selection counterpart of factory: where factory threads runtime values down a composed struct tree, port_opt_view threads an index selection — restricting every data-bearing field and composed child to the subset i. It is the mechanism that makes meta-optimisers (NestedClustered, SubsetResampling) and cross-validation variants operate on subproblems with identical struct shapes.

Callers do not normally call port_opt_view directly; it is driven by meta-optimisers and cross-validation internals. It is public (not exported) because extension authors who implement a new composed estimator may need to define a method. Use @vprop on data-bearing fields to have the method generated automatically.

This universal fallback handles leaf values: arrays are sliced via nothing_scalar_array_view; scalars, nothing, estimators without data fields, and algorithms pass through unchanged. Composed structs that recurse into children define their own (more specific) method — emitted by @vprop or hand-written.

The threaded tail args... (typically the returns matrix X for the JuMP families) and any kwargs are accepted and dropped here, so a macro-threaded port_opt_view(child, i, X) never MethodErrors on a leaf field.

Related

source
julia
port_opt_view(::RiskBudgetingFormulation, args...) -> nothing

Default fallback for risk budgeting formulation view. Returns nothing for formulations that do not require view slicing.

source
PortfolioOptimisers.port_opt_view Method
julia
port_opt_view(x, i, args...; kwargs...) -> nothing_scalar_array_view(x, i)

Sub-select an estimator, result, or algorithm to the asset/observation index i.

port_opt_view is the index-selection counterpart of factory: where factory threads runtime values down a composed struct tree, port_opt_view threads an index selection — restricting every data-bearing field and composed child to the subset i. It is the mechanism that makes meta-optimisers (NestedClustered, SubsetResampling) and cross-validation variants operate on subproblems with identical struct shapes.

Callers do not normally call port_opt_view directly; it is driven by meta-optimisers and cross-validation internals. It is public (not exported) because extension authors who implement a new composed estimator may need to define a method. Use @vprop on data-bearing fields to have the method generated automatically.

This universal fallback handles leaf values: arrays are sliced via nothing_scalar_array_view; scalars, nothing, estimators without data fields, and algorithms pass through unchanged. Composed structs that recurse into children define their own (more specific) method — emitted by @vprop or hand-written.

The threaded tail args... (typically the returns matrix X for the JuMP families) and any kwargs are accepted and dropped here, so a macro-threaded port_opt_view(child, i, X) never MethodErrors on a leaf field.

Related

source
julia
port_opt_view(::RiskBudgetingFormulation, args...) -> nothing

Default fallback for risk budgeting formulation view. Returns nothing for formulations that do not require view slicing.

source
PortfolioOptimisers.LogRiskBudgeting Type
julia
struct LogRiskBudgeting{T} <: RiskBudgetingFormulation

Log-barrier formulation for Risk Budgeting.

Uses a logarithmic objective to enforce the risk budget constraints. Can provide an optional orthant vector to allow for negative weights in specific assets.

Fields

  • z: Optional orthant vector of ±1 defining which assets can have negative weights (-1) or must be positive (+1). If nothing, all assets have positive weights.

Constructors

julia
LogRiskBudgeting(;
    z::Option{<:VecInt} = nothing
) -> LogRiskBudgeting

Keywords correspond to the struct's fields.

Validation

  • If z is provided: !isempty(z) and all(x -> abs(x) == 1, z).

Related

source
PortfolioOptimisers.MixedIntegerRiskBudgeting Type
julia
struct MixedIntegerRiskBudgeting <: RiskBudgetingFormulation

Mixed-integer formulation for Risk Budgeting.

Uses binary variables and big-M constraints to enforce the risk budget constraints. This can find the minimal risk portfolio which meets the risk budgeting constraints by exploring all possible sign combinations of weights. This can be very expensive for large universes.

Related Types

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

Abstract supertype for risk budgeting algorithm specifications.

Related Types

source
PortfolioOptimisers.AssetRiskBudgeting Type
julia
struct AssetRiskBudgeting{__T_rkb, __T_sets, __T_alg} <: RiskBudgetingAlgorithm

Asset-level Risk Budgeting algorithm.

AssetRiskBudgeting specifies the risk budget as a vector of asset-level risk targets, optionally grouped by asset sets.

Fields

  • rkb: Risk budget estimator or result.

  • sets: Sets used to map estimator values to features.

  • alg: Risk budget algorithm.

Constructors

julia
AssetRiskBudgeting(;
    rkb::Option{<:RkbE_Rkb} = nothing,
    sets::Option{<:AssetSets} = nothing,
    alg::RiskBudgetingFormulation = LogRiskBudgeting()
) -> AssetRiskBudgeting

Keywords correspond to the struct's fields.

Validation

  • If rkb is a RiskBudgetEstimator: !isnothing(sets).

Related

source
PortfolioOptimisers.FactorRiskBudgeting Type
julia
struct FactorRiskBudgeting{__T_re, __T_rkb, __T_sets, __T_flag} <: RiskBudgetingAlgorithm

Factor-level Risk Budgeting algorithm.

FactorRiskBudgeting specifies the risk budget at the factor level, using a factor model regression to decompose risk across factors and an idiosyncratic component.

Fields

  • re: Regression estimator.

  • rkb: Risk budget estimator or result.

  • sets: Sets used to map estimator values to features.

  • flag: Algorithm selection flag.

Constructors

julia
FactorRiskBudgeting(;
    re::RegE_Reg = StepwiseRegression(),
    rkb::Option{<:RkbE_Rkb} = nothing,
    sets::Option{<:AssetSets} = nothing,
    flag::Bool = true
) -> FactorRiskBudgeting

Keywords correspond to the struct's fields.

Validation

  • If rkb is a RiskBudgetEstimator: !isnothing(sets).

Related

source
PortfolioOptimisers.RiskBudgeting Type
julia
struct RiskBudgeting{__T_opt, __T_r, __T_rba, __T_wi, __T_fb} <: RiskJuMPOptimisationEstimator

Risk Budgeting (RB) portfolio optimiser.

RiskBudgeting allocates portfolio weights so that each asset (or factor) contributes a specified fraction of the total portfolio risk. It uses a logarithmic or mixed-integer formulation and can be combined with any risk measure.

Fields

  • opt: JuMP optimiser configuration.

  • r: Risk measure or vector of risk measures.

  • rba: Risk budget algorithm.

  • wi: Initial portfolio weights for warm-starting the solver.

  • fb: Fallback result or estimator.

Constructors

julia
RiskBudgeting(;
    opt::JuMPOptimiser,
    r::TD{<:RM_VecRM} = Variance(),
    rba::TD{<:RiskBudgetingAlgorithm} = AssetRiskBudgeting(),
    wi::TD_Option{<:VecNum} = nothing,
    fb::TDO_Option{<:OptE_Opt} = nothing
) -> RiskBudgeting

Keywords correspond to the struct's fields. Fields typed TD, TD_Option or TDO_Option may hold a TimeDependent per-fold schedule instead of a static value: the risk measure, budgeting algorithm (and with it the risk budget), warm start and fallback are problem definition, so a cross-validation fold loop resolves them per fold, and a fold-less optimise runs with each at its static default (nothing for wi and fb).

Validation

  • If r is a vector: !isempty(r).

  • If wi is provided: !isempty(wi).

  • fb schedules: bind !== :nearest.

Mathematical definition

Risk budgeting allocates weights so that each asset i contributes a target fraction bi of total portfolio risk:

wiρ(w)wi=biρ(w),i=1Nbi=1,bi0.

The logarithmic formulation (LogRiskBudgeting) solves the equivalent convex problem:

minwρ(w)i=1Nbilnwis.t.w>0.

Where:

  • wi: Portfolio weight of asset i.

  • ρ(w): Portfolio risk measure.

  • bi: Risk budget (target risk fraction) for asset i.

  • N: Number of assets.

  • w: Portfolio weight vector.

Propagated parameters

When factory is called on this type, the following @fprop-tagged fields are automatically propagated:

  • opt: Recursively updated via factory.

  • r: Recursively updated via factory.

  • fb: Recursively updated via factory.

Related

source
PortfolioOptimisers.needs_previous_weights Method
julia
needs_previous_weights(opt::RiskBudgeting) -> Any

Return true if any sub-estimator of opt requires previous portfolio weights (JuMP optimiser, risk measure, or fallback).

source
PortfolioOptimisers.factory Method
julia
factory(a::Union{Nothing, <:AbstractEstimator, <:AbstractAlgorithm,
                 <:AbstractResult}, args...; kwargs...) -> a

No-op factory function for constructing objects with a uniform interface.

Defining methods which dispatch on the first argument allows for a consistent factory interface across different types.

factory and port_opt_view are the two propagation mechanisms in this library. They are duals: factory threads runtime values (prior moments, observation weights, previous portfolio weights) down through a composed struct tree; port_opt_view threads an index selection (a subset of assets or observations) down through the same tree.

Arguments

  • a: Indicates no object should be constructed.

  • args...: Arbitrary positional arguments (ignored).

  • kwargs...: Arbitrary keyword arguments (ignored).

Returns

  • a: The input unchanged.

Examples

julia
julia> factory(nothing, 1, 2; x = 3)

julia> factory(MeanValue())
MeanValue
  w ┴ nothing

Related

source
julia
factory(
    opt::Union{NonFiniteAllocationOptimisationEstimator, NonFiniteAllocationOptimisationResult},
    _
) -> SubsetResamplingResult

Return opt unchanged.

Default pass-through factory for optimisation estimators and results. Overridden for estimators that carry parameters requiring update at each optimisation step.

Related

source
PortfolioOptimisers.port_opt_view Method
julia
port_opt_view(
    rb::RiskBudgeting,
    i,
    X::AbstractMatrix{<:Union{var"#s29", var"#s28"} where {var"#s29"<:Number, var"#s28"<:AbstractJuMPScalar}},
    args...
) -> RiskBudgeting{JuMPOptimiser{__T_pe, __T_slv, __T_wb, __T_bgt, __T_sbgt, __T_lt, __T_st, __T_lcse, __T_cte, __T_gcarde, __T_sgcarde, __T_smtx, __T_sgmtx, __T_slt, __T_sst, __T_sglt, __T_sgst, __T_tn, __T_fees, __T_sets, __T_tr, __T_ple, __T_ret, __T_sca, __T_ccnt, __T_cobj, __T_sc, __T_so, __T_ss, __T_card, __T_scard, __T_wn2, __T_wnp, __T_wninf, __T_l1, __T_l2, __T_linf, __T_lp, __T_brt, __T_cle_pr, __T_strict}} where {__T_pe, __T_slv, __T_wb, __T_bgt, __T_sbgt, __T_lt, __T_st, __T_lcse, __T_cte, __T_gcarde, __T_sgcarde, __T_smtx, __T_sgmtx, __T_slt, __T_sst, __T_sglt, __T_sgst, __T_tn, __T_fees, __T_sets, __T_tr, __T_ple, __T_ret, __T_sca, __T_ccnt, __T_cobj, __T_sc, __T_so, __T_ss, __T_card, __T_scard, __T_wn2, __T_wnp, __T_wninf, __T_l1, __T_l2, __T_linf, __T_lp, __T_brt, __T_cle_pr, __T_strict}

Return a cluster-sliced copy of RiskBudgeting for asset index set i and returns matrix X.

source
PortfolioOptimisers._set_risk_budgeting_constraints! Method
julia
_set_risk_budgeting_constraints!(model, rb, ...)

Internal function to set risk budgeting constraints in the JuMP model.

Configures the equality constraints ensuring each asset's marginal risk contribution equals its budget target.

Arguments

  • model: JuMP model.

  • rb: RiskBudgeting optimiser configuration.

  • Additional risk and budget parameters.

Returns

  • nothing.

Related

source
PortfolioOptimisers.set_risk_budgeting_constraints! Function
julia
set_risk_budgeting_constraints!(model, rb, pr, wb, args...)

Add risk budgeting constraints and weight variables to the JuMP model.

Dispatches based on the risk budgeting algorithm and formulation. Sets up weight variables, logarithmic risk budget constraints, and weight bounds for the specified formulation (log, MIP, or factor-based).

Arguments

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

  • rb::RiskBudgeting: Risk budgeting estimator configuration.

  • pr::AbstractPriorResult: Prior result with asset moments.

  • wb::WeightBounds: Weight bounds configuration.

  • args...: Additional arguments (e.g. returns data for factor risk budgeting).

Returns

  • Processed risk budgeting attributes.

Related

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

Create long and short weight variables for MIP risk budgeting in the JuMP model.

Registers long lw, short sw weight variables and the derived expressions w = lw - sw and w_obj = lw + sw.

Arguments

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

  • X::MatNum: Asset returns matrix (used to determine number of assets).

Returns

  • nothing.

Related

source
PortfolioOptimisers.optimise Function
julia
optimise(rb::RiskBudgeting{<:Any, <:Any, <:Any, <:Any, Nothing},
         rd::ReturnsResult = ReturnsResult(); dims::Int = 1,
         str_names::Bool = false, save::Bool = true, kwargs...) -> RiskBudgetingResult

Run the Risk Budgeting portfolio optimisation.

Arguments

  • rb: The risk budgeting optimiser to use.

  • rd: The returns result to use. If isa(rb.opt.pe, AbstractPriorResult), rd is not necessary if doing a standalone optimisation, but may be required/desired by fallbacks and/or clusterisation.

  • dims: The dimension along which observations advance in time.

  • str_names: Whether to use string names for the assets in the optimisation.

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

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

Related

source