Skip to content
13

Windowed variance

PortfolioOptimisers.WindowedVariance Type
julia
struct WindowedVariance{__T_ce, __T_w, __T_window} <: AbstractVarianceEstimator

Variance estimator that restricts computation to a rolling or indexed observation window.

WindowedVariance wraps another variance estimator and applies it to a subset of observations defined by a window and/or custom observation weights. This enables time-varying or recency-weighted variance estimation.

Fields

  • ce: Expected returns estimator.

  • w: Optional observation weights vector observations × 1, or a concrete subtype of DynamicAbstractWeights. If nothing, the computation is unweighted.

  • window: Window specification: an integer (last window observations) or a vector of indices.

Constructors

julia
WindowedVariance(;
    ce::AbstractVarianceEstimator = SimpleVariance(),
    w::Option{<:ObsWeights} = nothing,
    window::Option{<:Int_VecInt} = nothing
) -> WindowedVariance

Keywords correspond to the struct's fields.

Validation

  • If w is not nothing, !isempty(w).

  • If window is provided, it must be nonempty, nonnegative, and finite.

Related

source
PortfolioOptimisers.factory Method
julia
factory(ce::WindowedVariance, w::ObsWeights) -> WindowedVariance

Return a new WindowedVariance estimator with observation weights w applied to the underlying variance estimator and stored as the windowed weights.

Arguments

  • ce: Windowed variance estimator.

  • w: Observation weights vector observations × 1.

Returns

  • ce::WindowedVariance: Updated estimator with weights applied.

Related

source
Statistics.var Method
julia
Statistics.var(ce::WindowedVariance, X::MatNum; dims::Int = 1, mean = nothing, iv::Option{<:MatNum} = nothing,
               kwargs...)

Compute the variance vector using a rolling or indexed observation window (matrix input).

This method selects a window of observations from X, applies observation weights if specified, then delegates to the underlying variance estimator.

Arguments

  • ce: Windowed variance estimator.

  • X: Data matrix of asset returns (observations × assets).

  • dims: Dimension along which to perform the computation.

  • mean: Optional pre-computed mean passed to the underlying estimator.

  • iv: Optional implied volatility matrix. Used if any internal covariance estimator is an instance of ImpliedVolatility.

  • kwargs...: Additional keyword arguments passed to the underlying estimator.

Returns

  • var::Matrix{<:Number}: Variance vector for the selected window.

Related

source
Statistics.var Method
julia
Statistics.var(ce::WindowedVariance, X::VecNum; mean = nothing)

Compute the variance using a rolling or indexed observation window (vector input).

This method selects a window of observations from the vector X, applies observation weights if specified, then delegates to the underlying variance estimator.

Arguments

  • ce: Windowed variance estimator.

  • X: Data vector of returns.

  • mean: Optional pre-computed mean passed to the underlying estimator.

Returns

  • var::Number: Variance for the selected window.

Related

source
Statistics.std Method
julia
Statistics.std(ce::WindowedVariance, X::MatNum; dims::Int = 1, mean = nothing, iv::Option{<:MatNum} = nothing, kwargs...)

Compute the standard deviation vector using a rolling or indexed observation window (matrix input).

This method selects a window of observations from X, applies observation weights if specified, then delegates to the underlying variance estimator's std method.

Arguments

  • ce: Windowed variance estimator.

  • X: Data matrix of asset returns (observations × assets).

  • dims: Dimension along which to perform the computation.

  • mean: Optional pre-computed mean passed to the underlying estimator.

  • iv: Optional implied volatility matrix. Used if any internal covariance estimator is an instance of ImpliedVolatility.

  • kwargs...: Additional keyword arguments passed to the underlying estimator.

Returns

  • sd::Matrix{<:Number}: Standard deviation vector for the selected window.

Related

source
Statistics.std Method
julia
Statistics.std(ce::WindowedVariance, X::VecNum; mean = nothing)

Compute the standard deviation using a rolling or indexed observation window (vector input).

This method selects a window of observations from the vector X, applies observation weights if specified, then delegates to the underlying variance estimator's std method.

Arguments

  • ce: Windowed variance estimator.

  • X: Data vector of returns.

  • mean: Optional pre-computed mean passed to the underlying estimator.

Returns

  • sd::Number: Standard deviation for the selected window.

Related

source