Mean
Public
PortfolioOptimisers.SimpleExpectedReturns Type
struct SimpleExpectedReturns{T1} <: AbstractExpectedReturnsEstimator
w::T1
endA 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. It supports both unweighted and weighted mean estimation by storing an optional weights vector.
Fields
w: Optional weights for each observation. Ifnothing, the unweighted mean is computed.
Constructor
SimpleExpectedReturns(; w::Option{<:AbstractWeights} = nothing)Keyword arguments correspond to the fields above.
Validation
- If `w` is provided, `!isempty(w)`.Related
sourceStatistics.mean Method
mean(me::SimpleExpectedReturns, X::MatNum; dims::Int = 1, kwargs...)Compute the mean of asset returns using a SimpleExpectedReturns estimator.
This method computes the expected returns as the sample mean of the input data X, optionally using observation weights stored in the estimator. If no weights are provided, the unweighted mean is computed.
Arguments
me: The expected returns estimator.X: Data array of asset returns (observations × assets).dims: Dimension along which to compute the mean.kwargs...: Additional keyword arguments passed toStatistics.mean.
Returns
mu::VecNum: The expected returns vector.
Examples
julia> using StatsBase
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> w = Weights([0.2, 0.8]);
julia> serw = SimpleExpectedReturns(; w = w)
SimpleExpectedReturns
w ┴ StatsBase.Weights{Float64, Float64, Vector{Float64}}: [0.2, 0.8]
julia> mean(serw, X)
1×2 Matrix{Float64}:
0.026 0.036Related
sourcePortfolioOptimisers.factory Function
factory(me::SimpleExpectedReturns, w::Option{<:AbstractWeights} = nothing)Create a new SimpleExpectedReturns estimator with updated observation weights.
This function constructs a new SimpleExpectedReturns object, optionally replacing the weights stored in the input estimator with the provided weights. If w is nothing, the weights from me are used.
Arguments
me: ExistingSimpleExpectedReturnsestimator.w: Optional observation weights to use in the new estimator. Ifnothing, usesme.w.
Returns
me::SimpleExpectedReturns: New estimator with updated weights.
Details
Returns a new estimator, preserving the type and updating weights as specified.
If
wis not provided, the weights frommeare used.Validates that weights are non-empty and finite.
Related
source