Ratio Risk Measure
PortfolioOptimisers.RiskRatio — Type
struct RiskRatio{__T_r1, __T_r2} <: HierarchicalRiskMeasureMeasures the risk of r1 divided by the risk of r2, for a hierarchical optimiser.
r1 is the numerator and r2 is the denominator. Both sides are optimisation risk measures, so a hierarchical optimiser can use the ratio as its risk. The ratio follows IEEE division: a denominator of zero gives Inf or -Inf, and 0 / 0 gives NaN. bigger_is_better of the ratio is that of r1. The ratio is homogeneous of the degree of r1 minus the degree of r2. When the two degrees are equal, the contributions of risk_contribution sum to zero and not to the ratio.
Mathematical definition
\[\begin{align} \mathrm{RiskRatio}(\boldsymbol{x}) &= \frac{r_1(\boldsymbol{x})}{r_2(\boldsymbol{x})}\,. \end{align}\]
Where:
- $\mathrm{RiskRatio}(\boldsymbol{x})$: Risk ratio of the portfolio.
- $\boldsymbol{x}$: Portfolio returns vector $T \times 1$.
- $r_1$: Risk measure of the numerator.
- $r_2$: Risk measure of the denominator.
Fields
r1: First risk measure.
r2: Second risk measure.
Constructors
RiskRatio(; r1::OptimisationRiskMeasure = Variance(), r2::OptimisationRiskMeasure = ConditionalValueatRisk()) -> RiskRatioKeywords correspond to the struct's fields.
Propagated parameters
factory passes its arguments on to these @fprop fields:
Examples
julia> RiskRatio()RiskRatio r1 ┼ Variance │ settings ┼ RiskMeasureSettings │ │ scale ┼ Float64: 1.0 │ │ ub ┼ nothing │ │ rke ┴ Bool: true │ sigma ┼ nothing │ chol ┼ nothing │ rc ┼ nothing │ alg ┼ SquaredSOCRiskExpr() │ mtx_sqrt ┼ EigenFallbackSquareRoot() │ ratio_alg ┼ SquareRootRatio() │ corner ┴ nothing r2 ┼ ConditionalValueatRisk │ settings ┼ RiskMeasureSettings │ │ scale ┼ Float64: 1.0 │ │ ub ┼ nothing │ │ rke ┴ Bool: true │ alpha ┼ Float64: 0.05 │ w ┴ nothingOn a returns path whose Range is 0.625 and whose worst realisation is 0.25, the ratio is 2.5.
julia> RiskRatio(; r1 = Range(), r2 = WorstRealisation())([0.125, -0.25, 0.0625, -0.125, 0.375])2.5Related
PortfolioOptimisers.NonOptimisationRiskRatio — Type
struct NonOptimisationRiskRatio{__T_settings, __T_r1, __T_sca1, __T_r2, __T_sca2} <: NonOptimisationRiskMeasureMeasures the risk of r1 divided by the risk of r2, for analysis and for scoring.
No optimiser takes the ratio as an objective or as a constraint, so each side can be any base risk measure, such as MeanReturn, or a vector of them. r1 is the numerator and r2 is the denominator. The ratio follows IEEE division: a denominator of zero gives Inf or -Inf, and 0 / 0 gives NaN.
bigger_is_better of the ratio is that of r1, so a return over a risk is better when it is larger, and a risk over a return is better when it is smaller. A vector r1 must agree on its polarity. The ratio is homogeneous of the degree of r1 minus the degree of r2 when each side has one degree. When the two degrees are equal, the contributions of risk_contribution sum to zero and not to the ratio.
Mathematical definition
\[\begin{align} \mathrm{RiskRatio}(\boldsymbol{x}) &= \frac{S_1\left(r_1(\boldsymbol{x})\right)}{S_2\left(r_2(\boldsymbol{x})\right)}\,. \end{align}\]
Where:
- $\mathrm{RiskRatio}(\boldsymbol{x})$: Risk ratio of the portfolio.
- $\boldsymbol{x}$: Portfolio returns vector $T \times 1$.
- $r_1$: Risk measure of the numerator, or a vector of them.
- $r_2$: Risk measure of the denominator, or a vector of them.
- $S_1$, $S_2$: The scalarisers
sca1andsca2, which are the identity on a single measure.
Fields
settings: Risk measure settings.
r1: First risk measure, or a vector of them scalarised bysca1.
sca1: Scalariser combining the risk measures inr1into one number.nothinggives the sum ofSumScalariser. Inert whenr1holds a single measure.
r2: Second risk measure, or a vector of them scalarised bysca2.
sca2: Scalariser combining the risk measures inr2into one number.nothinggives the sum ofSumScalariser. Inert whenr2holds a single measure.
Constructors
NonOptimisationRiskRatio(; settings::HierarchicalRiskMeasureSettings = HierarchicalRiskMeasureSettings(), r1::BaseRM_VecBaseRM = Variance(), sca1::Option{<:Scalariser} = nothing, r2::BaseRM_VecBaseRM = ConditionalValueatRisk(), sca2::Option{<:Scalariser} = nothing) -> NonOptimisationRiskRatioKeywords correspond to the struct's fields.
Multiplicity
Each side takes one risk measure or a vector of them, and each side has its own scalariser. sca1 combines r1, and sca2 combines r2. Each scalariser field comes directly after the field that it combines, and the two scalarisers can differ.
The two fields take precedence over a sca keyword of the caller. The ratio does not pass that keyword to its sides, so its value always uses the scalarisers that the type holds.
Validation
- If
r1is a vector:!isempty(r1). - If
r2is a vector:!isempty(r2).
Propagated parameters
factory passes its arguments on to these @fprop fields:
Examples
julia> NonOptimisationRiskRatio()NonOptimisationRiskRatio settings ┼ HierarchicalRiskMeasureSettings │ scale ┴ Float64: 1.0 r1 ┼ Variance │ settings ┼ RiskMeasureSettings │ │ scale ┼ Float64: 1.0 │ │ ub ┼ nothing │ │ rke ┴ Bool: true │ sigma ┼ nothing │ chol ┼ nothing │ rc ┼ nothing │ alg ┼ SquaredSOCRiskExpr() │ mtx_sqrt ┼ EigenFallbackSquareRoot() │ ratio_alg ┼ SquareRootRatio() │ corner ┴ nothing sca1 ┼ nothing r2 ┼ ConditionalValueatRisk │ settings ┼ RiskMeasureSettings │ │ scale ┼ Float64: 1.0 │ │ ub ┼ nothing │ │ rke ┴ Bool: true │ alpha ┼ Float64: 0.05 │ w ┴ nothing sca2 ┴ nothingRelated
PortfolioOptimisers.factory — Method
factory(a, args...; kwargs...) -> a
factory(a::AbstractArray{<:Union{Nothing, AbstractEstimator, AbstractAlgorithm,
AbstractResult, StatsBase.CovarianceEstimator}},
args...; kwargs...) -> AbstractArrayRebuild an estimator, an algorithm or a result with runtime values. These two methods are the leaf and the array step of the traversal.
factory and port_opt_view are the two propagation mechanisms of this library. factory passes runtime values, such as prior moments, observation weights and previous portfolio weights, down a tree of composed structs. port_opt_view passes an index selection, a subset of the assets, down the same tree.
factory is a traversal, so it owns the identity on every leaf, as fmap in Functors.jl and adapt_structure in Adapt.jl do. A value that has no method of its own comes back with no change: a data field, a scalar, nothing, a set of observation weights and a covariance estimator of StatsBase. So a @propagatable struct sends each @fprop field to factory directly, whatever the field holds.
The array method is the one forwarding contract for every propagation field that holds an array of estimators, algorithms, results or covariance estimators. It applies factory to each element, and it forwards args... and kwargs... with no change. A family that accepts an array of them needs no method of its own. A family that needs more than the forward defines its own, more specific method. A concrete element type, through concrete_typed_array_if_abstract, is an example. An array of data, such as a vector of numbers, is a leaf, and it comes back with no change and with no copy.
Algorithm
The leaf method:
- Return
awith no change, and dropargs...andkwargs.... This method is the leaf of the recursion. Because of it, a call of the verb on a type with no tags returns the value and raises no error.
The array method:
- For each element
aiofa, callfactoryonai, and forwardargs...andkwargs...with no change. - Collect the results into a new array of the shape of
a, in the order ofa, and return it.
A @propagatable struct always has a generated method that is more specific than the leaf method. If the struct has at least one @fprop or @wprop field, that method builds the struct again with its keyword constructor. It sends each @fprop field through factory and each @wprop field through _wprop. If the struct has no such field, that method returns x.
The leaf method does not fill a nothing field. A weights field that must take the incoming weights when it holds nothing carries @wprop, and it goes to _wprop.
Arguments
a: Any value, which the leaf method returns with no change. For the array method, an array of estimators, algorithms, results, covariance estimators ornothing, which it rebuilds one element at a time.args...: Positional arguments. The leaf method ignores them, and the array method forwards them.kwargs...: Keyword arguments. The leaf method ignores them, and the array method forwards them.
Returns
a: The input with no change, for the leaf method.v::AbstractArray: The rebuilt elements, in an array of the shape ofa, for the array method.
Examples
julia> factory(nothing, 1, 2; x = 3)julia> factory([1.0, 2.0], 1, 2; x = 3)2-element Vector{Float64}: 1.0 2.0julia> factory(MeanValue())MeanValue w ┴ nothingRelated
PortfolioOptimisers.factory — Method
factory(a, args...; kwargs...) -> a
factory(a::AbstractArray{<:Union{Nothing, AbstractEstimator, AbstractAlgorithm,
AbstractResult, StatsBase.CovarianceEstimator}},
args...; kwargs...) -> AbstractArrayRebuild an estimator, an algorithm or a result with runtime values. These two methods are the leaf and the array step of the traversal.
factory and port_opt_view are the two propagation mechanisms of this library. factory passes runtime values, such as prior moments, observation weights and previous portfolio weights, down a tree of composed structs. port_opt_view passes an index selection, a subset of the assets, down the same tree.
factory is a traversal, so it owns the identity on every leaf, as fmap in Functors.jl and adapt_structure in Adapt.jl do. A value that has no method of its own comes back with no change: a data field, a scalar, nothing, a set of observation weights and a covariance estimator of StatsBase. So a @propagatable struct sends each @fprop field to factory directly, whatever the field holds.
The array method is the one forwarding contract for every propagation field that holds an array of estimators, algorithms, results or covariance estimators. It applies factory to each element, and it forwards args... and kwargs... with no change. A family that accepts an array of them needs no method of its own. A family that needs more than the forward defines its own, more specific method. A concrete element type, through concrete_typed_array_if_abstract, is an example. An array of data, such as a vector of numbers, is a leaf, and it comes back with no change and with no copy.
Algorithm
The leaf method:
- Return
awith no change, and dropargs...andkwargs.... This method is the leaf of the recursion. Because of it, a call of the verb on a type with no tags returns the value and raises no error.
The array method:
- For each element
aiofa, callfactoryonai, and forwardargs...andkwargs...with no change. - Collect the results into a new array of the shape of
a, in the order ofa, and return it.
A @propagatable struct always has a generated method that is more specific than the leaf method. If the struct has at least one @fprop or @wprop field, that method builds the struct again with its keyword constructor. It sends each @fprop field through factory and each @wprop field through _wprop. If the struct has no such field, that method returns x.
The leaf method does not fill a nothing field. A weights field that must take the incoming weights when it holds nothing carries @wprop, and it goes to _wprop.
Arguments
a: Any value, which the leaf method returns with no change. For the array method, an array of estimators, algorithms, results, covariance estimators ornothing, which it rebuilds one element at a time.args...: Positional arguments. The leaf method ignores them, and the array method forwards them.kwargs...: Keyword arguments. The leaf method ignores them, and the array method forwards them.
Returns
a: The input with no change, for the leaf method.v::AbstractArray: The rebuilt elements, in an array of the shape ofa, for the array method.
Examples
julia> factory(nothing, 1, 2; x = 3)julia> factory([1.0, 2.0], 1, 2; x = 3)2-element Vector{Float64}: 1.0 2.0julia> factory(MeanValue())MeanValue w ┴ nothingRelated
PortfolioOptimisers.factory — Method
factory(a, args...; kwargs...) -> a
factory(a::AbstractArray{<:Union{Nothing, AbstractEstimator, AbstractAlgorithm,
AbstractResult, StatsBase.CovarianceEstimator}},
args...; kwargs...) -> AbstractArrayRebuild an estimator, an algorithm or a result with runtime values. These two methods are the leaf and the array step of the traversal.
factory and port_opt_view are the two propagation mechanisms of this library. factory passes runtime values, such as prior moments, observation weights and previous portfolio weights, down a tree of composed structs. port_opt_view passes an index selection, a subset of the assets, down the same tree.
factory is a traversal, so it owns the identity on every leaf, as fmap in Functors.jl and adapt_structure in Adapt.jl do. A value that has no method of its own comes back with no change: a data field, a scalar, nothing, a set of observation weights and a covariance estimator of StatsBase. So a @propagatable struct sends each @fprop field to factory directly, whatever the field holds.
The array method is the one forwarding contract for every propagation field that holds an array of estimators, algorithms, results or covariance estimators. It applies factory to each element, and it forwards args... and kwargs... with no change. A family that accepts an array of them needs no method of its own. A family that needs more than the forward defines its own, more specific method. A concrete element type, through concrete_typed_array_if_abstract, is an example. An array of data, such as a vector of numbers, is a leaf, and it comes back with no change and with no copy.
Algorithm
The leaf method:
- Return
awith no change, and dropargs...andkwargs.... This method is the leaf of the recursion. Because of it, a call of the verb on a type with no tags returns the value and raises no error.
The array method:
- For each element
aiofa, callfactoryonai, and forwardargs...andkwargs...with no change. - Collect the results into a new array of the shape of
a, in the order ofa, and return it.
A @propagatable struct always has a generated method that is more specific than the leaf method. If the struct has at least one @fprop or @wprop field, that method builds the struct again with its keyword constructor. It sends each @fprop field through factory and each @wprop field through _wprop. If the struct has no such field, that method returns x.
The leaf method does not fill a nothing field. A weights field that must take the incoming weights when it holds nothing carries @wprop, and it goes to _wprop.
Arguments
a: Any value, which the leaf method returns with no change. For the array method, an array of estimators, algorithms, results, covariance estimators ornothing, which it rebuilds one element at a time.args...: Positional arguments. The leaf method ignores them, and the array method forwards them.kwargs...: Keyword arguments. The leaf method ignores them, and the array method forwards them.
Returns
a: The input with no change, for the leaf method.v::AbstractArray: The rebuilt elements, in an array of the shape ofa, for the array method.
Examples
julia> factory(nothing, 1, 2; x = 3)julia> factory([1.0, 2.0], 1, 2; x = 3)2-element Vector{Float64}: 1.0 2.0julia> factory(MeanValue())MeanValue w ┴ nothingRelated
PortfolioOptimisers.bigger_is_better — Method
bigger_is_better(r::Union{RiskRatio, NonOptimisationRiskRatio}) -> BoolReturn whether a larger value of the ratio r is better, which is the answer of its numerator r1.
The ratio grows with its numerator and falls with its denominator. So a return over a risk is better when it is larger, and a risk over a risk, or a risk over a return, is better when it is smaller. MeanReturnRiskRatio follows the same rule, and returns true. A vector r1 answers through the method for a vector, which throws an ArgumentError when its elements disagree.
Arguments
r: The ratio measure.
Validation
- When
r1is a vector, its elements agree onbigger_is_better.
Returns
Bool:bigger_is_better(r.r1).
Examples
julia> PortfolioOptimisers.bigger_is_better(NonOptimisationRiskRatio(; r1 = MeanReturn(), r2 = Variance()))truejulia> PortfolioOptimisers.bigger_is_better(NonOptimisationRiskRatio(; r1 = Variance(), r2 = MeanReturn()))falsejulia> PortfolioOptimisers.bigger_is_better(RiskRatio())falseRelated
PortfolioOptimisers.supports_precomputed_returns — Method
supports_precomputed_returns(
r::Union{NonOptimisationRiskRatio, RiskRatio}
) -> Any
Return whether RkRatioRM r supports evaluation on a precomputed return series.
Returns true only when both constituent risk measures support precomputed returns.
Related