Standard deviation expected returns
PortfolioOptimisers.StandardDeviationExpectedReturns — Type
struct StandardDeviationExpectedReturns{__T_ce} <: AbstractExpectedReturnsEstimatorExpected 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()) -> StandardDeviationExpectedReturnsKeywords correspond to the struct's fields.
Propagated parameters
factory passes its arguments on to these @fprop fields:
ce: Recursively updated throughfactory.
View parameters
port_opt_view takes the view of these @vprop fields at the selected indices:
ce: Recursively viewed throughport_opt_view.
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
AbstractExpectedReturnsEstimatorPortfolioOptimisersCovarianceVarianceExpectedReturns: The sibling that returns the square of this result.factoryport_opt_view
PortfolioOptimisers.VarianceExpectedReturns — Type
struct VarianceExpectedReturns{__T_ce} <: AbstractExpectedReturnsEstimatorExpected 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()) -> VarianceExpectedReturnsKeywords correspond to the struct's fields.
Propagated parameters
factory passes its arguments on to these @fprop fields:
ce: Recursively updated throughfactory.
View parameters
port_opt_view takes the view of these @vprop fields at the selected indices:
ce: Recursively viewed throughport_opt_view.
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
AbstractExpectedReturnsEstimatorPortfolioOptimisersCovarianceStandardDeviationExpectedReturns: The sibling that returns the square root of this result.factoryport_opt_view
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.ceestimates. - $\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 ifdims == 1or an(N, 1)matrix ifdims == 2.
Related
PortfolioOptimisers.factory — Method
factory(a, args...; kwargs...) -> a
factory(a::AbstractArray{<:Union{Nothing, AbstractEstimator, AbstractAlgorithm,
AbstractResult, StatsBase.CovarianceEstimator}},
args...; kwargs...) -> AbstractArrayRebuild 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:
- Return
awith no change, and dropargs...andkwargs.... 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:
- For each element
aiofa, callfactoryonai, and forwardargs...andkwargs...with no change. - Collect the results into a new array of the shape of
a, in the order ofa, 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 ornothing, 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 ofa, 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 ┴ nothingRelated
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.ceestimates. - $\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 ifdims == 1or an(N, 1)matrix ifdims == 2.
Related