Base Risk Measures
PortfolioOptimisers.RiskMeasure Type
abstract type RiskMeasure <: OptimisationRiskMeasureAbstract supertype for standard risk measures used in portfolio optimisation.
Subtype RiskMeasure to implement concrete risk measures that quantify portfolio risk and can be used as objectives or constraints in optimisation problems. This type ensures compatibility with the optimisation framework and enables composability with other estimators and algorithms.
Related
sourcePortfolioOptimisers.HierarchicalRiskMeasure Type
abstract type HierarchicalRiskMeasure <: OptimisationRiskMeasureAbstract supertype for hierarchical risk measures used in portfolio optimisation.
Subtype HierarchicalRiskMeasure to implement risk measures that operate on hierarchical or clustered portfolio structures. These measures are designed for use as objectives or constraints in optimisation problems that leverage asset clustering, hierarchical risk parity, or similar techniques.
Related
sourcePortfolioOptimisers.Frontier Type
struct Frontier{__T_N, __T_factor, __T_bound} <: AbstractAlgorithmDefines the number of points on the efficient frontier (Pareto Front).
Fields
N: Number of points on the efficient frontier.factor: Scaling factor for the efficient frontier range.bound: What operation needs to be performed on the risk lower bound.
Constructors
Frontier(;
N::Integer = 20,
bound::FrontierBoundEstimator = LinearBound()
) -> FrontierCreates a Frontier with N points, a scaling factor of 1, and the specified bound strategy. Used to set appropriate frontier bounds in variance_risk_bounds_val and second_moment_bound_val.
PortfolioOptimisers._Frontier(;
N::Integer = 20,
factor::Number,
bound::FrontierBoundEstimator
) -> FrontierInternal constructor. Keywords correspond to the struct's fields.
Validation
N > 0.isfinite(factor)andfactor > 0.
Examples
julia> Frontier(; N = 15)
Frontier
N ┼ Int64: 15
factor ┼ Int64: 1
bound ┴ LinearBound()Related
sourcePortfolioOptimisers.RiskMeasureSettings Type
struct RiskMeasureSettings{__T_scale, __T_ub, __T_rke} <: JuMPRiskMeasureSettingsSettings type for configuring risk measure estimators in PortfolioOptimisers.jl. Encapsulates scaling, upper bounds, and risk evaluation flags for risk measures used in optimisation routines.
Fields
scale: Scaling factor applied to the risk measure.ub: Upper bound(s) for the risk measure. Can be a scalar, vector, orFrontier.rke: Whether to include the risk measure value in theJuMPrisk expression.
Constructors
RiskMeasureSettings(;
scale::Number = 1.0,
ub::Option{<:RkRtBounds} = nothing,
rke::Bool = true,
) -> RiskMeasureSettingsCreates a RiskMeasureSettings instance with the specified scale, upper bound, and risk evaluation flag.
Validation
isfinite(scale).ubis validated withassert_nonempty_nonneg_finite_val.
Examples
julia> RiskMeasureSettings()
RiskMeasureSettings
scale ┼ Float64: 1.0
ub ┼ nothing
rke ┴ Bool: trueRelated
sourcePortfolioOptimisers.HierarchicalRiskMeasureSettings Type
struct HierarchicalRiskMeasureSettings{__T_scale} <: AbstractRiskMeasureSettingsSettings type for configuring hierarchical risk measure estimators in PortfolioOptimisers.jl.
Used for HierarchicalRiskMeasure, where it is impossible to set a risk upper bound.
Fields
scale: Scaling factor applied to the risk measure.
Constructors
HierarchicalRiskMeasureSettings(;
scale::Number,
) -> HierarchicalRiskMeasureSettingsCreates a HierarchicalRiskMeasureSettings instance with the specified scaling factor.
Validation
scalemust be finite.
Examples
julia> HierarchicalRiskMeasureSettings()
HierarchicalRiskMeasureSettings
scale ┴ Float64: 1.0Related
sourcePortfolioOptimisers.SumScalariser Type
struct SumScalariser <: NonHierarchicalScalariserScalariser that combines multiple risk measures using a weighted sum.
SumScalariser aggregates a vector of risk measures by computing the weighted sum of their scaled values. The weights are specified in the scale field of RiskMeasureSettings or HierarchicalRiskMeasureSettings. This scalarisation strategy is used in portfolio optimisation routines that require a single risk value from multiple risk measures.
Where:
: Number of risk measures. : Subscript denoting the i-th risk measure.: i-th risk measure value.: Weight of the i-th risk measure.
Related
PortfolioOptimisers.MaxScalariser Type
struct MaxScalariser <: NonHierarchicalScalariserScalariser that selects the risk expression whose scaled value is the largest.
MaxScalariser aggregates a vector of risk measures by selecting the maximum of their scaled values. The weights are specified in the scale field of RiskMeasureSettings or HierarchicalRiskMeasureSettings. In clustering optimisations, the risk of each cluster is computed separately, so there is no coherence in which risk measure is chosen between clusters.
Where:
: Number of risk measures. : Subscript denoting the i-th risk measure.: i-th risk measure value.: Weight of the i-th risk measure.
Related
PortfolioOptimisers.MinScalariser Type
struct MinScalariser <: HierarchicalScalariserScalariser that selects the risk expression whose scaled value is the largest.
MinScalariser aggregates a vector of risk measures by selecting the minimum of their scaled values. The weights are specified in the scale field of RiskMeasureSettings or HierarchicalRiskMeasureSettings. In clustering optimisations, the risk of each cluster is computed separately, so there is no coherence in which risk measure is chosen between clusters.
Where:
: Number of risk measures. : Subscript denoting the i-th risk measure.: i-th risk measure value.: Weight of the i-th risk measure.
Related
PortfolioOptimisers.LogSumExpScalariser Type
struct LogSumExpScalariser{__T_gamma} <: NonHierarchicalScalariserScalariser that aggregates multiple risk measures using the log-sum-exp function.
LogSumExpScalariser combines a vector of risk measures by applying the log-sum-exp transformation to their scaled values. The weights are specified in the scale field of RiskMeasureSettings or HierarchicalRiskMeasureSettings.
The parameter gamma controls the approximation accuracy to the maximum function: as gamma → 0, the function approaches the weighted sum; as gamma → ∞, it approaches the maximum. This behaviour is only true in JuMP-based optimisations. In clustering optimisations, each cluster's risk is computed separately, so there is no coherence between clusters.
Where:
: Number of risk measures. : Subscript denoting the i-th risk measure.: i-th risk measure value.: Weight of the i-th risk measure.: Positive parameter controlling the interpolation between the weighted sum and the maximum functions.
Fields
gamma: Log-sum-exp scalariser smoothing parameter.
Constructors
LogSumExpScalariser(;
gamma::Number = 1.0,
) -> LogSumExpScalariserKeywords correspond to the struct's fields.
Validation
gamma > 0.
Examples
julia> LogSumExpScalariser()
LogSumExpScalariser
gamma ┴ Float64: 1.0Related
sourcePortfolioOptimisers.AbstractBaseRiskMeasure Type
abstract type AbstractBaseRiskMeasure <: AbstractEstimatorAbstract supertype for all risk measure estimators in PortfolioOptimisers.jl.
Defines the interface for risk measure types, which quantify portfolio risk using various statistical or econometric methods. All concrete risk measure types should subtype AbstractBaseRiskMeasure to ensure consistency and composability within the optimisation framework.
All concrete risk measures can be used as functors (callable structs) to compute their associated risk quantity.
Related
sourcePortfolioOptimisers.NonOptimisationRiskMeasure Type
abstract type NonOptimisationRiskMeasure <: AbstractBaseRiskMeasureAbstract supertype for risk measures that are not intended for use in portfolio optimisation routines.
These risk measures are typically used for analysis, reporting, or diagnostics, and are not designed to be included as objectives or constraints in optimisation problems. Subtype this when implementing a risk measure that should not be selectable by optimisation algorithms.
Related
sourcePortfolioOptimisers.OptimisationRiskMeasure Type
abstract type OptimisationRiskMeasure <: AbstractBaseRiskMeasureAbstract supertype for risk measures that are intended for use in portfolio optimisation routines.
All concrete risk measures that can be used as objectives or constraints in optimisation problems should subtype OptimisationRiskMeasure. This ensures compatibility with the optimisation framework and enables composability with other estimators and algorithms.
Related
sourcePortfolioOptimisers.AbstractRiskMeasureSettings Type
abstract type AbstractRiskMeasureSettings <: AbstractEstimatorAbstract supertype for all risk measure settings in PortfolioOptimisers.jl.
Defines the interface for settings types that configure the behavior of risk measure estimators. All concrete risk measure settings types should subtype AbstractRiskMeasureSettings to ensure consistency and composability within the optimisation framework.
Related
sourcePortfolioOptimisers.JuMPRiskMeasureSettings Type
abstract type JuMPRiskMeasureSettings <: AbstractRiskMeasureSettingsAbstract supertype for risk measure settings used in JuMP-based optimisation routines.
All concrete settings types compatible with JuMP optimisation (e.g. RiskMeasureSettings, MaxRiskMeasureSettings) should subtype JuMPRiskMeasureSettings.
Related
sourcePortfolioOptimisers.FrontierBoundEstimator Type
abstract type FrontierBoundEstimator <: AbstractEstimatorAbstract supertype for bound-transformation strategies applied to efficient frontier bounds.
Concrete subtypes control how numeric bound values are transformed before being applied to JuMP risk expressions. All subtypes should subtype FrontierBoundEstimator.
Related
sourcePortfolioOptimisers.LinearBound Type
struct LinearBound <: FrontierBoundEstimatorPasses bound values through unchanged (identity transformation).
Used when the risk expression and the user-supplied bound are already in the same units (e.g. SDP variance formulation where both sides are in variance units).
Related
sourcePortfolioOptimisers.SquareRootBound Type
struct SquareRootBound <: FrontierBoundEstimatorApplies a square-root transformation to bound values before enforcing them.
Used when the risk expression is in standard-deviation units but the user-supplied bound is in variance units (e.g. kurtosis and negative-skewness SOC formulations).
Related
sourcePortfolioOptimisers.SquaredBound Type
struct SquaredBound <: FrontierBoundEstimatorApplies a squaring transformation to bound values before enforcing them.
Used when the risk expression is in squared units but the user-supplied bound is in linear units (e.g. kurtosis SDP formulation).
Related
sourcePortfolioOptimisers.Scalariser Type
abstract type Scalariser <: AbstractEstimatorAbstract supertype for scalarisation strategies used to combine multiple risk measures into a single scalar value for optimisation.
Subtype Scalariser to implement different methods for aggregating risk measures. These strategies are used in portfolio optimisation routines that require a single risk value from multiple risk measures.
Related
sourcePortfolioOptimisers.NonHierarchicalScalariser Type
abstract type NonHierarchicalScalariser <: ScalariserAbstract supertype for scalarisation strategies that combine multiple risk measures into a single scalar value compatible with all portfolio optimisation estimators.
Subtype NonHierarchicalScalariser to implement aggregation methods that work with all optimisation estimators.
Related
sourcePortfolioOptimisers.HierarchicalScalariser Type
abstract type HierarchicalScalariser <: ScalariserAbstract supertype for scalarisation strategies that combine multiple risk measures into a single scalar value compatible only with hierarchical optimisations.
Subtype HierarchicalScalariser to implement aggregation methods that only work with hierarchical optimisation estimators.
Related
sourcePortfolioOptimisers.nothing_scalar_array_selector Function
nothing_scalar_array_selector(risk_variable::Nothing, prior_variable::Nothing)
nothing_scalar_array_selector(risk_variable::Num_ArrNum_VecScalar_DynWeights, ::Any)
nothing_scalar_array_selector(risk_variable::Nothing, prior_variable::Num_ArrNum_VecScalar_DynWeights)Function for selecting a non-nothing value when provided by a risk measure, or fall back to a value contained in a prior result
Arguments
risk_variable: The risk-side input.prior_variable: The prior-side input.
Returns
If both inputs are
nothingreturnsnothing.If
risk_variableis notnothing, returnsrisk_variable.If
risk_variableisnothingandprior_variableis notnothing, returnsprior_variable.
PortfolioOptimisers.risk_measure_nothing_scalar_array_view Function
risk_measure_nothing_scalar_array_view(risk_variable, prior_variable, i)Get a view of a risk measure's risk or prior variable for index i.
Internal helper for slicing scalar, array, or nothing risk/prior variables by index. Dispatches on the types of risk_variable and prior_variable.
Arguments
risk_variable: Risk variable (scalar, array, ornothing).prior_variable: Prior variable (array ornothing).i: Index or range to slice.
Returns
- Sliced or unchanged value.
Related
sourcePortfolioOptimisers.solver_selector Function
solver_selector(risk_solvers, slv)Select the appropriate solver for a risk measure computation.
Returns the risk-measure-specific solver if provided, otherwise falls back to the optimiser-level solver. Returns nothing if neither is available.
Arguments
risk_solvers: Risk-measure-specific solver(s) ornothing.slv: Optimiser-level solver(s) ornothing.
Returns
- Selected solver(s) or
nothing.
Related
sourcePortfolioOptimisers.VecBaseRM Type
const VecBaseRM = AbstractVector{<:AbstractBaseRiskMeasure}Alias for an abstract vector of AbstractBaseRiskMeasure elements.
Related
sourcePortfolioOptimisers.VecOptRM Type
const VecOptRM = AbstractVector{<:OptimisationRiskMeasure}Alias for an abstract vector of OptimisationRiskMeasure elements.
Related
sourcePortfolioOptimisers.OptRM_VecOptRM Type
const OptRM_VecOptRM = Union{<:OptimisationRiskMeasure, <:VecOptRM}Union type accepting a single OptimisationRiskMeasure or a vector of them.
Related
sourcePortfolioOptimisers.VecRM Type
const VecRM = AbstractVector{<:RiskMeasure}Alias for an abstract vector of RiskMeasure elements.
Related
sourcePortfolioOptimisers.RM_VecRM Type
const RM_VecRM = Union{<:RiskMeasure, <:VecRM}Union type accepting a single RiskMeasure or a vector of them.
Related
sourcePortfolioOptimisers.RkRtBounds Type
const RkRtBounds = Union{<:Num_VecNum, <:Frontier}Union type for risk-measure upper bound specifications.
Accepts either a scalar/vector numeric bound or a Frontier sweep configuration. Used in RiskMeasureSettings to set the upper bound field.
Related
sourcePortfolioOptimisers.Front_NumVec Type
const Front_NumVec = Union{<:VecNum, <:Frontier}Union type for frontier or numeric-vector specifications used internally for risk bounds.
Related
sourcePortfolioOptimisers.bigger_is_better Function
bigger_is_better(r::AbstractBaseRiskMeasure) -> BoolReturn whether a larger value of risk measure r is preferred over a smaller one.
The default implementation returns false (lower risk is better) for all AbstractBaseRiskMeasure subtypes. Ratio-based or return-like measures that should be maximised may override this method to return true.
Returns
Bool:trueif a higher value ofris preferred;falseotherwise.
Related
sourcebigger_is_better(_::Skewness) -> BoolReturn true because higher skewness is preferred over lower skewness.
Related
sourcePortfolioOptimisers.needs_previous_weights Method
needs_previous_weights(r::AbstractBaseRiskMeasure) -> Bool
needs_previous_weights(r::VecBaseRM) -> BoolReturn whether risk measure r requires previous portfolio weights as input.
The default returns false. Override to true for risk measures such as turnover or tracking constraints that depend on prior weights. The VecBaseRM overload returns true if any element returns true.
Returns
Bool:trueif prior weights are required;falseotherwise.
Related
sourcePortfolioOptimisers.RiskInputKind Type
abstract type RiskInputKindAbstract supertype for the input-shape classification of a risk measure, used by expected_risk to decide what to feed a measure's functor.
Each concrete AbstractBaseRiskMeasure declares its kind via risk_input_kind. The three kinds correspond to the three functor call shapes:
NetReturnsInput:r(calc_net_returns(w, X, fees)).WeightsReturnsFeesInput:r(w, X, fees).WeightsInput:r(w).
Related
sourcePortfolioOptimisers.NetReturnsInput Type
struct NetReturnsInput <: RiskInputKindInput kind for risk measures whose expected risk is computed on net returns (returns after fees). The measure's functor is called as r(calc_net_returns(w, X, fees)).
Related
sourcePortfolioOptimisers.WeightsReturnsFeesInput Type
struct WeightsReturnsFeesInput <: RiskInputKindInput kind for risk measures whose expected risk depends on weights, the returns matrix, and fees. The measure's functor is called as r(w, X, fees).
Related
sourcePortfolioOptimisers.WeightsInput Type
struct WeightsInput <: RiskInputKindInput kind for risk measures whose expected risk depends only on portfolio weights. The measure's functor is called as r(w).
Related
sourcePortfolioOptimisers.risk_input_kind Function
risk_input_kind(r::AbstractBaseRiskMeasure) -> RiskInputKindReturn the RiskInputKind of risk measure r, declaring what its functor consumes when expected_risk evaluates it.
There is no default: every concrete AbstractBaseRiskMeasure (other than composite measures handled by explicit expected_risk methods) must declare its kind beside its type definition. Returning one of NetReturnsInput, WeightsReturnsFeesInput, or WeightsInput. An undeclared measure throws, rather than silently routing to the wrong input shape.
Returns
RiskInputKind: the declared input kind.
Related
sourcePortfolioOptimisers.supports_precomputed_returns Method
supports_precomputed_returns(r::AbstractBaseRiskMeasure) -> Bool
supports_precomputed_returns(rk::RiskInputKind, r::AbstractBaseRiskMeasure) -> BoolWhether risk measure r has a well-defined precomputed-returns form — i.e. whether its expected risk can be evaluated on an already-reduced net-return series x alone, via the functor r(x::VecNum) (ADR 0007).
The contract is well-defined exactly when the measure's result is a function of the series alone:
NetReturnsInputmeasures (quantile / drawdown families): alwaystrue— their functor is the net-returns functor.The moment family (
LowOrderMoment,HighOrderMoment,Skewness,Kurtosis,MedianAbsoluteDeviation,ThirdCentralMoment):trueiff its target is weight-independent (muisnothing, a scalar, or a centering function); a per-assetmu(VecNum/VecScalar) reduces asdot(w, mu)and needs the weights the series no longer carries, sofalse.WeightsInputmeasures, tracking measures, and variance-carrying composites (VarianceSkewKurtosis):false— "risk of a bare return series" is undefined for them.
This predicate is what makes the precomputed-returns contract safe. Because a WeightsInput measure's functor r(w) shares the r(::VecNum) signature with the contract, dispatch alone cannot distinguish weights from returns; expected_risk_from_returns consults this predicate and throws an explanatory error for ineligible measures rather than silently consuming the series as weights.
Related
sourcePortfolioOptimisers.supports_precomputed_returns Method
supports_precomputed_returns(_::NetReturnsInput, _) -> BoolReturn true: NetReturnsInput measures always support precomputed returns — their functor is the net-returns functor.
Related
sourcePortfolioOptimisers.supports_precomputed_returns Method
supports_precomputed_returns(_::WeightsInput, _) -> BoolReturn false: WeightsInput measures never support precomputed returns — their functor consumes portfolio weights, not a return series.
Related
sourcePortfolioOptimisers.supports_precomputed_returns Method
supports_precomputed_returns(
_::WeightsReturnsFeesInput,
r::AbstractBaseRiskMeasure
)Erroring tripwire for WeightsReturnsFeesInput measures that have not declared supports_precomputed_returns at their own definition site. Every such measure must declare it there: moment measures as supports_precomputed_returns(r::T) = weight_independent_target(r.mu); weights-dependent measures (tracking, variance-carrying composites) as supports_precomputed_returns(::T) = false. Reaching this leaf means a measure forgot to declare it — throws an ArgumentError with instructions rather than silently mis-routing (and the completeness test in test_09c_risk_input_kind.jl turns that into a CI failure).
Related
sourcePortfolioOptimisers.weight_independent_target Method
weight_independent_target(_::Nothing) -> BoolReturn true: a Nothing target is trivially weight-independent and can be evaluated on a bare return series.
Related
sourcePortfolioOptimisers.weight_independent_target Method
weight_independent_target(_::Number) -> BoolReturn true: a scalar target does not require portfolio weights and can be evaluated on a bare return series.
Related
sourcePortfolioOptimisers.weight_independent_target Method
weight_independent_target(_) -> BoolReturn false: the target type requires portfolio weights (e.g. a per-asset mu involves dot(w, mu)) and cannot be evaluated on a bare return series.
Related
sourcePortfolioOptimisers.factory Method
factory(
rs::AbstractBaseRiskMeasure,
args...;
kwargs...
) -> ConditionalValueatRiskRange{RiskMeasureSettings{__T_scale, __T_ub, __T_rke}, <:Number, <:Number} where {__T_scale, __T_ub, __T_rke}Return the risk measure rs unchanged.
Identity pass-through used when a risk measure is provided in a context that calls factory.
Related
sourcePortfolioOptimisers.factory Method
factory(
rs::AbstractVector{<:AbstractBaseRiskMeasure},
args...;
kwargs...
) -> AnyReturn a new vector of risk measures with factory applied element-wise.
Related
sourcePortfolioOptimisers.port_opt_view Method
port_opt_view(rs, i, X)Get a view or subset of a risk measure for asset cluster index i.
Returns the risk measure sliced for the given cluster or asset index. Used internally in hierarchical optimisation to apply risk measures to each cluster.
Arguments
rs: Risk measure (or vector thereof).i: Cluster or asset index.X: Data matrix (used for dimension-aware slicing).
Returns
- Sliced risk measure or the original if no slicing is needed.
Related
sourcePortfolioOptimisers._Frontier Function
_Frontier(; N = 20, factor, bound)Construct a range of N evenly-spaced frontier parameter values.
Internal helper that generates a parameter grid (e.g., for risk bounds) used when sweeping the efficient frontier.
Arguments
N: Number of frontier points (default 20).factor: Scaling factor for the range.bound: Controls whether to sweep from min-to-max or max-to-min.
Returns
- Vector of frontier parameter values.
Related
source