Ratio Risk Measure

PortfolioOptimisers.RiskRatio — Type
struct RiskRatio{__T_r1, __T_r2} <: HierarchicalRiskMeasure

Measures 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()) -> RiskRatio

Keywords correspond to the struct's fields.

Propagated parameters

factory passes its arguments on to these @fprop fields:

  • r1: Recursively updated through factory.
  • r2: Recursively updated through factory.

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 ┴ nothing

On 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.5

Related

source
PortfolioOptimisers.NonOptimisationRiskRatio — Type
struct NonOptimisationRiskRatio{__T_settings, __T_r1, __T_sca1, __T_r2, __T_sca2} <: NonOptimisationRiskMeasure

Measures 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 sca1 and sca2, which are the identity on a single measure.

Fields

  • settings: Risk measure settings.
  • r1: First risk measure, or a vector of them scalarised by sca1.
  • sca1: Scalariser combining the risk measures in r1 into one number. nothing gives the sum of SumScalariser. Inert when r1 holds a single measure.
  • r2: Second risk measure, or a vector of them scalarised by sca2.
  • sca2: Scalariser combining the risk measures in r2 into one number. nothing gives the sum of SumScalariser. Inert when r2 holds a single measure.

Constructors

NonOptimisationRiskRatio(;    settings::HierarchicalRiskMeasureSettings = HierarchicalRiskMeasureSettings(),    r1::BaseRM_VecBaseRM = Variance(),    sca1::Option{<:Scalariser} = nothing,    r2::BaseRM_VecBaseRM = ConditionalValueatRisk(),    sca2::Option{<:Scalariser} = nothing) -> NonOptimisationRiskRatio

Keywords 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 r1 is a vector: !isempty(r1).
  • If r2 is a vector: !isempty(r2).

Propagated parameters

factory passes its arguments on to these @fprop fields:

  • r1: Recursively updated through factory.
  • r2: Recursively updated through factory.

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 ┴ nothing

Related

source
PortfolioOptimisers.factory — Method
factory(a, args...; kwargs...) -> a
factory(a::AbstractArray{<:Union{Nothing, AbstractEstimator, AbstractAlgorithm,
                                 AbstractResult, StatsBase.CovarianceEstimator}},
        args...; kwargs...) -> AbstractArray

Rebuild 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:

  1. Return a with no change, and drop args... and kwargs.... 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:

  1. For each element ai of a, call factory on ai, and forward args... and kwargs... with no change.
  2. Collect the results into a new array of the shape of a, in the order of a, 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 or nothing, 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 of a, 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 ┴ nothing

Related

source
PortfolioOptimisers.factory — Method
factory(a, args...; kwargs...) -> a
factory(a::AbstractArray{<:Union{Nothing, AbstractEstimator, AbstractAlgorithm,
                                 AbstractResult, StatsBase.CovarianceEstimator}},
        args...; kwargs...) -> AbstractArray

Rebuild 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:

  1. Return a with no change, and drop args... and kwargs.... 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:

  1. For each element ai of a, call factory on ai, and forward args... and kwargs... with no change.
  2. Collect the results into a new array of the shape of a, in the order of a, 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 or nothing, 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 of a, 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 ┴ nothing

Related

source
PortfolioOptimisers.factory — Method
factory(a, args...; kwargs...) -> a
factory(a::AbstractArray{<:Union{Nothing, AbstractEstimator, AbstractAlgorithm,
                                 AbstractResult, StatsBase.CovarianceEstimator}},
        args...; kwargs...) -> AbstractArray

Rebuild 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:

  1. Return a with no change, and drop args... and kwargs.... 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:

  1. For each element ai of a, call factory on ai, and forward args... and kwargs... with no change.
  2. Collect the results into a new array of the shape of a, in the order of a, 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 or nothing, 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 of a, 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 ┴ nothing

Related

source
PortfolioOptimisers.bigger_is_better — Method
bigger_is_better(r::Union{RiskRatio, NonOptimisationRiskRatio}) -> Bool

Return 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 r1 is a vector, its elements agree on bigger_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())false

Related

source