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

source
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

source
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

source
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

source
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

source
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

source
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

source
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

  1. Return nothing when has_fixed_target of r, fees and T is true. This applies to steps 2 and 7.
  2. Return 2 for a member of SquaredRiskMeasures, 3 for a member of CubedRiskMeasures, 4 for a member of FourthPowerRiskMeasures, and 0 for a member of ScaleFreeRiskMeasures.
  3. For RiskTrackingRiskMeasure, return nothing when its benchmark is a fixed target. Otherwise return the degree of its measure r under fees and T. The benchmark weights are zero at this step, so the measure tracks r itself on the same net returns.
  4. For RiskRatio and NonOptimisationRiskRatio, get the degree of each side under fees and T with scalarised_degree, and subtract the degree of r2 from the degree of r1 with degree_difference.
  5. For MeanReturnRiskRatio and ExpectedReturnRiskRatio, return nothing when rf is not zero. Otherwise subtract the degree of rk from the degree of rt, in the same way. A return estimator does not read T. ExpectedReturn has the degree of its return estimator rt.
  6. Return nothing for VarianceSkewKurtosis, whose three terms have the degrees 2, 3 and 4, and for a member of RelativeDrawdownRiskMeasures.
  7. Return 1 for every other measure.

Arguments

  • r: Risk measure or vector of risk measures.
  • fees: The fees that the risk pays, or nothing.
  • T: The number of observations of the net returns, or nothing when it is not known.

Returns

  • d::Option{<:Integer}: The degree of homogeneity, or nothing when r is 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

source
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

  1. Return nothing for LogarithmicReturn, and 1 for NoReturn.
  2. For every other return estimator, return nothing when settings.fee is true and has_fixed_fee finds a fee. Otherwise return 1.
  3. For a vector, return nothing when a term whose settings.rte is true has no degree. Otherwise return 1.
  4. For ExpectedReturn, return the degree of rt.
  5. For ExpectedReturnRiskRatio, return nothing when rf is not zero. Otherwise subtract the degree of rk, from scalarised_degree, from the degree of rt with degree_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, or nothing.
  • T: The number of observations of the net returns, or nothing when it is not known. A return estimator does not read it, and the risk measure rk of a ratio does.

Returns

  • d::Option{<:Integer}: The degree of homogeneity, or nothing.

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()))0

Related

source
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) -> Bool

Return 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

  1. For a LowOrderMoment, a HighOrderMoment, a ThirdCentralMoment and a MedianAbsoluteDeviation, read the Moment Target mu. A number is fixed when it is not zero. A VecScalar is fixed when its offset s is not zero.
  2. For a TrackingRiskMeasure and a RiskTrackingRiskMeasure, read the benchmark tr. The weights of a WeightsTracking and the series of a ReturnsTracking are fixed when they are not zero. A vector B of a DataBenchmarkTracking is fixed when it is not zero, and so is an unbound B, whose target is not known. A matrix B gives the series $\mathbf{B} \boldsymbol{w}$, which scales with the weights.
  3. For a TurnoverRiskMeasure, the reference weights w are fixed when they are not zero.
  4. For a Turnover fee, the previous weights w are fixed when an asset whose rate is not zero has a previous weight that is not zero.
  5. With fees, return true when step 1, 2 or 3 is true. Otherwise return true when r reads the fees, reads_fees, and has_fixed_fee finds a fee that does not cancel from the risk of r on T observations, cancels_constant_fee.
  6. Return false for every other measure and every other target value.

Arguments

  • r: Risk measure or vector of risk measures.
  • fees: The fees that the risk pays, or nothing.
  • T: The number of observations of the net returns, or nothing when it is not known.
  • target: The target value of a measure.

Returns

  • flag::Bool: true when 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))false

Related

source
PortfolioOptimisers.has_fixed_fee — Function
has_fixed_fee(fees::Option{<:Fees}, cancels::Bool) -> Bool

Return 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

  1. Return false for a nothing fees.
  2. Get the flags periodic and one_off on the clock fees.fa with fixed_fee_terms.
  3. Return true when one_off is true, or when periodic is true and cancels is false.

Arguments

  • fees: The fees that the risk pays, or nothing.
  • cancels::Bool: Whether a fee that every observation pays in the same amount cancels from the risk.

Returns

  • flag::Bool: true when 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)false

Related

source
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

  1. Set periodic when has_fixed_target of fees.tn is true, or when the charge of fees.lq from calc_liquidation_fees is not zero.
  2. Set one_off when a rate fees.fl or fees.fs is not zero, or when the charge of fees.flq from calc_fixed_liquidation_fees is not zero. A nothing rate is zero.
  3. 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 of fees.

Returns

  • (periodic, one_off)::Tuple{Bool, Bool}: The two flags.

Related

source
PortfolioOptimisers.reads_fees — Function
reads_fees(r::AbstractBaseRiskMeasure) -> Bool
reads_fees(kind::RiskInputKind) -> Bool

Return 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: true when the risk reads the fees.

Examples

julia> PortfolioOptimisers.reads_fees(ConditionalValueatRisk())truejulia> PortfolioOptimisers.reads_fees(Variance())false

Related

source
PortfolioOptimisers.cancels_constant_fee — Function
cancels_constant_fee(r::AbstractBaseRiskMeasure, T::Option{<:Integer} = nothing) -> Bool

Return 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

  1. Return true for a member of ShiftInvariantRiskMeasures.
  2. For a LowOrderMoment, a HighOrderMoment, a ThirdCentralMoment and a MedianAbsoluteDeviation, return true when the Moment Target mu is 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.
  3. For a GenericValueatRiskRange, return true when both tails read the fees, reads_fees. A tail with DistributionValueatRisk does not move, so the other tail does not cancel.
  4. For an OrderedWeightsArray, return true when its weights on T observations sum to zero, from resolve_owa_weights and sums_to_zero. A number $c$ moves the risk by $c$ times the sum of the weights. For an OrderedWeightsArrayRange, apply the same rule to w1 - w2, so the two tails must hold the same sum. A weight builder without T has no known sum, so it returns false.
  5. Return false for every other measure.

Arguments

  • r: Risk measure or vector of risk measures.
  • T: The number of observations of the net returns, or nothing when it is not known.

Returns

  • flag::Bool: true when 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())false

Related

source
PortfolioOptimisers.sums_to_zero — Function
sums_to_zero(w::Option{<:VecNum}) -> Bool
sums_to_zero(w1::Option{<:VecNum}, w2::Option{<:VecNum}) -> Bool

Return 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, or nothing.
  • w1, w2: The weights of the two tails of a range, or nothing.

Returns

  • flag::Bool: true when the weights sum to zero.

Related

source
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, or nothing when it is not known.

Returns

  • w::Option{<:VecNum}: The weights, or nothing.

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))true

Related

source
PortfolioOptimisers.owa_weights — Function
owa_weights(w::OWA_Func_VecNum, T::Integer, sym::Symbol = :w) -> VecNum

Return 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

  1. Resolve w on T observations with resolve_owa_weights.
  2. 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 a DimensionMismatch.

Returns

  • w::VecNum: The weights of the T observations.

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

source
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, or nothing.
  • T: The number of observations of the net returns, or nothing when it is not known.

Returns

  • d::Option{<:Integer}: The degree of the side, or nothing.

Related

source
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, or nothing.
  • d2: Degree of the denominator, or nothing.

Returns

  • d::Option{<:Integer}: The degree of the ratio, or nothing.

Related

source
PortfolioOptimisers.adjust_risk_contribution — Function
adjust_risk_contribution(r::AbstractBaseRiskMeasure, val::Number,
                         fees::Option{<:Fees} = nothing,
                         T::Option{<:Integer} = nothing) -> Number

Divide 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 of r at the weights.
  • fees: The fees that the risk pays, or nothing.
  • T: The number of observations of the net returns, or nothing when it is not known.

Returns

  • Number: val / d, or val when the degree d is 0 or nothing.

Examples

julia> PortfolioOptimisers.adjust_risk_contribution(Variance(), 0.5)0.25julia> PortfolioOptimisers.adjust_risk_contribution(EqualRisk(), 0.5)0.5

Related

source