Risk Measure Tools: private API
PortfolioOptimisers.MomentRiskMeasures — Type
const MomentRiskMeasures{T} = Union{LowOrderMoment{<:Any, T}, HighOrderMoment{<:Any, T}, ThirdCentralMoment{<:Any, T}}Parameterised union of the three central-moment risk measures that read the returns and whose observation weights have the type T.
The members are LowOrderMoment, HighOrderMoment and ThirdCentralMoment. Kurtosis and Skewness read a comoment matrix and not the returns, so they are not members. Each member computes its risk in the same three operations. resolve_observation_weights resolves the weights against the data, calc_deviations_vec gives the deviations from the Moment Target, and moment_risk reduces the deviations. So the union holds the two functor methods, one for the asset returns and one for a return series, and each member uses them.
The kernels read only resolved weights. A measure that holds a DynamicAbstractWeights rebuilds one time for each call, with the resolved weights, and passes the new measure to each kernel. A measure with stored weights or with no weights does not rebuild, so it has no extra cost.
Related
PortfolioOptimisers.resolve_observation_weights — Function
resolve_observation_weights(r::AbstractBaseRiskMeasure, X::VecNum_MatNum)Return the risk measure r with its observation weights resolved against the data X.
A MomentRiskMeasures member that holds a DynamicAbstractWeights rebuilds with its keyword constructor. The constructor passes the weights to the variance estimator of the measure. That estimator is alg.ve of a SecondMoment, and ve of a HighOrderMoment or of a ThirdCentralMoment. So the measure and its variance estimator read the same resolved weights, as they do after factory against a prior.
A member that holds a StatsBase.AbstractWeights returns unchanged, after checked_observation_weights checks its weights against X. Every other measure returns unchanged. A measure with w = nothing needs no weights, and a measure outside the union resolves its own weights inside its kernel.
Algorithm
- Resolve
r.wagainstXwithchecked_observation_weights, givingw. This also checks thatwhas one entry for each observation. - Rebuild
rwithwin place ofr.w, withrebuild_struct, which calls the keyword constructor. Every other field keeps its value. Stored weights need no rebuild, so this step applies to aDynamicAbstractWeightsonly.
Validation
checked_observation_weightsraises aDimensionMismatchwhen the weights do not have one entry for each observation ofX. It also refuses resolved weights thatassert_observation_weightsrefuses.
Arguments
r: Risk measure or vector of risk measures.X: The data that the weights resolve against: the asset returns matrixobservations × assets, or a return seriesobservations × 1.
Returns
r::AbstractBaseRiskMeasure: The measure with its weights resolved.
Related
PortfolioOptimisers.measure_label — Function
measure_label(r::AbstractBaseRiskMeasure) -> String
measure_label(rs::VecBaseRM) -> StringReturn the name of a risk measure for an axis label, a title or a legend entry.
One measure gives the name of its type. A vector gives the names of its elements, joined by " + ". The vector method is the reason for the function. string(nameof(typeof(rs))) of a vector gives "Vector", which is a wrong label and raises no error. The measure plots and the frontier plots call this function to name a measure.
Arguments
r: Risk measure or vector of risk measures.
Returns
label::String: The name of the measure, or the joined names of the measures of the vector.
Examples
julia> PortfolioOptimisers.measure_label(ConditionalValueatRisk())"ConditionalValueatRisk"julia> PortfolioOptimisers.measure_label([Variance(), ConditionalValueatRisk()])"Variance + ConditionalValueatRisk"Related