Median Absolute Deviation Risk
PortfolioOptimisers.MedianCentering — Type
struct MedianCentering <: MedianCenteringFunctionCentres the portfolio returns on their median.
It is the default centre of MedianAbsoluteDeviation. With this centre and flag = true, the measure is the median absolute deviation that estimates the standard deviation of a Gaussian series. When the measure holds observation weights, the centre is the weighted median Statistics.median(x, w).
Related
PortfolioOptimisers.MeanCentering — Type
struct MeanCentering <: MedianCenteringFunctionCentres the portfolio returns on their mean.
MedianAbsoluteDeviation then gives the median of the absolute deviations about the mean. On a skewed series, this value is not the deviation about the median. When the measure holds observation weights, the centre is the weighted mean Statistics.mean(x, w).
Related
PortfolioOptimisers.MedianAbsoluteDeviation — Type
struct MedianAbsoluteDeviation{__T_settings, __T_w, __T_mu, __T_flag} <: HierarchicalRiskMeasureMeasures the dispersion of the portfolio returns as the median of their absolute deviations from a centre.
A few extreme returns move a median less than they move a mean of squares, so the measure reacts less to outliers than the standard deviation does. The alias MAD does not build it. MAD builds the mean absolute deviation, a LowOrderMoment with MeanAbsoluteDeviation.
The measure is a HierarchicalRiskMeasure. A hierarchical optimiser, such as HierarchicalRiskParity or HierarchicalEqualRiskContribution, evaluates it on each cluster. The library has no JuMP model of a median, so the type bound of a JuMP optimiser, such as MeanRisk, refuses it.
Mathematical definition
\[\begin{align} \delta_t &= x_t - \mu\,, \\ \mathrm{MedAD}(\boldsymbol{x}) &= c \, \underset{1 \leq t \leq T}{\mathrm{median}} \lvert \delta_t \rvert\,, \\ c &= \begin{cases} 1 / \Phi^{-1}(3/4) \approx 1.4826 & \texttt{flag} = \texttt{true}\,, \\ 1 & \texttt{flag} = \texttt{false}\,. \end{cases} \end{align}\]
Where:
- $\mathrm{MedAD}(\boldsymbol{x})$: Median absolute deviation of the portfolio returns.
- $\boldsymbol{x}$: Portfolio returns vector $T \times 1$.
- $T$: Number of observations.
- $\mu$: Centre of the deviations.
calc_moment_targetstates it for each type ofmu. It is the median of $\boldsymbol{x}$ underMedianCenteringand its mean underMeanCentering. - $\delta_t$: Deviation of the return at observation $t$ from the centre.
- $c$: Consistency constant.
- $\Phi$: Distribution function of the standard normal distribution, and $\Phi^{-1}$ its quantile function.
For a Gaussian series with standard deviation $\sigma$, the median of $\lvert x_t - \mu \rvert$ about the median is $\Phi^{-1}(3/4) \, \sigma$. So with flag = true and MedianCentering, the measure is a consistent estimator of $\sigma$. When w holds observation weights, a weighted median replaces the median of the absolute deviations, and the centre takes the same weights. Equal weights give the unweighted value.
Fields
settings: Risk measure settings.
w: Optional observation weights vectorobservations × 1, or a concrete subtype ofDynamicAbstractWeights. Ifnothing, the computation is unweighted.
mu: Centre the absolute deviation is taken about. It is aMedianCenteringFunctionthat centres the portfolio series at the point of use, a scalar or a vectorassets × 1, or a Deferred Quantity — an expected returns estimator or a prior estimator that computes the centre against the optimisation's own prior, atfactorytime (seeMedAbsDevMuandresolve_deferred_quantities). There is nonothingstate; the default isMedianCentering.
flag: Iftrue, the measure multiplies the median of the absolute deviations by the consistency constant $1 / \Phi^{-1}(3/4)$, so that it estimates the standard deviation of a Gaussian series. Iffalse, it returns the median itself.
Constructors
MedianAbsoluteDeviation(; settings::HierarchicalRiskMeasureSettings = HierarchicalRiskMeasureSettings(), w::Option{<:ObsWeights} = nothing, mu::MedAbsDevMu = MedianCentering(), flag::Bool = true) -> MedianAbsoluteDeviationKeywords correspond to the struct's fields.
Validation
- If
muis aVecNum:!isempty(mu)andall(isfinite, mu). - If
muis aNumber:isfinite(mu). - If
wis aStatsBase.AbstractWeights, it is not empty, each entry is finite and>= 0, andsum(w) > 0, throughassert_observation_weights. ADynamicAbstractWeightsholds no weights until it reads the data, sochecked_observation_weightschecks it at evaluation, and also checks there that the weights have one entry for each observation.
A stated mu is pinned. It crosses a Cross-Validation fold or a subset view as the value of the whole universe, so it does not follow the refit that the optimisation runs on. A caller who wants it to follow the fit names a Deferred Quantity in mu, or keeps a MedianCenteringFunction, which recomputes the centre from the portfolio series at every call.
Propagated parameters
factory passes its arguments on to these @fprop fields:
w: Replaced with the incomingObsWeights.
Observation weight parameters
obs_weights_view indexes these fields to the selected observations:
w: Indexed to the selected observations throughobs_weights_view.
Functor
(r::MedianAbsoluteDeviation)(w::VecNum, X::MatNum, fees = nothing)(r::MedianAbsoluteDeviation)(x::VecNum)Computes the median absolute deviation of the portfolio returns X * w net of fees, or of the net portfolio returns x. The second form needs a centre that does not read the weights, which supports_precomputed_returns reports.
Arguments
w::VecNum: Portfolio weights vector.X::MatNum: Asset returns matrix ($T \times N$).fees: Optional fee structure.x::VecNum: Net portfolio returns.
View parameters
port_opt_view takes the view of these @vprop fields at the selected indices:
mu: A stated value is sliced to the selected indices throughport_opt_view. A Deferred Quantity passes through unsliced, and then fits on the subset.
Examples
julia> MedianAbsoluteDeviation()MedianAbsoluteDeviation settings ┼ HierarchicalRiskMeasureSettings │ scale ┴ Float64: 1.0 w ┼ nothing mu ┼ MedianCentering() flag ┴ Bool: trueRelated
HierarchicalRiskMeasureHierarchicalRiskMeasureSettingsMedianCenteringMeanCenteringcalc_moment_targetStandardDeviation: the dispersion thatflag = trueestimates on a Gaussian series.factoryobs_weights_view
References
- [220] F. R. Hampel. The influence curve and its role in robust estimation. Journal of the American Statistical Association 69, 383–393 (1974). Pages 383–393. The original source of this formulation was not found. The formulation follows this work and is not checked against the original.
- [221] P. J. Rousseeuw and C. Croux. Alternatives to the median absolute deviation. Journal of the American Statistical Association 88, 1273–1283 (1993).
PortfolioOptimisers.port_opt_view — Method
port_opt_view(x, i, args...; kwargs...) -> nothing_scalar_array_view(x, i)Select the assets i of an estimator, a result or an algorithm.
port_opt_view is the index-selection counterpart of factory. factory passes runtime values down a tree of composed structs, and port_opt_view passes an index selection down the same tree. It restricts every field that holds data, and every composed child, to the subset i. The meta-optimisers, such as NestedClustered and SubsetResampling, and the cross-validation variants use it to solve sub-problems with structs of the same shape.
A caller does not usually call port_opt_view. The meta-optimisers and the cross-validation internals call it. It is public and not exported, because the author of a new composed estimator can need to define a method. Tag each field that holds data with @vprop, and @propagatable makes the method.
This universal fallback handles leaf values. It views an array through nothing_scalar_array_view. It returns a scalar, nothing, an estimator with no data fields and an algorithm with no change. A composed struct that recurses into its children has its own, more specific method, which @propagatable makes from the @vprop tags or which the author writes by hand.
This method accepts and drops the threaded tail args... and all kwargs. The tail is usually the returns matrix X of the JuMP families. With this method, a call port_opt_view(child, i, X) that a macro makes never raises a MethodError on a leaf field.
Algorithm
- Drop
args...andkwargs.... This method is the leaf of the recursion, so it passes nothing further. - Return
nothing_scalar_array_viewofxati. The algorithm of that function gives the rule for each leaf type.
Related
PortfolioOptimisers.supports_precomputed_returns — Method
supports_precomputed_returns(
r::MedianAbsoluteDeviation
) -> Any
Return whether MedianAbsoluteDeviation r supports precomputed-return evaluation.
The method returns weight_independent_target of r.mu. That is true for a MedianCenteringFunction and for a number, and false for a per-asset mu, which reads the asset weights.
Related
References
- [220]
- F. R. Hampel. The influence curve and its role in robust estimation. Journal of the American Statistical Association 69, 383–393 (1974).
- [221]
- P. J. Rousseeuw and C. Croux. Alternatives to the median absolute deviation. Journal of the American Statistical Association 88, 1273–1283 (1993).