Base moments
Abstract moment types and fallbacks
The abstract types below are the supertypes of the estimators of the expected returns, the variance and the covariance. The functions below are their default methods, which an estimator uses when it does not define its own.
PortfolioOptimisers.AbstractCovarianceEstimator — Type
abstract type AbstractCovarianceEstimator <: CovarianceEstimatorAbstract supertype for all covariance estimator types.
Every concrete or abstract type that estimates a covariance matrix must subtype AbstractCovarianceEstimator.
Interfaces
To implement a new covariance estimator, subtype AbstractCovarianceEstimator. Keep every parameter in a field of the struct, the observation weights among them. Then implement these methods:
Covariance and correlation
Statistics.cov(ce::AbstractCovarianceEstimator, X::MatNum; kwargs...) -> MatNum: Estimates the covariance matrix.Statistics.cor(ce::AbstractCovarianceEstimator, X::MatNum; kwargs...) -> MatNum: Estimates the correlation matrix.
Arguments
ce: Covariance estimator.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.kwargs...: More keyword arguments, passed to the inner covariance estimator.
Returns
sigrho::MatNum: Covariance or correlation matrix,assets × assets.
Factory
PortfolioOptimisers.factory(ce::AbstractCovarianceEstimator, w::PortfolioOptimisers.ObsWeights) -> AbstractCovarianceEstimator: Builds a copy of the estimator that holds the new observation weights.
Arguments
ce: Covariance estimator.w: Observation weights vectorobservations × 1.
Returns
ce: New covariance estimator of the same type as the argument, with the new weights applied.
Examples
This example defines a minimal covariance estimator.
julia> struct MyCovarianceEstimator{T1} <: PortfolioOptimisers.AbstractCovarianceEstimator w::T1 function MyCovarianceEstimator(w::PortfolioOptimisers.Option{<:PortfolioOptimisers.ObsWeights}) PortfolioOptimisers.assert_nonempty_nonneg_finite_val(w, :w) return new{typeof(w)}(w) end endjulia> function MyCovarianceEstimator(; w::PortfolioOptimisers.Option{<:PortfolioOptimisers.ObsWeights} = nothing) return MyCovarianceEstimator(w) endMyCovarianceEstimatorjulia> function PortfolioOptimisers.factory(::MyCovarianceEstimator, w::PortfolioOptimisers.ObsWeights) return MyCovarianceEstimator(; w = w) endjulia> function Statistics.cov(est::MyCovarianceEstimator, X::PortfolioOptimisers.MatNum; dims::Int = 1, kwargs...) X = PortfolioOptimisers.dims_oriented(dims, X) w = ifelse(isnothing(est.w), StatsBase.fweights(fill(1.0, size(X, 1))), est.w) X = X .* w sigma = X' * X return sigma endjulia> function Statistics.cor(est::MyCovarianceEstimator, X::PortfolioOptimisers.MatNum; dims::Int = 1, kwargs...) X = PortfolioOptimisers.dims_oriented(dims, X) w = isnothing(est.w) ? StatsBase.fweights(fill(1.0, size(X, 1))) : est.w X = X .* w sigma = X' * X d = LinearAlgebra.diag(sigma) StatsBase.cov2cor!(sigma, sqrt.(d)) return sigma endjulia> cov(MyCovarianceEstimator(), [1.0 2.0; 0.3 0.7; 0.5 1.1])2×2 Matrix{Float64}: 1.34 2.76 2.76 5.7julia> cor(MyCovarianceEstimator(), [1.0 2.0; 0.3 0.7; 0.5 1.1])2×2 Matrix{Float64}: 1.0 0.998664 0.998664 1.0julia> PortfolioOptimisers.factory(MyCovarianceEstimator(), StatsBase.Weights([1, 2, 3]))MyCovarianceEstimator w ┴ StatsBase.Weights{Int64, Int64, Vector{Int64}}: [1, 2, 3]Related
PortfolioOptimisers.AbstractVarianceEstimator — Type
abstract type AbstractVarianceEstimator <: AbstractCovarianceEstimatorAbstract supertype for all variance estimator types.
Every concrete or abstract type that estimates a variance must subtype AbstractVarianceEstimator.
Interfaces
To implement a new variance estimator, subtype AbstractVarianceEstimator. Keep every parameter in a field of the struct, the observation weights among them. Then implement these methods:
Variance and standard deviation
Statistics.var(ve::AbstractVarianceEstimator, X::MatNum; kwargs...) -> ArrNum: Estimates the variance of each asset.Statistics.std(ve::AbstractVarianceEstimator, X::MatNum; kwargs...) -> ArrNum: Estimates the standard deviation of each asset.Statistics.var(ve::AbstractVarianceEstimator, X::VecNum; kwargs...) -> Number: Estimates the variance of the vector.Statistics.std(ve::AbstractVarianceEstimator, X::VecNum; kwargs...) -> Number: Estimates the standard deviation of the vector.
Arguments
ve: Variance estimator.XX: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.X: Data vectorobservations × 1.
kwargs...: More keyword arguments, passed to the expected returns estimator.
Returns
X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.res::ArrNum: Variance or standard deviation vector ofX, with the shape that matches the dimension of the computation.
X: Data vectorobservations × 1.res::Number: Variance or standard deviation ofX.
Covariance and correlation
Statistics.cov(ve::AbstractVarianceEstimator, X::MatNum; kwargs...) and Statistics.cor(ve::AbstractVarianceEstimator, X::MatNum; kwargs...) always throw a MethodError. A variance estimator computes one marginal variance for each asset and no relation between two assets, so it cannot compute either matrix.
A slot of the library that calls cov or cor refuses a variance estimator in its constructor, with the ArgumentError of assert_covariance_estimator. A slot that calls only var or std accepts one.
Factory
PortfolioOptimisers.factory(ve::AbstractVarianceEstimator, w::PortfolioOptimisers.ObsWeights) -> AbstractVarianceEstimator: Builds a copy of the estimator that holds the new observation weights.
Arguments
ve: Variance estimator.w: Observation weights vectorobservations × 1.
Returns
ve: New variance estimator of the same type as the argument, with the new weights applied.
Examples
This example defines a minimal variance estimator.
julia> struct MyVarianceEstimator{T1} <: PortfolioOptimisers.AbstractVarianceEstimator w::T1 function MyVarianceEstimator(w::PortfolioOptimisers.Option{<:PortfolioOptimisers.ObsWeights}) PortfolioOptimisers.assert_nonempty_nonneg_finite_val(w, :w) return new{typeof(w)}(w) end endjulia> function MyVarianceEstimator(; w::PortfolioOptimisers.Option{<:PortfolioOptimisers.ObsWeights} = nothing) return MyVarianceEstimator(w) endMyVarianceEstimatorjulia> function PortfolioOptimisers.factory(::MyVarianceEstimator, w::PortfolioOptimisers.ObsWeights) return MyVarianceEstimator(; w = w) endjulia> function Statistics.var(est::MyVarianceEstimator, X::PortfolioOptimisers.MatNum; dims::Int = 1, kwargs...) X = PortfolioOptimisers.dims_oriented(dims, X) w = isnothing(est.w) ? StatsBase.fweights(fill(1.0, size(X, 1))) : est.w X = X .* w sigma = LinearAlgebra.diag(X' * X) return isone(dims) ? reshape(sigma, 1, :) : reshape(sigma, :, 1) endjulia> function Statistics.std(est::MyVarianceEstimator, X::PortfolioOptimisers.MatNum; dims::Int = 1, kwargs...) X = PortfolioOptimisers.dims_oriented(dims, X) w = isnothing(est.w) ? StatsBase.fweights(fill(1.0, size(X, 1))) : est.w X = X .* w sigma = sqrt.(LinearAlgebra.diag(X' * X)) return isone(dims) ? reshape(sigma, 1, :) : reshape(sigma, :, 1) endjulia> function Statistics.var(est::MyVarianceEstimator, X::PortfolioOptimisers.VecNum; kwargs...) w = isnothing(est.w) ? StatsBase.fweights(fill(1.0, size(X, 1))) : est.w X = X .* w return sum(abs2, X) endjulia> function Statistics.std(est::MyVarianceEstimator, X::PortfolioOptimisers.VecNum; kwargs...) w = isnothing(est.w) ? StatsBase.fweights(fill(1.0, size(X, 1))) : est.w X = X .* w return sqrt(sum(abs2, X)) endjulia> var(MyVarianceEstimator(), [1.0 2.0; 0.3 0.7; 0.5 1.1])1×2 Matrix{Float64}: 1.34 5.7julia> std(MyVarianceEstimator(), [1.0 2.0; 0.3 0.7; 0.5 1.1])1×2 Matrix{Float64}: 1.15758 2.38747julia> var(MyVarianceEstimator(), [1.0 0.3 0.5; 2.0 0.7 1.1]; dims = 2)2×1 Matrix{Float64}: 1.34 5.7julia> var(MyVarianceEstimator(), [1.0, 0.3, 0.5])1.34julia> PortfolioOptimisers.factory(MyVarianceEstimator(), StatsBase.Weights([1, 2, 3]))MyVarianceEstimator w ┴ StatsBase.Weights{Int64, Int64, Vector{Int64}}: [1, 2, 3]Related
PortfolioOptimisers.AbstractExpectedReturnsEstimator — Type
abstract type AbstractExpectedReturnsEstimator <: AbstractEstimatorAbstract supertype for all expected returns estimator types.
Every concrete or abstract type that estimates expected returns must subtype AbstractExpectedReturnsEstimator.
Interfaces
To implement a new expected returns estimator, subtype AbstractExpectedReturnsEstimator. Keep every parameter in a field of the struct, the observation weights among them. Then implement these methods:
Expected returns
Statistics.mean(me::AbstractExpectedReturnsEstimator, X::MatNum; kwargs...) -> ArrNum: Estimates the expected returns.
Arguments
me: Expected returns estimator.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.kwargs...: More keyword arguments for the estimator.
Returns
mu::ArrNum: Expected returns vectorassets x 1if thedimskeyword does not exist ordims = 2,1 x assetsifdims = 1.
Factory
PortfolioOptimisers.factory(me::AbstractExpectedReturnsEstimator, w::PortfolioOptimisers.ObsWeights) -> AbstractExpectedReturnsEstimator: Builds a copy of the estimator that holds the new observation 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 new weights applied.
Examples
julia> struct MyExpectedReturnsEstimator{T1} <: PortfolioOptimisers.AbstractExpectedReturnsEstimator w::T1 function MyExpectedReturnsEstimator(w::PortfolioOptimisers.Option{<:PortfolioOptimisers.ObsWeights}) PortfolioOptimisers.assert_nonempty_nonneg_finite_val(w, :w) return new{typeof(w)}(w) end endjulia> function MyExpectedReturnsEstimator(; w::PortfolioOptimisers.Option{<:PortfolioOptimisers.ObsWeights} = nothing) return MyExpectedReturnsEstimator(w) endMyExpectedReturnsEstimatorjulia> function PortfolioOptimisers.factory(::MyExpectedReturnsEstimator, w::PortfolioOptimisers.ObsWeights) return MyExpectedReturnsEstimator(; w = w) endjulia> function Statistics.mean(est::MyExpectedReturnsEstimator, X::PortfolioOptimisers.MatNum; dims::Int = 1, kwargs...) X = PortfolioOptimisers.dims_oriented(dims, X) w = isnothing(est.w) ? fill(one(eltype(X)), size(X, 1)) : est.w X = X .* w mu = sum(X; dims = 1) / sum(w) return isone(dims) ? reshape(mu, 1, :) : reshape(mu, :, 1) endjulia> mean(MyExpectedReturnsEstimator(), [1.0 2.0; 0.3 0.7; 0.5 1.1]; dims = 2)3×1 Matrix{Float64}: 1.5 0.5 0.8julia> PortfolioOptimisers.factory(MyExpectedReturnsEstimator(), StatsBase.Weights([1, 2, 3]))MyExpectedReturnsEstimator w ┴ StatsBase.Weights{Int64, Int64, Vector{Int64}}: [1, 2, 3]Related
PortfolioOptimisers.port_opt_view — Method
port_opt_view(
ce::CovarianceEstimator,
_,
args...
) -> WindowedCovariance{var"#s185", _A, _B, <:AbstractWindowRule} where {var"#s185"<:CovarianceEstimator, _A, _B}
Returns the asset view of a covariance estimator, which is the estimator unchanged.
This is the fallback of port_opt_view for a covariance estimator that defines no method of its own. A covariance estimator of StatsBase holds no field that is indexed by asset, so its view is the estimator itself.
Arguments
ce: Covariance estimator.::Any: The asset indices. The method ignores them.args...: More arguments. The method ignores them.
Returns
ce::StatsBase.CovarianceEstimator: The original covariance estimator.
Related
PortfolioOptimisers.port_opt_view — Method
port_opt_view(
me::AbstractExpectedReturnsEstimator,
_,
args...
) -> SimpleExpectedReturns
Returns the asset view of an expected returns estimator, which is the estimator unchanged.
This is the fallback of port_opt_view for an expected returns estimator that defines no method of its own. An estimator that holds a field indexed by asset needs a method of its own.
Arguments
me: Expected returns estimator.::Any: The asset indices. The method ignores them.args...: More arguments. The method ignores them.
Returns
me::AbstractExpectedReturnsEstimator: The original expected returns estimator.
Related
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
PortfolioOptimisers.port_opt_view — Method
port_opt_view(
alg::AbstractExpectedReturnsAlgorithm,
_,
args...
) -> AbstractExpectedReturnsAlgorithm
Returns the asset view of an expected returns algorithm, which is the algorithm unchanged.
This is the fallback of port_opt_view for an expected returns algorithm that defines no method of its own.
Arguments
alg: The expected returns algorithm.::Any: The asset indices. The method ignores them.args...: More arguments. The method ignores them.
Returns
alg::AbstractExpectedReturnsAlgorithm: The original expected returns algorithm.
Related
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.cov — Method
Statistics.cov(ce::AbstractCovarianceEstimator, X::MatNum; dims::Int = 1, kwargs...)Computes the covariance matrix from the correlation matrix of the estimator and the standard deviations of its variance estimator ce.ve.
With this fallback, a covariance estimator that computes a correlation needs only its own Statistics.cor method. The fallback scales the correlation matrix by the standard deviations from std(ce.ve, X). An estimator whose covariance is not a scaled correlation defines its own method. ImpliedVolatility is one such estimator.
Mathematical definition
\[\begin{align} \hat{\mathbf{\Sigma}}_{ij} &= \hat{\rho}_{ij}\,\hat{\sigma}_i\,\hat{\sigma}_j\,. \end{align}\]
Where:
- $\hat{\mathbf{\Sigma}}$: Estimated covariance matrix.
- $\hat{\rho}_{ij}$: Correlation between assets $i$ and $j$.
- $\hat{\sigma}_i$: Standard deviation of asset $i$.
Algorithm
- Estimate the correlation matrix with
Statistics.cor(ce, X). - Estimate the marginal standard deviations with
Statistics.std(ce.ve, X). - Scale the correlation matrix into a covariance matrix with
StatsBase.cor2cov!. The call writes in place, over the matrix that step 1 returned.
Arguments
ce: Covariance estimator.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.dims: Dimension along which the computation runs.kwargs...: More keyword arguments, passed tocorand to the variance estimator.
Returns
sigma::MatNum: Covariance matrixassets x assets.
Related
Statistics.cov — Method
cov(
ce::AbstractCovarianceEstimator,
state::SampleBufferState;
kwargs...
) -> Any
Computes a covariance matrix from the observations of a SampleBufferState with the batch verb.
An estimator in an Online wrapper holds a refit Sample Buffer and not a family state, so it has no exact fold. Its estimate is the batch fit over the rows of the buffer. An uncapped buffer holds every observation folded so far, and a capped buffer holds the last max_history of them.
The method does no assert_partial_fittable check of its own. The batch verb accepts configurations that an incremental fold refuses, and the wrapper gives a caller access to them.
The buffer also keeps the masks of each observation that it folded. The method gives them to the batch verb, so a wrapped estimator under a CoveragePolicy returns the same value as an unwrapped one. The buffer keeps the implied volatilities and the ivpa of each fold too, so a wrapped ImpliedVolatility reads its surface over the same rows.
Arguments
ce: Covariance estimator.state: The buffer to read.kwargs...: More keyword arguments, passed to the batch verb.strictis one of them.
Returns
sigma::MatNum: Covariance matrix of the observations the buffer holds.
Related
Statistics.cor — Method
cor(
ce::AbstractCovarianceEstimator,
state::SampleBufferState;
kwargs...
) -> Any
Computes a correlation matrix from the observations of a SampleBufferState with the batch verb.
An estimator in an Online wrapper holds a refit Sample Buffer and not a family state, so it has no exact fold. Its estimate is the batch fit over the rows of the buffer. An uncapped buffer holds every observation folded so far, and a capped buffer holds the last max_history of them.
The method does no assert_partial_fittable check of its own. The batch verb accepts configurations that an incremental fold refuses, and the wrapper gives a caller access to them.
The buffer also keeps the masks of each observation that it folded. The method gives them to the batch verb, so a wrapped estimator under a CoveragePolicy returns the same value as an unwrapped one. The buffer keeps the implied volatilities and the ivpa of each fold too, so a wrapped ImpliedVolatility reads its surface over the same rows.
Arguments
ce: Covariance estimator.state: The buffer to read.kwargs...: More keyword arguments, passed to the batch verb.strictis one of them.
Returns
rho::MatNum: Correlation matrix of the observations the buffer holds.
Related
Statistics.var — Method
var(
ve::AbstractVarianceEstimator,
state::SampleBufferState
) -> Any
Computes the variance of each asset from the observations of a SampleBufferState with the batch verb.
An estimator in an Online wrapper holds a refit Sample Buffer and not a family state, so it has no exact fold. Its estimate is the batch fit over the rows of the buffer. An uncapped buffer holds every observation folded so far, and a capped buffer holds the last max_history of them.
The method does no assert_partial_fittable check of its own. The batch verb accepts configurations that an incremental fold refuses, and the wrapper gives a caller access to them.
The buffer also keeps the masks of each observation that it folded. The method gives them to the batch verb, so a wrapped estimator under a CoveragePolicy returns the same value as an unwrapped one.
Arguments
ve: Variance estimator.state: The buffer to read.
Returns
sigma2::ArrNum: Variance of the observations the buffer holds, one entry per asset.
Related
Statistics.std — Method
std(
ve::AbstractVarianceEstimator,
state::SampleBufferState
) -> Any
Computes the standard deviation of each asset from the observations of a SampleBufferState with the batch verb.
An estimator in an Online wrapper holds a refit Sample Buffer and not a family state, so it has no exact fold. Its estimate is the batch fit over the rows of the buffer. An uncapped buffer holds every observation folded so far, and a capped buffer holds the last max_history of them.
The method does no assert_partial_fittable check of its own. The batch verb accepts configurations that an incremental fold refuses, and the wrapper gives a caller access to them.
The buffer also keeps the masks of each observation that it folded. The method gives them to the batch verb, so a wrapped estimator under a CoveragePolicy returns the same value as an unwrapped one.
Arguments
ve: Variance estimator.state: The buffer to read.
Returns
sigma::ArrNum: Standard deviation of the observations the buffer holds, one entry per asset.
Related
Statistics.mean — Method
mean(
me::AbstractExpectedReturnsEstimator,
state::SampleBufferState
) -> Any
Computes the expected returns from the observations of a SampleBufferState with the batch verb.
An estimator in an Online wrapper holds a refit Sample Buffer and not a family state, so it has no exact fold. Its estimate is the batch fit over the rows of the buffer. An uncapped buffer holds every observation folded so far, and a capped buffer holds the last max_history of them.
The method does no assert_partial_fittable check of its own. The batch verb accepts configurations that an incremental fold refuses, and the wrapper gives a caller access to them.
The buffer also keeps the masks of each observation that it folded. The method gives them to the batch verb, so a wrapped estimator under a CoveragePolicy returns the same value as an unwrapped one.
Arguments
me: Expected returns estimator.state: The buffer to read.
Returns
mu::VecNum: Expected returns of the observations the buffer holds,assets × 1.
Related
Full and semi moments
A moment other than the expected return can use every deviation from the target, FullMoment, or only the deviations below the target, SemiMoment. An estimator that has both forms takes one of these two types in its alg field.
PortfolioOptimisers.FullMoment — Type
struct FullMoment <: AbstractMomentAlgorithmKeeps every deviation from the target, so the moment is two-sided.
Mathematical definition
\[\begin{align} \boldsymbol{D} &= \boldsymbol{X} - t \end{align}\]
Where:
- $\boldsymbol{X}$: Data vector
observations × 1. - $t$: Target value. It is usually the expected value $E[\boldsymbol{X}]$, weighted or unweighted.
Constructors
FullMoment() -> FullMomentExamples
julia> FullMoment()FullMoment()Related
PortfolioOptimisers.SemiMoment — Type
struct SemiMoment <: AbstractMomentAlgorithmClips every deviation above the target to zero, so the moment measures only the downside.
Mathematical definition
\[\begin{align} \boldsymbol{D} &= \min\left(\boldsymbol{X} - t,\, 0\right) \end{align}\]
Where:
- $\boldsymbol{X}$: Data vector
observations × 1. - $t$: Target value. It is usually the expected value $E[\boldsymbol{X}]$, weighted or unweighted.
Constructors
SemiMoment() -> SemiMomentExamples
julia> SemiMoment()SemiMoment()Related