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.
| Scalariser | HRP weights | HERC weights |
|---|---|---|
SumScalariser | finite | NaN |
MinScalariser | NaN | NaN |
MaxScalariser | finite | finite |
LogSumExpScalariser | an even split | NaN |
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:truewhenris or holds aNoRisk.
Related
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.
- A
NoRiskmeasure is present, whichnorisk_flagtests withany. Hereanyis wider than the state:[NoRisk(), Variance()]gives a:riskthat is not zero, and the function still returnstrue. SoMinimumRiskandMaximumRatiorefuse the pair, with a message that overstates the cause. ANoRiskbeside a real measure has no use, so the refusal stays. - Every measure sets
settings.rke = false, soset_risk_expression!adds nothing to the expression. The test isall, 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:truewhen the risk expression ofris zero.
Related
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
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.
RiskBudgeting,FactorRiskContributionandNearOptimalCenteringpasszero_risk_expression_flag. It covers aNoRiskmeasure and a vector whose every measure setssettings.rke = false.HierarchicalRiskParityandHierarchicalEqualRiskContributionkeep the defaultnorisk_flag. They do not build a JuMP risk expression, so they do not readrke, and the wider test refuses a measure that they use correctly.
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_flagorzero_risk_expression_flag.
Validation
!flag(r). A failure throws anArgumentErrorthat namesTand the cause fromzero_risk_expression_cause.
Returns
nothing.
Related
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
- When
zero_risk_expression_flagistrue:!isa(obj, MinimumRisk)and!isa(obj, MaximumRatio). A failure throws anArgumentErrorwhose message names the cause fromzero_risk_expression_cause.
Returns
nothing.
Related