Adjust Risk Contributions: private API
PortfolioOptimisers.SquaredRiskMeasures — Type
const SquaredRiskMeasures = Union{Variance, BrownianDistanceVariance, UncertaintySetVariance,
LowOrderMoment{<:Any, <:Any, <:Any,
<:SecondMoment{<:Any, <:Any,
<:QuadSecondMomentFormulations}},
LowOrderMoment{<:Any, <:Any, <:Any, <:EvenMoment},
Kurtosis{<:Any, <:Any, <:Any, <:SOCRiskExpr},
NegativeSkewness{<:Any, <:Any, <:Any, <:Any,
<:NSkeQuadFormulations},
TrackingRiskMeasure{<:Any, <:Any, <:SquaredL2Norm}}Union of the risk measures that are homogeneous of degree 2 in the portfolio weights. homogeneity_degree returns 2 for each member.
A member reports a squared quantity: a variance, a second moment, the square root of a fourth moment, or the square of a tracking error. EvenMoment of order $2p$ reports the $p$-th root of the moment, so it is a member for every $p$.
Related
PortfolioOptimisers.QuadExpressionRiskMeasures — Type
const QuadExpressionRiskMeasures = Union{Variance, BrownianDistanceVariance,
LowOrderMoment{<:Any, <:Any, <:Any,
<:SecondMoment{<:Any, <:Any,
<:QuadSecondMomentFormulations}},
NegativeSkewness{<:Any, <:Any, <:Any, <:Any,
<:NSkeQuadFormulations},
Kurtosis{<:Any, <:Any, <:Any,
<:QuadSecondMomentFormulations},
TrackingRiskMeasure{<:Any, <:Any, <:SquaredL2Norm}}Union of the risk measures whose risk expression in a JuMP model is quadratic in the weights.
The tracking constraint of a dependent variable and the near-optimal centering read the union, because a quadratic expression needs a different encoding there than an affine one.
Related
PortfolioOptimisers.CubedRiskMeasures — Type
const CubedRiskMeasures = Union{Skewness, ThirdCentralMoment{<:Any, <:Any, <:Any, Nothing},
HighOrderMoment{<:Any, <:Any, <:Any, <:ThirdLowerMoment,
Nothing}}Union of the risk measures that are homogeneous of degree 3 in the portfolio weights. homogeneity_degree returns 3 for each member.
A member reports a raw third moment. The standardised third moments, of a HighOrderMoment and of a ThirdCentralMoment with a variance estimator in ve, divide by the cube of a standard deviation, so they are members of ScaleFreeRiskMeasures and not of this union.
Related
PortfolioOptimisers.FourthPowerRiskMeasures — Type
const FourthPowerRiskMeasures = Union{HighOrderMoment{<:Any, <:Any, <:Any, <:FourthMoment,
Nothing},
Kurtosis{<:Any, <:Any, <:Any,
<:QuadSecondMomentFormulations}}Union of the risk measures that are homogeneous of degree 4 in the portfolio weights. homogeneity_degree returns 4 for each member.
A member reports a raw fourth moment. Kurtosis under SOCRiskExpr reports the square root of the moment, so it is a member of SquaredRiskMeasures. A HighOrderMoment with a variance estimator in ve reports the standardised fourth moment, so it is a member of ScaleFreeRiskMeasures.
Related
PortfolioOptimisers.ScaleFreeRiskMeasures — Type
const ScaleFreeRiskMeasures = Union{EqualRisk,
ThirdCentralMoment{<:Any, <:Any, <:Any,
<:AbstractVarianceEstimator},
HighOrderMoment{<:Any, <:Any, <:Any, <:Any,
<:AbstractVarianceEstimator}}Union of the risk measures that are homogeneous of degree 0 in the portfolio weights. homogeneity_degree returns 0 for each member.
A member does not change when every weight is multiplied by the same positive number. EqualRisk reads only the length of the weights, and a standardised moment divides by a power of the standard deviation of the same degree. So the risk contributions of a member sum to zero, and not to its risk. The contributions of EqualRisk are each zero, because its risk does not depend on the weights at all.
Related
PortfolioOptimisers.RelativeDrawdownRiskMeasures — Type
const RelativeDrawdownRiskMeasures = Union{RelativeAverageDrawdown,
RelativeConditionalDrawdownatRisk,
RelativeDrawdownatRisk,
RelativeEntropicDrawdownatRisk,
RelativeMaximumDrawdown,
RelativePowerNormDrawdownatRisk,
RelativeRelativisticDrawdownatRisk,
RelativeUlcerIndex}Union of the risk measures of the drawdowns of the compounded cumulative returns. homogeneity_degree returns nothing for each member.
The compounded wealth $\prod_{t} (1 + \boldsymbol{x}_t^{\intercal} \boldsymbol{w})$ is not homogeneous in the weights, so no member has a degree. The measure of the drawdowns of the uncompounded cumulative returns, such as MaximumDrawdown, has degree 1.
Related
PortfolioOptimisers.ShiftInvariantRiskMeasures — Type
const ShiftInvariantRiskMeasures = Union{Range, BrownianDistanceVariance,
ValueatRiskRange, ConditionalValueatRiskRange,
DistributionallyRobustConditionalValueatRiskRange,
EntropicValueatRiskRange,
RelativisticValueatRiskRange,
PowerNormValueatRiskRange}Union of the risk measures whose risk does not change when the same number is added to each net return. cancels_constant_fee returns true for each member.
A range is the sum of the risk of the losses and the risk of the gains. Each tail moves by the number with an opposite sign, so the sum does not move. The distance variance of BrownianDistanceVariance reads only the differences between two returns. A fee that every period pays in the same amount is such a number, so it cancels from the risk of a member.
Related
PortfolioOptimisers.homogeneity_degree — Function
homogeneity_degree(r::AbstractBaseRiskMeasure, fees::Option{<:Fees} = nothing,
T::Option{<:Integer} = nothing) -> Option{<:Integer}Return the degree of homogeneity of the risk measure r in the portfolio weights, under the fees fees on T observations, or nothing when r has no degree.
adjust_risk_contribution divides a risk by this degree, so that the risk contributions of risk_contribution sum to the risk. A measure that no other method names has degree 1, unless it measures a distance to a fixed target that is not zero. has_fixed_target finds such a target, and the measure then has no degree, because $|x - c|$ with a fixed $c \neq 0$ is not homogeneous in $x$.
The degree is a property of the risk as a function of the weights, so it reads the fees that the risk pays. A fee that does not scale with the weights is a fixed target on the net returns. A turnover fee against previous weights that are not zero, a liquidation charge and a fixed fee are such fees, and has_fixed_fee finds them. A measure that reads the net returns then has no degree, unless the fee cancels from its risk. A proportional fee, and a turnover fee against zero weights, scale with the weights and keep the degree.
Whether a fee cancels from the risk of an OWA measure depends on the sum of its weights, and a weight builder gives the weights of the observation count. adjusted_risk passes the count T of its returns matrix. Without T, the sum of a builder is not known, and the fee does not cancel.
Mathematical definition
\[\begin{align} R(c \boldsymbol{w}) &= c^{d} R(\boldsymbol{w}) \quad \forall c > 0\,, \\ d\left(\frac{R_1}{R_2}\right) &= d(R_1) - d(R_2)\,. \end{align}\]
The second line gives the degree of a ratio of two homogeneous measures. A scalarised vector of measures has the degree of its elements when every element has the same degree, and the sum, the maximum and the minimum keep that degree.
Where:
- $R(\boldsymbol{w})$: Portfolio risk.
- $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
- $d$: Degree of homogeneity of the risk measure, the $d$ for which $R(c \boldsymbol{w}) = c^{d} R(\boldsymbol{w})$ at every $c > 0$.
- $R_1$, $R_2$: The risk measures of the numerator and of the denominator of a ratio.
Algorithm
- Return
nothingwhenhas_fixed_targetofr,feesandTistrue. This applies to steps 2 and 7. - Return
2for a member ofSquaredRiskMeasures,3for a member ofCubedRiskMeasures,4for a member ofFourthPowerRiskMeasures, and0for a member ofScaleFreeRiskMeasures. - For
RiskTrackingRiskMeasure, returnnothingwhen its benchmark is a fixed target. Otherwise return the degree of its measurerunderfeesandT. The benchmark weights are zero at this step, so the measure tracksritself on the same net returns. - For
RiskRatioandNonOptimisationRiskRatio, get the degree of each side underfeesandTwithscalarised_degree, and subtract the degree ofr2from the degree ofr1withdegree_difference. - For
MeanReturnRiskRatioandExpectedReturnRiskRatio, returnnothingwhenrfis not zero. Otherwise subtract the degree ofrkfrom the degree ofrt, in the same way. A return estimator does not readT.ExpectedReturnhas the degree of its return estimatorrt. - Return
nothingforVarianceSkewKurtosis, whose three terms have the degrees 2, 3 and 4, and for a member ofRelativeDrawdownRiskMeasures. - Return
1for every other measure.
Arguments
r: Risk measure or vector of risk measures.fees: The fees that the risk pays, ornothing.T: The number of observations of the net returns, ornothingwhen it is not known.
Returns
d::Option{<:Integer}: The degree of homogeneity, ornothingwhenris not homogeneous.
Examples
julia> PortfolioOptimisers.homogeneity_degree(Variance())2julia> PortfolioOptimisers.homogeneity_degree(ConditionalValueatRisk())1julia> PortfolioOptimisers.homogeneity_degree(NonOptimisationRiskRatio(; r1 = ConditionalValueatRisk(), r2 = Variance()))-1julia> PortfolioOptimisers.homogeneity_degree(EqualRisk())0julia> PortfolioOptimisers.homogeneity_degree(LowOrderMoment(; mu = 0.01))julia> PortfolioOptimisers.homogeneity_degree(TurnoverRiskMeasure(; w = [0.5, 0.5]))julia> PortfolioOptimisers.homogeneity_degree(TurnoverRiskMeasure(; w = [0.0, 0.0]))1julia> fees = Fees(; tn = Turnover(; w = [0.5, 0.5], val = 0.001));julia> PortfolioOptimisers.homogeneity_degree(LowOrderMoment(; mu = 0.0), fees)julia> PortfolioOptimisers.homogeneity_degree(LowOrderMoment(), fees)1julia> r = RiskRatio(; r1 = OrderedWeightsArray(), r2 = Variance());julia> PortfolioOptimisers.homogeneity_degree(r, fees), PortfolioOptimisers.homogeneity_degree(r, fees, 200)(nothing, -1)Related
homogeneity_degree(rt::JuMPReturnsEstimator, fees::Option{<:Fees} = nothing) -> Option{<:Integer}
homogeneity_degree(rt::VecJRE, fees::Option{<:Fees} = nothing) -> Option{<:Integer}
homogeneity_degree(r::ExpectedReturn, fees::Option{<:Fees} = nothing,
T::Option{<:Integer} = nothing) -> Option{<:Integer}
homogeneity_degree(r::ExpectedReturnRiskRatio, fees::Option{<:Fees} = nothing,
T::Option{<:Integer} = nothing) -> Option{<:Integer}Return the degree of homogeneity of a return estimator in the portfolio weights, under the fees fees, and of the two measures that read one.
The arithmetic return $\boldsymbol{\mu}^{\intercal} \boldsymbol{w}$ has degree 1. The logarithmic return $\mathbb{E}[\log(1 + \boldsymbol{x}^{\intercal} \boldsymbol{w})]$ is not homogeneous, so it has no degree. A vector of return estimators sums its terms whose settings.rte is true, so it has no degree when one of those terms has none.
A term whose settings.fee is true subtracts the fees, through term_fees. A fee that does not scale with the weights, from has_fixed_fee, then takes the degree from the term. A constant shift moves the return, so no such fee cancels. NoReturn charges no fee.
Algorithm
- Return
nothingforLogarithmicReturn, and1forNoReturn. - For every other return estimator, return
nothingwhensettings.feeistrueandhas_fixed_feefinds a fee. Otherwise return1. - For a vector, return
nothingwhen a term whosesettings.rteistruehas no degree. Otherwise return1. - For
ExpectedReturn, return the degree ofrt. - For
ExpectedReturnRiskRatio, returnnothingwhenrfis not zero. Otherwise subtract the degree ofrk, fromscalarised_degree, from the degree ofrtwithdegree_difference.
Arguments
rt: Return estimator, or a vector of them.r: Risk measure or vector of risk measures.fees: The fees that the return pays, ornothing.T: The number of observations of the net returns, ornothingwhen it is not known. A return estimator does not read it, and the risk measurerkof a ratio does.
Returns
d::Option{<:Integer}: The degree of homogeneity, ornothing.
Examples
julia> PortfolioOptimisers.homogeneity_degree(ExpectedReturn(; rt = LogarithmicReturn()))julia> PortfolioOptimisers.homogeneity_degree(ExpectedReturn(), Fees(; fl = 0.001))julia> PortfolioOptimisers.homogeneity_degree(ExpectedReturnRiskRatio())-1julia> PortfolioOptimisers.homogeneity_degree(ExpectedReturnRiskRatio(; rk = StandardDeviation()))0Related
PortfolioOptimisers.has_fixed_target — Function
has_fixed_target(r::AbstractBaseRiskMeasure) -> Bool
has_fixed_target(r::AbstractBaseRiskMeasure, fees::Option{<:Fees},
T::Option{<:Integer} = nothing) -> Bool
has_fixed_target(target) -> BoolReturn true when the risk measure r measures a distance to a target that is not zero and does not scale with the portfolio weights.
Such a measure is not homogeneous in the weights, so homogeneity_degree gives it no degree. A target that scales with the weights, such as the expected portfolio return $\boldsymbol{\mu}^{\intercal} \boldsymbol{w}$, keeps the degree of the measure. The second form also reads the fees: a fee that does not scale with the weights moves the net returns by a fixed amount, so it is a fixed target of a measure that reads the net returns. The third form reads one target value. A Turnover fee is a distance to its previous weights.
Algorithm
- For a
LowOrderMoment, aHighOrderMoment, aThirdCentralMomentand aMedianAbsoluteDeviation, read the Moment Targetmu. A number is fixed when it is not zero. AVecScalaris fixed when its offsetsis not zero. - For a
TrackingRiskMeasureand aRiskTrackingRiskMeasure, read the benchmarktr. The weights of aWeightsTrackingand the series of aReturnsTrackingare fixed when they are not zero. A vectorBof aDataBenchmarkTrackingis fixed when it is not zero, and so is an unboundB, whose target is not known. A matrixBgives the series $\mathbf{B} \boldsymbol{w}$, which scales with the weights. - For a
TurnoverRiskMeasure, the reference weightsware fixed when they are not zero. - For a
Turnoverfee, the previous weightsware fixed when an asset whose rate is not zero has a previous weight that is not zero. - With
fees, returntruewhen step 1, 2 or 3 istrue. Otherwise returntruewhenrreads the fees,reads_fees, andhas_fixed_feefinds a fee that does not cancel from the risk ofronTobservations,cancels_constant_fee. - Return
falsefor every other measure and every other target value.
Arguments
r: Risk measure or vector of risk measures.fees: The fees that the risk pays, ornothing.T: The number of observations of the net returns, ornothingwhen it is not known.target: The target value of a measure.
Returns
flag::Bool:truewhen the target is fixed and not zero.
Examples
julia> PortfolioOptimisers.has_fixed_target(LowOrderMoment(; mu = 0.01))truejulia> PortfolioOptimisers.has_fixed_target(LowOrderMoment(; mu = [0.01, 0.02]))falsejulia> PortfolioOptimisers.has_fixed_target(TrackingRiskMeasure(; tr = WeightsTracking(; w = [0.5, 0.5])))truejulia> PortfolioOptimisers.has_fixed_target(ConditionalValueatRisk(), Fees(; fl = 0.001))truejulia> PortfolioOptimisers.has_fixed_target(Variance(), Fees(; fl = 0.001))falseRelated
PortfolioOptimisers.has_fixed_fee — Function
has_fixed_fee(fees::Option{<:Fees}, cancels::Bool) -> BoolReturn true when fees holds a fee that does not scale with the portfolio weights and that does not cancel from the risk of a measure.
A periodic fee falls on each observation. The term of a Turnover fee whose previous weights are not zero is such a fee, and so is the proportional liquidation charge lq, which does not read the weights at all. A one-off fee is a fixed fee fl or fs, or the fixed liquidation charge flq. It counts the positions, so it does not scale with the weights. The Fee Amortisation fa names its clock. AmortisedFees spreads it over each observation, so it is then a periodic fee. Otherwise it falls on the first observation alone.
A periodic fee moves each net return by the same amount, so it cancels from the risk of a measure that a constant shift does not change. cancels states that property of the measure, from cancels_constant_fee. A one-off fee on the first observation moves one return, and it cancels from no measure. A proportional fee l or s, and a turnover fee against zero weights, scale with the weights, so they are not fixed.
Algorithm
- Return
falsefor anothingfees. - Get the flags
periodicandone_offon the clockfees.fawithfixed_fee_terms. - Return
truewhenone_offistrue, or whenperiodicistrueandcancelsisfalse.
Arguments
fees: The fees that the risk pays, ornothing.cancels::Bool: Whether a fee that every observation pays in the same amount cancels from the risk.
Returns
flag::Bool:truewhen a fee that does not scale with the weights reaches the risk.
Examples
julia> fees = Fees(; tn = Turnover(; w = [0.5, 0.5], val = 0.001));julia> PortfolioOptimisers.has_fixed_fee(fees, false), PortfolioOptimisers.has_fixed_fee(fees, true)(true, false)julia> PortfolioOptimisers.has_fixed_fee(Fees(; fl = 0.001), true)truejulia> PortfolioOptimisers.has_fixed_fee(Fees(; fl = 0.001, fa = AmortisedFees()), true)falsejulia> PortfolioOptimisers.has_fixed_fee(Fees(; l = 0.001), false)falseRelated
PortfolioOptimisers.fixed_fee_terms — Function
fixed_fee_terms(fees::Fees, fa::Option{<:AbstractFeeAmortisation}) -> Tuple{Bool, Bool}Return the pair (periodic, one_off): whether fees holds a fee that does not scale with the portfolio weights and falls on each observation, and whether it holds one that falls on the first observation alone.
has_fixed_fee reads the pair. The Fee Amortisation fa is the clock of the one-off terms, so it decides which flag they set.
Algorithm
- Set
periodicwhenhas_fixed_targetoffees.tnistrue, or when the charge offees.lqfromcalc_liquidation_feesis not zero. - Set
one_offwhen a ratefees.florfees.fsis not zero, or when the charge offees.flqfromcalc_fixed_liquidation_feesis not zero. Anothingrate is zero. - Under
AmortisedFees, the one-off terms fall on each observation, so return(periodic || one_off, false). Otherwise return(periodic, one_off).
Arguments
fees::Fees: The fees that the risk pays.fa: The Fee Amortisation offees.
Returns
(periodic, one_off)::Tuple{Bool, Bool}: The two flags.
Related
PortfolioOptimisers.reads_fees — Function
reads_fees(r::AbstractBaseRiskMeasure) -> Bool
reads_fees(kind::RiskInputKind) -> BoolReturn true when the risk of the measure r reads the fees.
The input kind of r, from risk_input_kind, gives the default. A WeightsInput measure reads the weights alone, so it does not read the fees. A NetReturnsInput and a WeightsReturnsFeesInput measure read them. Three measures take the fees and do not read them, because their risk reads the moments of a prior: VarianceSkewKurtosis, and a ValueatRisk and a ValueatRiskRange with DistributionValueatRisk. A GenericValueatRiskRange reads the fees when one of its tails reads them.
Arguments
r: Risk measure or vector of risk measures.kind::RiskInputKind: The input kind of a measure.
Returns
flag::Bool:truewhen the risk reads the fees.
Examples
julia> PortfolioOptimisers.reads_fees(ConditionalValueatRisk())truejulia> PortfolioOptimisers.reads_fees(Variance())falseRelated
PortfolioOptimisers.cancels_constant_fee — Function
cancels_constant_fee(r::AbstractBaseRiskMeasure, T::Option{<:Integer} = nothing) -> BoolReturn true when the risk of the measure r on T observations does not change when the same number is added to each net return.
A fee that every observation pays in the same amount is such a number, so it cancels from the risk, and has_fixed_fee does not count it. A measure that no other method names returns false. A tail measure, a drawdown and a tracking error move with the number.
Algorithm
- Return
truefor a member ofShiftInvariantRiskMeasures. - For a
LowOrderMoment, aHighOrderMoment, aThirdCentralMomentand aMedianAbsoluteDeviation, returntruewhen the Moment Targetmuis not a number. The mean or the median of the net returns moves with the number. A per-asset target is net of the mean fee per period,moment_target_fees, so it moves too. A number is a threshold on the net returns, and it does not move. - For a
GenericValueatRiskRange, returntruewhen both tails read the fees,reads_fees. A tail withDistributionValueatRiskdoes not move, so the other tail does not cancel. - For an
OrderedWeightsArray, returntruewhen its weights onTobservations sum to zero, fromresolve_owa_weightsandsums_to_zero. A number $c$ moves the risk by $c$ times the sum of the weights. For anOrderedWeightsArrayRange, apply the same rule tow1 - w2, so the two tails must hold the same sum. A weight builder withoutThas no known sum, so it returnsfalse. - Return
falsefor every other measure.
Arguments
r: Risk measure or vector of risk measures.T: The number of observations of the net returns, ornothingwhen it is not known.
Returns
flag::Bool:truewhen a constant shift of the net returns cancels from the risk.
Examples
julia> PortfolioOptimisers.cancels_constant_fee(LowOrderMoment())truejulia> PortfolioOptimisers.cancels_constant_fee(LowOrderMoment(; mu = 0.0))falsejulia> PortfolioOptimisers.cancels_constant_fee(ConditionalValueatRiskRange())truejulia> PortfolioOptimisers.cancels_constant_fee(ConditionalValueatRisk())falsejulia> PortfolioOptimisers.cancels_constant_fee(OrderedWeightsArray(), 200)truejulia> PortfolioOptimisers.cancels_constant_fee(OrderedWeightsArray())falseRelated
PortfolioOptimisers.sums_to_zero — Function
sums_to_zero(w::Option{<:VecNum}) -> Bool
sums_to_zero(w1::Option{<:VecNum}, w2::Option{<:VecNum}) -> BoolReturn true when the OWA weights w sum to zero. The second form tests w1 - w2. A nothing stands for weights whose sum is not known, from resolve_owa_weights, and returns false.
The vector test is isapprox(s + sum(w), s) with s = sum(abs, w), so it takes the default tolerance of the element type. The two vector methods each hold the test, the second on w = w1 - w2, and the two copies agree. A floating point vector passes at a sum near the rounding error of s, and an exact type, such as a Rational, passes only at an exact zero.
Arguments
w::Option{<:VecNum}: The weights, ornothing.w1,w2: The weights of the two tails of a range, ornothing.
Returns
flag::Bool:truewhen the weights sum to zero.
Related
PortfolioOptimisers.resolve_owa_weights — Function
resolve_owa_weights(w::OWA_Func_VecNum, T::Option{<:Integer}) -> Option{<:VecNum}Return the OWA weights of the weight slot w on T observations, or nothing when they are not known.
A weight vector is its own weights. A weight builder gives the weights of the observation count, so it returns w(T), as the risk of OrderedWeightsArray does. Without T, a builder returns nothing.
Arguments
w::OWA_Func_VecNum: A weight vector or a weight builder.T: The number of observations, ornothingwhen it is not known.
Returns
w::Option{<:VecNum}: The weights, ornothing.
Examples
julia> PortfolioOptimisers.resolve_owa_weights([0.5, -0.5], nothing)2-element Vector{Float64}: 0.5 -0.5julia> PortfolioOptimisers.resolve_owa_weights(owa_gmd, 3) == owa_gmd(3)truejulia> isnothing(PortfolioOptimisers.resolve_owa_weights(owa_gmd, nothing))trueRelated
PortfolioOptimisers.owa_weights — Function
owa_weights(w::OWA_Func_VecNum, T::Integer, sym::Symbol = :w) -> VecNumReturn the OWA weights of the weight slot w on T observations, and refuse weights whose length is not T.
An OWA risk pairs the k-th weight with the k-th smallest return, so it reads one weight for each observation. A weight builder gives the weights of every sample length. A weight vector is fixed at construction, so it holds the weights of one sample length only. The value of OrderedWeightsArray and of OrderedWeightsArrayRange, and every JuMP model of the two, read their weights through this function. So the optimisation and the risk of its answer refuse the same vector.
Algorithm
- Resolve
wonTobservations withresolve_owa_weights. - Refuse the weights when their length is not
T, and return them otherwise.
Arguments
w::OWA_Func_VecNum: A weight vector or a weight builder.T::Integer: The number of observations of the returns that the measure reads.sym::Symbol: The name of the weight slot in the message of the error.
Validation
length(w) == T. Raises aDimensionMismatch.
Returns
w::VecNum: The weights of theTobservations.
Examples
julia> PortfolioOptimisers.owa_weights(owa_gmd, 3) == owa_gmd(3)truejulia> PortfolioOptimisers.owa_weights(owa_gmd(4), 3)ERROR: DimensionMismatch: length(w) == 3 must hold: an OWA risk measure holds one weight for each observation, and the returns have 3 observations. Gotlength(w) => 4A weight vector is fixed at construction, so give the weights of exactly these observations, or give a weight builder such as `owa_gmd`, which builds the weights of every sample length.[...]Related
PortfolioOptimisers.scalarised_degree — Function
scalarised_degree(r::BaseRM_VecBaseRM, sca::Option{<:Scalariser}, fees::Option{<:Fees} = nothing,
T::Option{<:Integer} = nothing) -> Option{<:Integer}Return the degree of homogeneity of one side of a ratio, which is one measure or a vector of measures that sca combines, under the fees fees on T observations.
A single measure ignores sca. A vector has the common degree of its elements under SumScalariser, MaxScalariser and MinScalariser. It has no degree when two elements have different degrees, or under LogSumExpScalariser, which is not homogeneous.
Arguments
r: Risk measure or vector of risk measures.sca::Option{<:Scalariser}: Scalariser of the side.fees: The fees that the risk pays, ornothing.T: The number of observations of the net returns, ornothingwhen it is not known.
Returns
d::Option{<:Integer}: The degree of the side, ornothing.
Related
PortfolioOptimisers.degree_difference — Function
degree_difference(d1::Option{<:Integer}, d2::Option{<:Integer}) -> Option{<:Integer}Return the degree of homogeneity of a ratio from the degrees d1 of its numerator and d2 of its denominator.
The ratio has degree d1 - d2 when both sides have a degree, and no degree when either side has none. A degree is an integer or nothing, so any other type is a MethodError.
Arguments
d1: Degree of the numerator, ornothing.d2: Degree of the denominator, ornothing.
Returns
d::Option{<:Integer}: The degree of the ratio, ornothing.
Related
PortfolioOptimisers.adjust_risk_contribution — Function
adjust_risk_contribution(r::AbstractBaseRiskMeasure, val::Number,
fees::Option{<:Fees} = nothing,
T::Option{<:Integer} = nothing) -> NumberDivide the risk val of the measure r by the degree of homogeneity of r under the fees fees on T observations.
By Euler's theorem, the gradient of the divided risk, multiplied by the weights, sums to the risk. adjusted_risk calls this function, and risk_contribution differentiates the result. A measure of degree 0, and a measure with no degree, keep val unchanged.
Mathematical definition
\[\begin{align} A(\boldsymbol{w}) &= \frac{R(\boldsymbol{w})}{d}\,, \\ \sum_{i=1}^{N} w_i \frac{\partial A(\boldsymbol{w})}{\partial w_i} &= R(\boldsymbol{w})\,. \end{align}\]
The second line holds when $R$ is homogeneous of a degree $d \neq 0$. At $d = 0$ the sum is zero for every $R$, so no division gives back the risk, and the contributions of a measure of ScaleFreeRiskMeasures sum to zero. A measure that is not homogeneous, such as a tracking error or a turnover, has contributions that do not sum to its risk in general.
Where:
- $A(\boldsymbol{w})$: Homogeneity-adjusted risk.
- $R(\boldsymbol{w})$: Portfolio risk.
- $d$: Degree of homogeneity of the risk measure, the $d$ for which $R(c \boldsymbol{w}) = c^{d} R(\boldsymbol{w})$ at every $c > 0$.
- $w_i$: Weight of asset $i$.
- $N$: Number of assets.
Arguments
r: Risk measure or vector of risk measures.val::Number: Risk ofrat the weights.fees: The fees that the risk pays, ornothing.T: The number of observations of the net returns, ornothingwhen it is not known.
Returns
Number:val / d, orvalwhen the degreedis0ornothing.
Examples
julia> PortfolioOptimisers.adjust_risk_contribution(Variance(), 0.5)0.25julia> PortfolioOptimisers.adjust_risk_contribution(EqualRisk(), 0.5)0.5Related