Skip to content
18

Risk budget estimators

PortfolioOptimisers.RiskBudget Type
julia
struct RiskBudget{__T_val} <: AbstractConstraintResult

Container for the result of a risk budget constraint.

RiskBudget stores the vector of risk budget allocations resulting from risk budget constraint generation or normalisation. This type is used to encapsulate the output of risk budgeting routines in a consistent, composable format for downstream processing and reporting.

Fields

  • val: Vector of risk budget allocations.

Constructors

julia
RiskBudget(;
    val::VecNum
) -> RiskBudget

Keywords correspond to the struct's fields.

Validation

  • !isempty(val).

  • all(x -> zero(x) <= x, val).

View parameters

When port_opt_view is called on this type, the following @vprop-tagged fields are automatically subset to the selected indices:

Examples

julia
julia> RiskBudget(; val = [0.2, 0.3, 0.5])
RiskBudget
  val ┴ Vector{Float64}: [0.2, 0.3, 0.5]

Related

source
PortfolioOptimisers.RiskBudgetEstimator Type
julia
struct RiskBudgetEstimator{__T_val, __T_dval} <: AbstractConstraintEstimator

Container for a risk budget allocation mapping or vector.

RiskBudgetEstimator stores a mapping from asset or group names to risk budget values, or a vector of such pairs, for use in risk budgeting constraint generation. This type enables composable and validated workflows for specifying risk budgets in portfolio optimisation routines.

Fields

  • val: Mapping of names to risk budget values.

  • dval: Default value for assets not specified in val.

Constructors

julia
RiskBudgetEstimator(;
    val::EstValType
) -> RiskBudgetEstimator

Keywords correspond to the struct's fields.

Validation

Examples

julia
julia> RiskBudgetEstimator(; val = Dict("A" => 0.2, "B" => 0.3, "C" => 0.5))
RiskBudgetEstimator
   val ┼ Dict{String, Float64}: Dict("B" => 0.3, "A" => 0.2, "C" => 0.5)
  dval ┴ nothing

julia> RiskBudgetEstimator(; val = ["A" => 0.2, "B" => 0.3, "C" => 0.5])
RiskBudgetEstimator
   val ┼ Vector{Pair{String, Float64}}: ["A" => 0.2, "B" => 0.3, "C" => 0.5]
  dval ┴ nothing

Related

source
PortfolioOptimisers.RkbE_Rkb Type
julia
const RkbE_Rkb = Union{<:RiskBudgetEstimator, <:RiskBudget}

Alias for a risk budget estimator or result.

Matches either a RiskBudgetEstimator (specifying how to generate risk budget constraints) or a RiskBudget result (a pre-computed risk budget allocation). Used internally to accept either form in constraint generation dispatch.

Related

source
PortfolioOptimisers.risk_budget_constraints Function
julia
risk_budget_constraints(::Nothing, args...; N::Number, datatype::DataType = Float64,
                        kwargs...)

No-op fallback for risk budget constraint generation.

This method returns a uniform risk budget allocation when no explicit risk budget is specified (nothing). It creates a RiskBudget with equal weights summing to one, using the specified number of assets N and numeric type datatype. This is useful as a default in workflows where a risk budget is optional or omitted.

Arguments

  • ::Nothing: Indicates that no explicit risk budget is specified.

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

  • N::Number: Number of assets (required).

  • datatype::DataType: Numeric type for the risk budget vector.

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

Returns

  • rb::RiskBudget: A result object containing a uniform risk budget vector of length N, with each entry equal to 1/N.

Examples

julia
julia> risk_budget_constraints(nothing; N = 3)
RiskBudget
  val ┴ StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}: StepRangeLen(0.3333333333333333, 0.0, 3)

Related

source
julia
risk_budget_constraints(rb::RiskBudget, args...; kwargs...)

No-op fallback for risk budget constraint propagation.

This method returns the input RiskBudget object unchanged. It is used to pass through an already constructed risk budget allocation result, enabling composability and uniform interface handling in risk budgeting workflows.

Arguments

  • rb: An existing RiskBudget object.

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

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

Returns

  • rb::RiskBudget: The input RiskBudget object, unchanged.

Examples

julia
julia> RiskBudget(; val = [0.2, 0.3, 0.5])
RiskBudget
  val ┴ Vector{Float64}: [0.2, 0.3, 0.5]

Related

source
julia
risk_budget_constraints(rb::EstValType, sets::AssetSets,
                        dval::Option{<:Number} = nothing; strict::Bool = false,
                        kwargs...)

Generate a risk budget allocation from asset/group mappings and asset sets.

This method constructs a RiskBudget from a mapping of asset or group names to risk budget values, using the provided AssetSets. The mapping can be a dictionary, a single pair, or a vector of pairs. Asset and group names are resolved using sets, and the resulting risk budget vector is normalised to sum to one.

Arguments

  • rb: A dictionary, pair, or vector of pairs mapping asset or group names to risk budget values.

  • sets: An AssetSets object specifying the asset universe and groupings.

  • dval: Default value to use for assets not found in rb. If nothing, a default value of 1/length(sets.dict[sets.key]) is used.

  • strict: If true, throws an error if a key in rb is not found in sets; if false, issues a warning.

Details

  • Asset and group names in rb are mapped to indices in the asset universe using sets.

  • If a key is a group, all assets in the group are assigned the specified value.

  • The resulting vector is normalised to sum to one.

  • If strict is true, missing keys cause an error; otherwise, a warning is issued.

Returns

  • rb::RiskBudget: A result object containing the normalised risk budget vector.

Examples

julia
julia> sets = AssetSets(; key = "nx", dict = Dict("nx" => ["A", "B", "C"], "group1" => ["A", "B"]));

julia> risk_budget_constraints(Dict("A" => 0.2, "group1" => 0.8), sets)
RiskBudget
  val ┴ Vector{Float64}: [0.41379310344827586, 0.41379310344827586, 0.17241379310344826]

Related

source
julia
risk_budget_constraints(rb::RiskBudgetEstimator, sets::AssetSets;
                        strict::Bool = false, kwargs...)

This method is a wrapper calling:

julia
risk_budget_constraints(rb.val, sets; strict = strict)

It is used for type stability and to provide a uniform interface for processing constraint estimators, as well as simplifying the use of multiple estimators simulatneously.

Related

source