Risk budgeting
PortfolioOptimisers.RiskBudgetingResult Type
struct RiskBudgetingResult{__T_jr, __T_prb, __T_fb} <: RiskJuMPOptimisationResultResult type for Risk Budgeting portfolio optimisation.
Fields
jr: Shared JuMP result core, seeJuMPOptimisationResult.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).
Related
sourcePortfolioOptimisers.factory Method
factory(a::Union{Nothing, <:AbstractEstimator, <:AbstractAlgorithm,
<:AbstractResult}, args...; kwargs...) -> aNo-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.
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> factory(nothing, 1, 2; x = 3)
julia> factory(MeanValue())
MeanValue
w ┴ nothingRelated
sourcefactory(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
sourcefactory(
opt::Union{NonFiniteAllocationOptimisationEstimator, NonFiniteAllocationOptimisationResult},
_
) -> RandomWeighted{_A, var"#s179", _B, _C, _D, var"#s1791", _E, Bool} where {_A, var"#s179"<:AbstractRNG, _B, _C, _D, var"#s1791"<:WeightFinaliser, _E}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
sourceBase.getproperty Method
getproperty(r::RiskBudgetingResult, sym::Symbol) -> AnyAccess properties of RiskBudgetingResult. Unique field prb resolves directly; unknown properties forward into prb first, then delegate to the embedded JuMPOptimisationResult jr (the virtual :w and pa fall-through).
PortfolioOptimisers.ProcessedFactorRiskBudgetingAttributes Type
struct ProcessedFactorRiskBudgetingAttributes{__T_rkb, __T_b1, __T_rr} <: AbstractResultProcessed 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
sourcePortfolioOptimisers.ProcessedAssetRiskBudgetingAttributes Type
struct ProcessedAssetRiskBudgetingAttributes{__T_rkb} <: AbstractResultProcessed asset risk budgeting attributes for intermediate computations.
Fields
rkb: Processed asset risk budget constraints vector.
Related
sourcePortfolioOptimisers.RiskBudgetingFormulation Type
abstract type RiskBudgetingFormulation <: OptimisationAlgorithmAbstract supertype for risk budgeting optimisation formulations.
Related Types
sourcePortfolioOptimisers.port_opt_view Method
port_opt_view(::RiskBudgetingFormulation, args...) -> nothingDefault fallback for risk budgeting formulation view. Returns nothing for formulations that do not require view slicing.
PortfolioOptimisers.port_opt_view Method
port_opt_view(x, i, args...; kwargs...) -> nothing_scalar_array_view(x, i)Universal fallback for port_opt_view. Any value that has no more specific port_opt_view method is treated as leaf data: it is delegated to nothing_scalar_array_view, which slices arrays/VecScalars and passes scalars, nothing, estimators, and algorithms through unchanged. Composed structs that need to recurse into children define their own (more specific) method — emitted by the @vprop tag 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
sourceport_opt_view(::RiskBudgetingFormulation, args...) -> nothingDefault fallback for risk budgeting formulation view. Returns nothing for formulations that do not require view slicing.
PortfolioOptimisers.port_opt_view Method
port_opt_view(x, i, args...; kwargs...) -> nothing_scalar_array_view(x, i)Universal fallback for port_opt_view. Any value that has no more specific port_opt_view method is treated as leaf data: it is delegated to nothing_scalar_array_view, which slices arrays/VecScalars and passes scalars, nothing, estimators, and algorithms through unchanged. Composed structs that need to recurse into children define their own (more specific) method — emitted by the @vprop tag 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
sourceport_opt_view(::RiskBudgetingFormulation, args...) -> nothingDefault fallback for risk budgeting formulation view. Returns nothing for formulations that do not require view slicing.
PortfolioOptimisers.LogRiskBudgeting Type
struct LogRiskBudgeting{T} <: RiskBudgetingFormulationLog-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). Ifnothing, all assets have positive weights.
Constructors
LogRiskBudgeting(;
z::Option{<:VecInt} = nothing
) -> LogRiskBudgetingKeywords correspond to the struct's fields.
Validation
- If
zis provided:!isempty(z)andall(x -> abs(x) == 1, z).
Related
sourcePortfolioOptimisers.MixedIntegerRiskBudgeting Type
struct MixedIntegerRiskBudgeting <: RiskBudgetingFormulationMixed-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
sourcePortfolioOptimisers.RiskBudgetingAlgorithm Type
abstract type RiskBudgetingAlgorithm <: OptimisationAlgorithmAbstract supertype for risk budgeting algorithm specifications.
Related Types
sourcePortfolioOptimisers.AssetRiskBudgeting Type
struct AssetRiskBudgeting{__T_rkb, __T_sets, __T_alg} <: RiskBudgetingAlgorithmAsset-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
AssetRiskBudgeting(;
rkb::Option{<:RkbE_Rkb} = nothing,
sets::Option{<:AssetSets} = nothing,
alg::RiskBudgetingFormulation = LogRiskBudgeting()
) -> AssetRiskBudgetingKeywords correspond to the struct's fields.
Validation
- If
rkbis aRiskBudgetEstimator:!isnothing(sets).
Related
sourcePortfolioOptimisers.FactorRiskBudgeting Type
struct FactorRiskBudgeting{__T_re, __T_rkb, __T_sets, __T_flag} <: RiskBudgetingAlgorithmFactor-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
FactorRiskBudgeting(;
re::RegE_Reg = StepwiseRegression(),
rkb::Option{<:RkbE_Rkb} = nothing,
sets::Option{<:AssetSets} = nothing,
flag::Bool = true
) -> FactorRiskBudgetingKeywords correspond to the struct's fields.
Validation
- If
rkbis aRiskBudgetEstimator:!isnothing(sets).
Related
sourcePortfolioOptimisers.RiskBudgeting Type
struct RiskBudgeting{__T_opt, __T_r, __T_rba, __T_wi, __T_fb} <: RiskJuMPOptimisationEstimatorRisk 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:JuMPoptimiser 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
RiskBudgeting(;
opt::JuMPOptimiser = JuMPOptimiser(),
r::RM_VecRM = Variance(),
rba::RiskBudgetingAlgorithm = AssetRiskBudgeting(),
wi::Option{<:VecNum} = nothing,
fb::Option{<:OptE_Opt} = nothing
) -> RiskBudgetingKeywords correspond to the struct's fields.
Validation
If
ris a vector:!isempty(r).If
wiis provided:!isempty(wi).
Mathematical definition
Risk budgeting allocates weights so that each asset
The logarithmic formulation (LogRiskBudgeting) solves the equivalent convex problem:
Where:
: Portfolio weight of asset . : Portfolio risk measure. : Risk budget (target risk fraction) for asset . : Number of assets. : Portfolio weight vector.
Related
PortfolioOptimisers.needs_previous_weights Method
needs_previous_weights(opt::RiskBudgeting) -> AnyReturn true if any sub-estimator of opt requires previous portfolio weights (JuMP optimiser, risk measure, or fallback).
PortfolioOptimisers.factory Method
factory(
rb::RiskBudgeting,
w::AbstractVector
) -> 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_nea, __T_l1, __T_l2, __T_linf, __T_lp, __T_brt, __T_cle_pr, __T_strict}, _A, <:RiskBudgetingAlgorithm} 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_nea, __T_l1, __T_l2, __T_linf, __T_lp, __T_brt, __T_cle_pr, __T_strict, _A}Build an updated RiskBudgeting with all estimators that track previous weights updated via factory using w.
PortfolioOptimisers.port_opt_view Method
port_opt_view(
rb::RiskBudgeting,
i,
X::AbstractMatrix{<:Union{var"#s20", var"#s19"} where {var"#s20"<:Number, var"#s19"<: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_nea, __T_l1, __T_l2, __T_linf, __T_lp, __T_brt, __T_cle_pr, __T_strict}, _A, <:RiskBudgetingAlgorithm} 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_nea, __T_l1, __T_l2, __T_linf, __T_lp, __T_brt, __T_cle_pr, __T_strict, _A}Return a cluster-sliced copy of RiskBudgeting for asset index set i and returns matrix X.
PortfolioOptimisers.port_opt_view Method
port_opt_view(r, i)Return a view or subset of a risk budgeting algorithm for cluster index i.
Used in hierarchical optimisation to slice risk budget and asset set configurations for each cluster.
Arguments
r: Risk budgeting algorithm (AssetRiskBudgetingorFactorRiskBudgeting).i: Cluster or asset index.
Returns
- Sliced risk budgeting algorithm.
Related
sourcePortfolioOptimisers.port_opt_view Method
port_opt_view(r::FactorRiskBudgeting, i)Return a view of a FactorRiskBudgeting algorithm for cluster index i.
Slices the regression estimator for the given cluster while keeping the risk budget, asset sets, and idiosyncratic flag unchanged.
Arguments
r::FactorRiskBudgeting: Factor-level risk budgeting algorithm.i: Cluster or asset index.
Returns
FactorRiskBudgetingwith the regression estimator sliced to clusteri.
Related
sourcePortfolioOptimisers._set_risk_budgeting_constraints! Method
_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:RiskBudgetingoptimiser configuration.Additional risk and budget parameters.
Returns
nothing.
Related
sourcePortfolioOptimisers.set_risk_budgeting_constraints! Function
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
sourcePortfolioOptimisers.set_rb_mip_w! Function
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
sourcePortfolioOptimisers.optimise Function
optimise(rb::RiskBudgeting{<:Any, <:Any, <:Any, <:Any, Nothing},
rd::ReturnsResult = ReturnsResult(); dims::Int = 1,
str_names::Bool = false, save::Bool = true, kwargs...) -> RiskBudgetingResultRun the Risk Budgeting portfolio optimisation.
Arguments
rb: The risk budgeting optimiser to use.rd: The returns result to use. Ifisa(rb.opt.pe, AbstractPriorResult),rdis 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