Simple expected returns
The most basic moment is the simple expected return. These types and functions implement it.
PortfolioOptimisers.SimpleExpectedReturns Type
struct SimpleExpectedReturns{__T_w} <: AbstractExpectedReturnsEstimatorA simple expected returns estimator for PortfolioOptimisers.jl, representing the sample mean with optional observation weights.
SimpleExpectedReturns is the standard estimator for computing expected returns as the possibly weighted mean of asset returns.
Fields
w: Optional observation weights vectorobservations × 1, or a concrete subtype ofDynamicAbstractWeights. Ifnothing, the computation is unweighted.
Constructors
SimpleExpectedReturns(;
w::Option{<:ObsWeights} = nothing
) -> SimpleExpectedReturnsKeywords correspond to the struct's fields.
Validation
- If
wis notnothing,!isempty(w).
Examples
julia> SimpleExpectedReturns()
SimpleExpectedReturns
w ┴ nothing
julia> SimpleExpectedReturns(; w = StatsBase.Weights([0.5, 0.5]))
SimpleExpectedReturns
w ┴ StatsBase.Weights{Float64, Float64, Vector{Float64}}: [0.5, 0.5]Related
sourcePortfolioOptimisers.factory Method
factory(a::Union{Nothing, <:AbstractEstimator, <:AbstractAlgorithm,
<:AbstractResult}, args...; kwargs...) -> aNo-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.
Arguments
a: Indicates no object should be constructed.args...: Arbitrary positional arguments (ignored).kwargs...: Arbitrary keyword arguments (ignored).
Returns
a: The input unchanged.
Related
sourcefactory(
me::SimpleExpectedReturns,
w::ObsWeights
) -> SimpleExpectedReturnsCreate a new SimpleExpectedReturns estimator with observation weights w.
This function constructs a new SimpleExpectedReturns object, replacing the weights stored in the input estimator with the provided weights.
Arguments
me: Expected returns estimator.w: Observation weights vectorobservations × 1.
Returns
me: New expected returns estimator of the same type as the argument, with the appropriate weights applied.
Examples
julia> me = SimpleExpectedReturns()
SimpleExpectedReturns
w ┴ nothing
julia> factory(me, StatsBase.Weights([0.1, 0.2, 0.7]))
SimpleExpectedReturns
w ┴ StatsBase.Weights{Float64, Float64, Vector{Float64}}: [0.1, 0.2, 0.7]Related
sourceStatistics.mean Method
Statistics.mean(
me::SimpleExpectedReturns,
X::MatNum;
dims::Int = 1,
kwargs...
) -> ArrNumCompute the mean of asset returns using a SimpleExpectedReturns estimator.
This method computes the expected returns as the sample mean of the input data X according to ce.
Arguments
me: Expected returns estimator.X: Data matrixobservations × featuresif thedimskeyword does not exist ordims = 1,features × observationswhendims = 2.dims: Dimension along which to perform the computation.kwargs...: Additional keyword arguments passed toStatistics.mean.
Returns
mu::ArrNum: Expected returns vectorfeatures x 1if thedimskeyword does not exist ordims = 2,1 x featuresifdims = 1.
Examples
julia> X = [0.01 0.02; 0.03 0.04];
julia> ser = SimpleExpectedReturns()
SimpleExpectedReturns
w ┴ nothing
julia> mean(ser, X)
1×2 Matrix{Float64}:
0.02 0.03
julia> serw = SimpleExpectedReturns(; w = StatsBase.Weights([0.2, 0.8]))
SimpleExpectedReturns
w ┴ StatsBase.Weights{Float64, Float64, Vector{Float64}}: [0.2, 0.8]
julia> mean(serw, X)
1×2 Matrix{Float64}:
0.026 0.036Related
source