Excess expected returns
PortfolioOptimisers.ExcessExpectedReturns — Type
struct ExcessExpectedReturns{__T_me, __T_rf} <: AbstractShrunkExpectedReturnsEstimatorSubtracts a risk-free rate from the expected returns that a nested estimator computes.
The nested estimator does all the work. This type only shifts its result, so it composes with every other 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
When factory is called on this type, the following @fprop-tagged fields are automatically propagated:
me: Recursively updated viafactory.
View parameters
When port_opt_view is called on this type, the following @vprop-tagged fields are automatically subset to the selected indices:
me: Recursively viewed viaport_opt_view.
Examples
julia> ExcessExpectedReturns()ExcessExpectedReturns me ┼ SimpleExpectedReturns │ w ┴ nothing rf ┴ Float64: 0.0Related
PortfolioOptimisers.factory — Method
factory(a::Union{Nothing, <:AbstractEstimator, <:AbstractAlgorithm,
<:AbstractResult}, args...; kwargs...) -> a
factory(a::AbstractVector{<:Union{Nothing, <:AbstractEstimator, <:AbstractAlgorithm,
<:AbstractResult}}, args...; kwargs...) -> VectorNo-op factory function for constructing objects with a uniform interface.
Defining methods which dispatch on the first argument allows for a consistent factory interface across different types.
factory and port_opt_view are the two propagation mechanisms in this library. They are duals: factory threads runtime values (prior moments, observation weights, previous portfolio weights) down through a composed struct tree; port_opt_view threads an index selection (a subset of assets or observations) down through the same tree.
The vector method is the one forwarding contract for every vector-valued propagation field: it applies factory to each element and forwards args... and kwargs... unchanged, so a family that admits a vector of estimators, algorithms, or results needs no method of its own. A family that needs more than the forward, such as a concrete element type (concrete_typed_array_if_abstract), defines its own more specific method.
Algorithm
The scalar method:
- Return
aunchanged, and dropargs...andkwargs.... This method is the leaf of the recursion, and it is what makes an untagged type safe to call the verb on.
The vector method:
- For each element
aiofa, callfactoryonai, and forwardargs...andkwargs...unchanged. - Collect the results into a new vector, in the order of
a, and return it.
A @propagatable struct with at least one @fprop- or @wprop-tagged field carries a generated method that dominates the scalar method. That method rebuilds the struct with its keyword constructor, sending each @fprop field through factory_child and each @wprop field through _wprop.
Arguments
a: Indicates no object should be constructed, or a vector whose elements are rebuilt one by one.args...: Arbitrary positional arguments (ignored by the scalar method, forwarded by the vector method).kwargs...: Arbitrary keyword arguments (ignored by the scalar method, forwarded by the vector method).
Returns
a: The input unchanged.v::Vector: The element-wise rebuilds, for the vector method.
Examples
julia> factory(nothing, 1, 2; x = 3)julia> 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 rate is the one stored on the estimator. It is not read from the data and it is not read 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}}$: $N \times 1$ vector of excess expected returns.
- $\hat{\boldsymbol{\mu}}$: $N \times 1$ vector of estimated expected returns.
- $r_f$: Risk-free rate.
- $\boldsymbol{1}$: $N \times 1$ vector of ones.
Arguments
me: Excess expected returns estimator.X: Data matrix (observations × assets).dims: Dimension along which to perform the computation.kwargs...: Additional keyword arguments passed to the mean estimator.
Validation
dims in (1, 2).
Returns
mu::ArrNum: Excess expected returns. The shape is the shape thatme.mereturns, because the subtraction is elementwise.
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