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).
Constructors
RiskBudgetingResult(;
jr::JuMPOptimisationResult,
prb::Union{ProcessedAssetRiskBudgetingAttributes,
ProcessedFactorRiskBudgetingAttributes},
fb::Option{<:OptE_Opt}
) -> RiskBudgetingResultKeywords correspond to the struct's fields.
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.
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> 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},
_
) -> SubsetResamplingResultReturn opt unchanged.
Default pass-through factory for optimisation estimators and results. Overridden for estimators that carry parameters requiring update at each optimisation step.
Related
sourcePortfolioOptimisers.risk_budgeting_td_defaults Function
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
sourceBase.getproperty Method
getproperty(
r::RiskJuMPOptimisationResult,
sym::Symbol
) -> AnyDefault property access for RiskJuMPOptimisationResult: unique fields resolve directly; everything else delegates to the embedded JuMPOptimisationResult jr.
PortfolioOptimisers.ProcessedRiskBudgetingAttributes Type
abstract type ProcessedRiskBudgetingAttributes <: ProcessedAttributesAbstract supertype for processed risk budgeting attributes. Every collection of processed risk budgeting attributes should subtype this.
Related
sourcePortfolioOptimisers.ProcessedFactorRiskBudgetingAttributes Type
struct ProcessedFactorRiskBudgetingAttributes{__T_rkb, __T_b1, __T_rr} <: ProcessedRiskBudgetingAttributesProcessed 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} <: ProcessedRiskBudgetingAttributesProcessed 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)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
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)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
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,
r::TD{<:RM_VecRM} = Variance(),
rba::TD{<:RiskBudgetingAlgorithm} = AssetRiskBudgeting(),
wi::TD_Option{<:VecNum} = nothing,
fb::TDO_Option{<:OptE_Opt} = nothing
) -> RiskBudgetingKeywords 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
ris a vector:!isempty(r).If
wiis provided:!isempty(wi).fbschedules:bind !== :nearest.
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.
Propagated parameters
When factory is called on this type, the following @fprop-tagged fields are automatically propagated:
opt: Recursively updated viafactory.r: Recursively updated viafactory.fb: Recursively updated viafactory.
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(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.
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> factory(nothing, 1, 2; x = 3)
julia> factory(MeanValue())
MeanValue
w ┴ nothingRelated
sourcefactory(
opt::Union{NonFiniteAllocationOptimisationEstimator, NonFiniteAllocationOptimisationResult},
_
) -> SubsetResamplingResultReturn opt unchanged.
Default pass-through factory for optimisation estimators and results. Overridden for estimators that carry parameters requiring update at each optimisation step.
Related
sourcePortfolioOptimisers.port_opt_view Method
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.
PortfolioOptimisers._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