Skip to content
5

Mean

PortfolioOptimisers.SimpleExpectedReturns Type
julia
struct SimpleExpectedReturns{T1} <: AbstractExpectedReturnsEstimator
    w::T1
end

A 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. If nothing, the unweighted mean is computed.

Constructor

julia
SimpleExpectedReturns(; w::Union{Nothing, <:AbstractWeights} = nothing)

Keyword arguments correspond to the fields above.

Validation

julia
- If `w` is provided, `!isempty(w)`.

Related

source
Statistics.mean Method
julia
mean(me::SimpleExpectedReturns, X::AbstractMatrix; 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 to Statistics.mean.

Returns

  • mu::Vector{<:Real}: The expected returns vector.

Examples

julia
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.036

Related

source