Skip to content
18

Windowed variance

PortfolioOptimisers.WindowedVariance Type
julia
struct WindowedVariance{__T_ve, __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

  • ve: Variance 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(;
    ve::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.

Propagated parameters

When factory is called on this type, the following @fprop-tagged fields are automatically propagated:

View parameters

When port_opt_view is called on this type, the following @vprop-tagged fields are automatically subset to the selected indices:

Examples

julia
julia> WindowedVariance()
WindowedVariance
      ve ┼ SimpleVariance
         │          me ┼ SimpleExpectedReturns
         │             │   w ┴ nothing
         │           w ┼ nothing
         │   corrected ┴ Bool: true
       w ┼ nothing
  window ┴ nothing

Related

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

Compute Statistics.var over a rolling or indexed observation window (matrix input).

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

Arguments

  • ve: 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

  • vr::ArrNum: Variance vector of X, reshaped to be consistent with the dimension along which the value is computed.

Related

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

Compute Statistics.var over a rolling or indexed observation window (vector input).

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

Arguments

  • ve: Windowed variance estimator.

  • X: Data vector of returns.

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

Returns

  • vr::Number: Variance of X

Related

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

Compute Statistics.std over a rolling or indexed observation window (matrix input).

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

Arguments

  • ve: 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::ArrNum: Standard deviation vector of X, reshaped to be consistent with the dimension along which the value is computed.

Related

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

Compute Statistics.std over a rolling or indexed observation window (vector input).

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

Arguments

  • ve: Windowed variance estimator.

  • X: Data vector of returns.

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

Returns

  • vr::Number: Standard deviation of X

Related

source