Exponentially Weighted Variance: private API
Types
PortfolioOptimisers.ExpWeightedVarianceState — Type
struct ExpWeightedVarianceState{__T_variance, __T_location, __T_obs_count, __T_active} <: AbstractPartialFitStateInternal mutable cache for the online variance update in ExpWeightedVariance.
This type is an implementation detail and is not intended for direct use.
Fields
variance: Running per-asset variance vector.
location: Exponentially smoothed location (mean) vector.
obs_count: Per-asset count of observations processed.
active: Boolean mask indicating which assets are currently active.
Related
Functions
PortfolioOptimisers.process_observation! — Method
process_observation!(
cache::ExpWeightedVarianceState,
ce::ExpWeightedVariance,
X::AbstractVector{<:Union{var"#s136", var"#s53"} where {var"#s136"<:Number, var"#s53"<:AbstractJuMPScalar}},
active_mask::Union{Nothing, AbstractVector{<:Bool}}
) -> ExpWeightedVarianceState
Processes a single observation row (or column) to update the online variance cache.
An asset is valid when its return is finite and the active mask admits it. A valid asset takes the ordinary recursion, an active asset with a non-finite return freezes, and an asset that has just become inactive is reset to the cold state so that the bias correction restarts if it lists again. Where centred is false the deviation is taken from the location that stands before the observation, and the location is advanced afterwards.
Arguments
cache::ExpWeightedVarianceState: Online variance computation cache (mutated).ce::ExpWeightedVariance: Variance estimator configuration.X::VecNum: Returns vector for the current observation.active_mask::Option{<:AbstractVector{<:Bool}}: Optional mask of currently active assets. An asset that becomes inactive has its variance, its location and its count reset. Withnothingevery asset is active, so a non-finite return reads as a holiday.
Returns
cache::ExpWeightedVarianceState: The cache to read on and to pass to the next observation. Every field is an array that is mutated in place.
Related
PortfolioOptimisers.exp_weighted_pass! — Function
exp_weighted_pass!(
f,
est::ExpWeightedVariance,
X::AbstractMatrix{<:Union{var"#s136", var"#s53"} where {var"#s136"<:Number, var"#s53"<:AbstractJuMPScalar}},
dims::Int64,
active_mask::Union{Nothing, AbstractMatrix{<:Bool}}
) -> ExpWeightedVarianceState
exp_weighted_pass!(
f,
est::ExpWeightedVariance,
X::AbstractMatrix{<:Union{var"#s136", var"#s53"} where {var"#s136"<:Number, var"#s53"<:AbstractJuMPScalar}},
dims::Int64,
active_mask::Union{Nothing, AbstractMatrix{<:Bool}},
state::Union{Nothing, ExpWeightedVarianceState}
) -> ExpWeightedVarianceState
Variance method of exp_weighted_pass!. Runs one forward pass of the online variance update over the observations of X, and calls f after each observation.
Related
PortfolioOptimisers.exp_weighted_pass! — Function
exp_weighted_pass!(
est::ExpWeightedVariance,
X::AbstractMatrix{<:Union{var"#s136", var"#s53"} where {var"#s136"<:Number, var"#s53"<:AbstractJuMPScalar}},
dims::Int64,
active_mask::Union{Nothing, AbstractMatrix{<:Bool}}
) -> ExpWeightedVarianceState
exp_weighted_pass!(
est::ExpWeightedVariance,
X::AbstractMatrix{<:Union{var"#s136", var"#s53"} where {var"#s136"<:Number, var"#s53"<:AbstractJuMPScalar}},
dims::Int64,
active_mask::Union{Nothing, AbstractMatrix{<:Bool}},
state::Union{Nothing, ExpWeightedVarianceState}
) -> ExpWeightedVarianceState
Variance method of exp_weighted_pass!. Runs one forward pass of the online variance update over the observations of X, and reads no intermediate cache.
Related
PortfolioOptimisers.exp_weighted_moment — Method
exp_weighted_moment(
cache::ExpWeightedVarianceState,
est::ExpWeightedVariance
) -> Any
Variance method of exp_weighted_moment. Reads the exponentially weighted variance out of a cache, as it stands.
Applies the cold-start bias correction and blanks every asset that is not ready. The cache is read, never written, so the same cache answers this call after every observation of a forward pass.
Returns
variance::Vector{<:Number}: Per-asset variance vector. An asset that is inactive, or that carries fewer thanest.min_obsvalid observations, isNaN.
Related
PortfolioOptimisers.variance_series — Method
variance_series(
ce::ExpWeightedVariance,
X::MatNum;
dims::Int = 1,
active_mask::Option{<:AbstractMatrix{<:Bool}} = nothing,
kwargs...
) -> Matrix{<:Number}Compute the point-in-time exponentially weighted variance series.
Row t holds what var returns for the first t observations of X, so no row reads an observation after its own. The update is a recursion over one observation, so this method overrides the expanding-window fallback with a single forward pass: it reads the cache after each observation instead of refitting.
The fallback cannot answer this estimator. It slices X once per row and passes every keyword unsliced, so a mask of the whole window meets a window of t observations and the size check refuses the call.
Arguments
ce: Exponentially weighted variance estimator.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.dims: Dimension along which to perform the computation.active_mask: Optional boolean matrix with the same size asX.kwargs: Additional keyword arguments (ignored).
Validation
dims in (1, 2).- If
active_maskis notnothing,size(X) == size(active_mask).
Returns
val::Matrix{<:Number}: Variance series, shaped as(T, N)ifdims == 1or(N, T)ifdims == 2. An asset with fewer thance.min_obsobservations at rowtisNaNthere.
Related
PortfolioOptimisers.variance_series — Method
variance_series(
ce::ExpWeightedVariance,
X::MatNum,
pnl::Option{<:AssetPanel};
dims::Int = 1,
kwargs...
) -> Matrix{<:Number}Compute the point-in-time exponentially weighted variance series from a window of an Asset Panel.
This is the variance of the same call, read after each observation, and it reads the panel's active mask through the same override. A Descriptor that holds this estimator therefore keeps a number for a young asset, where the reduce-and-expand root would reduce every window and answer NaN.
Arguments
ce: Exponentially weighted variance estimator.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.pnl: OptionalAssetPanel, whose active mask the Coverage Universe of the fit is derived from.nothingmakes the rule finiteness alone.dims: Dimension along which to perform the computation.kwargs: Additional keyword arguments (ignored).
Returns
val::Matrix{<:Number}: Variance series on the full asset universe, shaped as(T, N)ifdims == 1or(N, T)ifdims == 2.
Related
Base.copy — Method
copy(
x::ExpWeightedVarianceState
) -> ExpWeightedVarianceState
Copies an ExpWeightedVarianceState, so the copy shares no array with the original.
The copy method of the AbstractPartialFitState interface, which partial_fit calls before it folds. Every field is an array, and every one is copied.
Arguments
x: The cache to copy.
Returns
state::ExpWeightedVarianceState: A fresh cache, equal tox, whose arrays are fresh.
Related