No Risk: private API

PortfolioOptimisers.norisk_flag — Function
norisk_flag(r) -> Bool

Return true when r is a NoRisk, or a vector that holds at least one.

The test is any, not all, because of the hierarchical optimisers. HierarchicalRiskParity and HierarchicalEqualRiskContribution allocate by the inverse of a risk. The risk of NoRisk is zero, so one NoRisk can make a divisor zero even beside a real measure. HRP forms alpha = 1 - lrisk / (lrisk + rrisk), and HERC forms inv.(risk) ./ sum(inv.(risk)) for each measure.

The table gives the result for r = [NoRisk(), Variance()] over a 200×4 returns matrix, when no check refuses the vector.

ScalariserHRP weightsHERC weights
SumScalariserfiniteNaN
MinScalariserNaNNaN
MaxScalariserfinitefinite
LogSumExpScalariseran even splitNaN

MaxScalariser is the only scalariser that gives finite weights for both, because it can discard the zero term. HERC computes inv(0) = Inf and then Inf / Inf = NaN for each measure, before the scalariser combines the measures, so every other scalariser keeps the NaN. HRP fails under MinScalariser alone, where the combined risk is zero and alpha is 0 / 0. Under LogSumExpScalariser, alpha is near 0.5, so the split carries no information.

The hierarchical optimisers do not read settings.rke, so the type of a measure is the only signal there. A test with all accepts every NaN row of the table. The JuMP optimisers ask a different question, whether the :risk expression is zero, and zero_risk_expression_flag answers it.

Arguments

  • r: Risk measure or vector of risk measures.

Returns

  • Bool: true when r is or holds a NoRisk.

Related

source
PortfolioOptimisers.zero_risk_expression_flag — Function
zero_risk_expression_flag(r) -> Bool

Return true when the :risk expression of the model is zero.

The function tests the state of the expression, and not the type of a measure. Two cases give a zero expression, and the function returns true when either holds.

  1. A NoRisk measure is present, which norisk_flag tests with any. Here any is wider than the state: [NoRisk(), Variance()] gives a :risk that is not zero, and the function still returns true. So MinimumRisk and MaximumRatio refuse the pair, with a message that overstates the cause. A NoRisk beside a real measure has no use, so the refusal stays.
  2. Every measure sets settings.rke = false, so set_risk_expression! adds nothing to the expression. The test is all, because one measure that enters keeps the expression away from zero.

The two cases combine only because case 1 already covers the mixed vector. The return side tests all(isa NoRisk || !rke), which agrees with this function except at [NoRisk(), Variance()], where the return form is the accurate one. The return side has no case like case 1, so it must use the combined form. See zero_return_expression_flag.

The all of case 2 lets a measure bound the risk and stay out of the objective. This is the risk side of what set_return_bounds! does for the return:

r = [Variance(), Variance(; settings = RiskMeasureSettings(; rke = false, ub = u))]

The second measure bounds the risk by ub and does not enter the objective, and the function returns false.

Arguments

  • r: Risk measure or vector of risk measures.

Returns

  • Bool: true when the risk expression of r is zero.

Related

source
PortfolioOptimisers.zero_risk_expression_cause — Function
zero_risk_expression_cause(r) -> String

Return the cause of a zero risk expression, as a phrase for an error message.

The function names a NoRisk measure when norisk_flag is true. Otherwise it names the settings.rke = false of every measure. A caller calls it only after zero_risk_expression_flag returns true.

Arguments

  • r: Risk measure or vector of risk measures.

Returns

  • String: The cause, as a phrase that follows "but" or a colon in a sentence.

Related

source
PortfolioOptimisers.assert_risk_measure_required — Function
assert_risk_measure_required(r, T::Symbol; flag)

Check that r gives a risk expression that is not zero, for an optimiser that is built on its risk.

Only MeanRisk can use a zero risk expression, under an objective that does not read it. Every other optimiser that takes a risk measure depends on the risk. A risk budget has nothing to share, a risk contribution is zero, and a hierarchical optimiser divides by a zero risk. So these optimisers refuse the measure and do not return a degenerate result.

flag selects the test, because the two kinds of caller do not see the same cases.

The function skips a TimeDependent schedule, because assert_time_dependent_substitution checks each entry of the schedule.

Arguments

  • r: Risk measure or vector of risk measures.
  • T::Symbol: Name of the calling optimiser, for the error message.
  • flag: Test of a zero risk expression, norisk_flag or zero_risk_expression_flag.

Validation

Returns

  • nothing.

Related

source
PortfolioOptimisers.assert_no_risk_objective_compatibility — Function
assert_no_risk_objective_compatibility(r, obj)

Check that a zero risk expression comes with an objective that does not read the risk.

Under MinimumRisk a zero :risk makes the objective zero, so every feasible portfolio is optimal and the solver returns any one of them. Under MaximumRatio the row that fixes the risk of the ratio has no effect, and the model is unbounded. zero_risk_expression_flag decides whether the expression is zero, so the check covers a NoRisk measure and a vector whose every measure sets settings.rke = false.

The constructor of MeanRisk calls the function. It skips a TimeDependent schedule, because assert_time_dependent_substitution runs the constructor again on each entry of the schedule.

Arguments

  • r: Risk measure or vector of risk measures.
  • obj: Objective function of the optimiser.

Validation

Returns

  • nothing.

Related

source