Standard deviation expected returns

PortfolioOptimisers.StandardDeviationExpectedReturns — Type
struct StandardDeviationExpectedReturns{__T_ce} <: AbstractExpectedReturnsEstimator

Expected returns estimator that returns the asset standard deviations.

StandardDeviationExpectedReturns returns the standard deviation of each asset in the place of an expected return. The covariance estimator ce estimates it. The result is in the units of the returns. Use it where a per-asset characteristic need not be a mean, for example to rank the assets on volatility with an L1UncertaintySet.

Fields

  • ce: Covariance estimator.

Constructors

StandardDeviationExpectedReturns(;    ce::StatsBase.CovarianceEstimator = PortfolioOptimisersCovariance()) -> StandardDeviationExpectedReturns

Keywords correspond to the struct's fields.

Propagated parameters

factory passes its arguments on to these @fprop fields:

  • ce: Recursively updated through factory.

View parameters

port_opt_view takes the view of these @vprop fields at the selected indices:

Examples

julia> StandardDeviationExpectedReturns()StandardDeviationExpectedReturns  ce ┼ PortfolioOptimisersCovariance     │   ce ┼ Covariance     │      │    me ┼ SimpleExpectedReturns     │      │       │   w ┴ nothing     │      │    ce ┼ GeneralCovariance     │      │       │   ce ┼ StatsBase.SimpleCovariance: StatsBase.SimpleCovariance(true)     │      │       │    w ┴ nothing     │      │   alg ┼ FullMoment()     │      │     w ┴ nothing     │   mp ┼ MatrixProcessing     │      │     pdm ┼ Posdef     │      │         │      alg ┼ UnionAll: NearestCorrelationMatrix.Newton     │      │         │   kwargs ┴ @NamedTuple{}: NamedTuple()     │      │      dn ┼ nothing     │      │      dt ┼ nothing     │      │     alg ┼ nothing     │      │   order ┴ NTuple{4, Symbol}: (:pdm, :dn, :dt, :alg)

Related

source
PortfolioOptimisers.VarianceExpectedReturns — Type
struct VarianceExpectedReturns{__T_ce} <: AbstractExpectedReturnsEstimator

Expected returns estimator that returns the asset variances.

VarianceExpectedReturns returns the variance of each asset in the place of an expected return. The covariance estimator ce estimates it. The result is in the squared units of the returns. The variance is the square of the standard deviation, so this type returns the elementwise square of what StandardDeviationExpectedReturns returns on the same data and the same ce.

Fields

  • ce: Covariance estimator.

Constructors

VarianceExpectedReturns(;    ce::StatsBase.CovarianceEstimator = PortfolioOptimisersCovariance()) -> VarianceExpectedReturns

Keywords correspond to the struct's fields.

Propagated parameters

factory passes its arguments on to these @fprop fields:

  • ce: Recursively updated through factory.

View parameters

port_opt_view takes the view of these @vprop fields at the selected indices:

Examples

julia> VarianceExpectedReturns()VarianceExpectedReturns  ce ┼ PortfolioOptimisersCovariance     │   ce ┼ Covariance     │      │    me ┼ SimpleExpectedReturns     │      │       │   w ┴ nothing     │      │    ce ┼ GeneralCovariance     │      │       │   ce ┼ StatsBase.SimpleCovariance: StatsBase.SimpleCovariance(true)     │      │       │    w ┴ nothing     │      │   alg ┼ FullMoment()     │      │     w ┴ nothing     │   mp ┼ MatrixProcessing     │      │     pdm ┼ Posdef     │      │         │      alg ┼ UnionAll: NearestCorrelationMatrix.Newton     │      │         │   kwargs ┴ @NamedTuple{}: NamedTuple()     │      │      dn ┼ nothing     │      │      dt ┼ nothing     │      │     alg ┼ nothing     │      │   order ┴ NTuple{4, Symbol}: (:pdm, :dn, :dt, :alg)

Related

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

Compute expected returns as the standard deviation of each asset.

This method returns the standard deviation of each asset in X, which the covariance estimator me.ce estimates. The result is in the units of the returns in X. It is the elementwise square root of what mean(me::VarianceExpectedReturns, X::MatNum; dims::Int = 1, kwargs...) returns on the same data and the same me.ce.

The method takes the square root of the diagonal of the matrix that me.ce returns. A choice inside me.ce that changes that diagonal, such as the observation weights, changes the result. The method calls me.ce through library_covariance_estimator. That function wraps an estimator that the library does not own, such as StatsBase.SimpleCovariance(), in a GeneralCovariance, because StatsBase defines no std for such an estimator.

Mathematical definition

\[\begin{align} \hat{\mu}_j &= \hat{\sigma}_j = \sqrt{\hat{\mathbf{\Sigma}}_{jj}}\,. \end{align}\]

Where:

  • $\hat{\mu}_j$: The value that takes the place of the expected return of asset $j$.
  • $\hat{\sigma}_j$: The standard deviation of asset $j$.
  • $\hat{\mathbf{\Sigma}}$: The covariance matrix that me.ce estimates.
  • $\hat{\mathbf{\Sigma}}_{jj}$: The $j$-th diagonal element of $\hat{\mathbf{\Sigma}}$.

Arguments

  • me: The standard deviation 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 passes to the covariance estimator.

Validation

  • dims in (1, 2).

Returns

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

Related

source
PortfolioOptimisers.factory — Method
factory(a, args...; kwargs...) -> a
factory(a::AbstractArray{<:Union{Nothing, AbstractEstimator, AbstractAlgorithm,
                                 AbstractResult, StatsBase.CovarianceEstimator}},
        args...; kwargs...) -> AbstractArray

Rebuild an estimator, an algorithm or a result with runtime values. These two methods are the leaf and the array step of the traversal.

factory and port_opt_view are the two propagation mechanisms of this library. factory passes runtime values, such as prior moments, observation weights and previous portfolio weights, down a tree of composed structs. port_opt_view passes an index selection, a subset of the assets, down the same tree.

factory is a traversal, so it owns the identity on every leaf, as fmap in Functors.jl and adapt_structure in Adapt.jl do. A value that has no method of its own comes back with no change: a data field, a scalar, nothing, a set of observation weights and a covariance estimator of StatsBase. So a @propagatable struct sends each @fprop field to factory directly, whatever the field holds.

The array method is the one forwarding contract for every propagation field that holds an array of estimators, algorithms, results or covariance estimators. It applies factory to each element, and it forwards args... and kwargs... with no change. A family that accepts an array of them needs no method of its own. A family that needs more than the forward defines its own, more specific method. A concrete element type, through concrete_typed_array_if_abstract, is an example. An array of data, such as a vector of numbers, is a leaf, and it comes back with no change and with no copy.

Algorithm

The leaf method:

  1. Return a with no change, and drop args... and kwargs.... This method is the leaf of the recursion. Because of it, a call of the verb on a type with no tags returns the value and raises no error.

The array method:

  1. For each element ai of a, call factory on ai, and forward args... and kwargs... with no change.
  2. Collect the results into a new array of the shape of a, in the order of a, and return it.

A @propagatable struct always has a generated method that is more specific than the leaf method. If the struct has at least one @fprop or @wprop field, that method builds the struct again with its keyword constructor. It sends each @fprop field through factory and each @wprop field through _wprop. If the struct has no such field, that method returns x.

The leaf method does not fill a nothing field. A weights field that must take the incoming weights when it holds nothing carries @wprop, and it goes to _wprop.

Arguments

  • a: Any value, which the leaf method returns with no change. For the array method, an array of estimators, algorithms, results, covariance estimators or nothing, which it rebuilds one element at a time.
  • args...: Positional arguments. The leaf method ignores them, and the array method forwards them.
  • kwargs...: Keyword arguments. The leaf method ignores them, and the array method forwards them.

Returns

  • a: The input with no change, for the leaf method.
  • v::AbstractArray: The rebuilt elements, in an array of the shape of a, for the array method.

Examples

julia> factory(nothing, 1, 2; x = 3)julia> factory([1.0, 2.0], 1, 2; x = 3)2-element Vector{Float64}: 1.0 2.0julia> factory(MeanValue())MeanValue  w ┴ nothing

Related

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

Compute expected returns as the variance of each asset.

This method returns the variance of each asset in X, which the covariance estimator me.ce estimates. The result is in the squared units of the returns in X. It is the elementwise square of what mean(me::StandardDeviationExpectedReturns, X::MatNum; dims::Int = 1, kwargs...) returns on the same data and the same me.ce.

The method reads the diagonal of the matrix that me.ce returns. A choice inside me.ce that changes that diagonal, such as the observation weights, changes the result. The method calls me.ce through library_covariance_estimator. That function wraps an estimator that the library does not own, such as StatsBase.SimpleCovariance(), in a GeneralCovariance, because StatsBase defines no var for such an estimator.

Mathematical definition

\[\begin{align} \hat{\mu}_j &= \hat{\sigma}_j^2 = \hat{\mathbf{\Sigma}}_{jj}\,. \end{align}\]

Where:

  • $\hat{\mu}_j$: The value that takes the place of the expected return of asset $j$.
  • $\hat{\sigma}_j^2$: The variance of asset $j$.
  • $\hat{\mathbf{\Sigma}}$: The covariance matrix that me.ce estimates.
  • $\hat{\mathbf{\Sigma}}_{jj}$: The $j$-th diagonal element of $\hat{\mathbf{\Sigma}}$.

Arguments

  • me: The variance 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 passes to the covariance estimator.

Validation

  • dims in (1, 2).

Returns

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

Related

source