Median expected returns

PortfolioOptimisers.MedianExpectedReturns — Type
struct MedianExpectedReturns{__T_w} <: AbstractExpectedReturnsEstimator

Computes the expected returns as the per-asset median of the asset returns.

w holds optional observation weights. If w is nothing, the median is unweighted. An outlier moves the sample mean in proportion to its size, and it moves the median only through its rank.

Fields

  • w: Optional observation weights vector observations × 1, or a concrete subtype of DynamicAbstractWeights. If nothing, the computation is unweighted.

Constructors

MedianExpectedReturns(;    w::Option{<:ObsWeights} = nothing) -> MedianExpectedReturns

Keywords correspond to the struct's fields.

Validation

  • If w is not nothing, !isempty(w).

Propagated parameters

factory passes its arguments on to these @fprop fields:

Observation weight parameters

obs_weights_view indexes these fields to the selected observations:

Examples

julia> me = MedianExpectedReturns()MedianExpectedReturns  w ┴ nothingjulia> factory(me, StatsBase.Weights([0.1, 0.2, 0.7]))MedianExpectedReturns  w ┴ StatsBase.Weights{Float64, Float64, Vector{Float64}}: [0.1, 0.2, 0.7]

Related

source
Statistics.mean — Method
Statistics.mean(me::MedianExpectedReturns, X::MatNum;
                dims::Int = 1, kwargs...)

Compute expected returns as the median of each asset.

This method returns the median of each asset over the observations in X. If me.w is nothing, the method calls Statistics.median(X; dims = dims). Otherwise, the method takes the weighted median of each asset under the observation weights me.w.

Mathematical definition

Unweighted:

\[\begin{align} \hat{\mu}_j &= \mathrm{median}(r_{1j}, r_{2j}, \ldots, r_{Tj})\,. \end{align}\]

Where:

  • $\hat{\mu}_j$: The median expected return of asset $j$.
  • $r_{tj}$: Return of asset $j$ at time $t$.
  • $T$: Number of observations.

Weighted. The weighted median is the StatsBase weighted quantile at probability $1/2$, which interpolates between two order statistics. Sort the returns of asset $j$ so that $r_{(1)j} \leq \ldots \leq r_{(T)j}$, and let $w_{(t)}$ be the weight of the observation that gives $r_{(t)j}$.

\[\begin{align} S_m &= \sum_{t=1}^{m} w_{(t)}\,, \\ h &= \frac{1}{2} \left( \sum_{t=1}^{T} w_t - w_{(1)} \right) + w_{(1)}\,, \\ k &= \max \left\lbrace m : S_m \leq h \right\rbrace\,, \\ \hat{\mu}_j &= r_{(k)j} + \frac{h - S_k}{S_{k+1} - S_k} \left( r_{(k+1)j} - r_{(k)j} \right)\,. \end{align}\]

Where:

  • $w_{t}$: Observation weight of observation $t$.
  • $w_{(t)}$: The weight of the $t$-th smallest return. The sort moves each weight with its return.
  • $r_{(t)j}$: The $t$-th smallest return of asset $j$.
  • $S_m$: The cumulative weight of the $m$ smallest returns.
  • $h$: The cumulative weight at the probability $1/2$.

The weighted median is not an order statistic, for two reasons.

  • The result is in general not one of the observed returns, because the last line interpolates between $r_{(k)j}$ and $r_{(k+1)j}$. Under equal weights it reduces to the ordinary median.
  • $w_{(1)}$ in the second line is the weight of the smallest return, not the weight of the first observation. The sort moves the weights with the returns before the second line gives $h$. A sample whose smallest return is the last observation therefore gives a different $h$ from the one that w[1] gives, and a different result.

Arguments

  • me: The median expected returns estimator.
  • X: The data matrix of asset returns, observations × assets.
  • dims: Dimension along which the computation runs.
  • kwargs: More keyword arguments, which the method ignores.

Validation

Returns

  • mu::Matrix{<:Number}: The medians, a (1, N) matrix if dims == 1 or an (N, 1) matrix if dims == 2.

Related

source
Statistics.mean — Method
mean(
    me::MedianExpectedReturns{<:Union{DynamicAbstractWeights, AbstractWeights}},
    X::AbstractMatrix{<:Union{Number, AbstractJuMPScalar}};
    dims,
    kwargs...
) -> Any

The weighted-median method of mean(me::MedianExpectedReturns, X::MatNum; dims::Int = 1, kwargs...). It takes the weighted median of each asset under the ObsWeights in me.w.

StatsBase has a weighted median of a vector and none of a matrix, so the method takes one column at a time. The weighted-quantile expression of the method above gives the result of one column.

Algorithm

  1. Orient X with dims_oriented, so that the observations run down the columns. This step also checks dims.
  2. Refuse a gapped sample with assert_finite_sample.
  3. Resolve me.w against the oriented X with get_observation_weights. The result is w.
  4. Allocate the result vector Y, of length size(X, 2).
  5. For each column i of X, put the weighted median of that column under w in Y[i].
  6. Insert the reduced dimension back into Y with insertdims. The result is a (1, N) matrix when dims == 1 and an (N, 1) matrix when dims == 2.

Validation

source