Excess expected returns
PortfolioOptimisers.ExcessExpectedReturns — Type
struct ExcessExpectedReturns{__T_me, __T_rf} <: AbstractExpectedReturnsEstimatorSubtracts a risk-free rate from the expected returns that a nested estimator computes.
The nested estimator me computes the expected returns, and this type subtracts rf from each element of its result. me can hold any expected returns estimator.
Fields
me: Expected returns estimator.
rf: Risk-free rate.
Constructors
ExcessExpectedReturns(; me::AbstractExpectedReturnsEstimator = SimpleExpectedReturns(), rf::Number = 0.0) -> ExcessExpectedReturnsKeywords correspond to the struct's fields.
Validation
isfinite(rf).
Propagated parameters
factory passes its arguments on to these @fprop fields:
me: Recursively updated throughfactory.
View parameters
port_opt_view takes the view of these @vprop fields at the selected indices:
me: Recursively viewed throughport_opt_view.
Examples
julia> ExcessExpectedReturns()ExcessExpectedReturns me ┼ SimpleExpectedReturns │ w ┴ nothing rf ┴ Float64: 0.0Related
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::ExcessExpectedReturns, X::MatNum; dims::Int = 1, kwargs...)Compute excess expected returns by subtracting the risk-free rate.
This method applies the nested estimator me.me to the data, and subtracts the risk-free rate me.rf from every element of the result. The method reads the rate from the estimator alone, and never from the data or from a keyword.
Mathematical definition
\[\begin{align} \hat{\boldsymbol{\mu}}_{\text{excess}} &= \hat{\boldsymbol{\mu}} - r_f \boldsymbol{1}\,. \end{align}\]
Where:
- $\hat{\boldsymbol{\mu}}_{\text{excess}}$: The $N \times 1$ vector of excess expected returns.
- $\hat{\boldsymbol{\mu}}$: The $N \times 1$ vector of expected returns that
me.meestimates. - $r_f$: The risk-free rate
me.rf. - $\boldsymbol{1}$: The $N \times 1$ vector of ones.
Arguments
me: The excess expected returns estimator.X: The data matrix,observations × assets.dims: Dimension along which the computation runs.kwargs...: More keyword arguments, which the method passes to the nested estimatorme.me.
Validation
dims in (1, 2).
Returns
mu::ArrNum: The excess expected returns. The subtraction is elementwise, so the result has the shape of the result ofme.me.
Examples
julia> me = ExcessExpectedReturns(; rf = 0.01);julia> X = [0.01 0.02; 0.03 0.04; 0.02 0.03];julia> mean(me, X)1×2 Matrix{Float64}: 0.01 0.02Related