Windowed covariance

PortfolioOptimisers.WindowedCovarianceType
struct WindowedCovariance{__T_ce, __T_w, __T_window} <: AbstractCovarianceEstimator

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

WindowedCovariance wraps another covariance 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 covariance estimation.

Fields

  • ce: Covariance estimator.

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

  • window: Observation window. An integer selects the last window observations, and a vector of indices selects those observations.

Constructors

WindowedCovariance(;    ce::StatsBase.CovarianceEstimator = PortfolioOptimisersCovariance(),    w::Option{<:ObsWeights} = nothing,    window::Option{<:Int_VecInt} = nothing) -> WindowedCovariance

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:

Observation weight parameters

When obs_weights_view is called on this type, the following fields are automatically indexed to the selected observations:

Examples

julia> WindowedCovariance()WindowedCovariance      ce ┼ PortfolioOptimisersCovariance         │   ce ┼ Covariance         │      │    me ┼ SimpleExpectedReturns         │      │       │   w ┴ nothing         │      │    ce ┼ GeneralCovariance         │      │       │   ce ┼ StatsBase.SimpleCovariance: StatsBase.SimpleCovariance(true)         │      │       │    w ┴ nothing         │      │   alg ┼ FullMoment()         │      │     w ┴ nothing         │   mp ┼ MatrixProcessing         │      │     pdm ┼ Posdef         │      │         │      alg ┼ UnionAll: NearestCorrelationMatrix.Newton         │      │         │   kwargs ┴ @NamedTuple{}: NamedTuple()         │      │      dn ┼ nothing         │      │      dt ┼ nothing         │      │     alg ┼ nothing         │      │   order ┴ NTuple{4, Symbol}: (:pdm, :dn, :dt, :alg)       w ┼ nothing  window ┴ nothing

Related

source
Statistics.covMethod
Statistics.cov(ce::WindowedCovariance, X::MatNum; dims::Int = 1, mean = nothing, iv::Option{<:MatNum} = nothing, kwargs...)

Compute Statistics.cov 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 covariance estimator.

Algorithm

  1. Resolve the window and the observation weights with windowed_preamble, giving inner, a copy of ce.ce that carries the windowed weights, together with the windowed X and the windowed iv.
  2. Call Statistics.cov on inner and the windowed X, and return its result. The inner estimator alone decides the value, so the window and the weights are the whole of this method's contribution.

Arguments

  • ce: Windowed covariance 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

  • sigma::MatNum: Covariance matrix assets x assets.

Related

source
Statistics.corMethod
Statistics.cor(ce::WindowedCovariance, X::MatNum; dims::Int = 1, mean = nothing, iv::Option{<:MatNum} = nothing, kwargs...)

Compute Statistics.cor 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 covariance estimator.

Algorithm

  1. Resolve the window and the observation weights with windowed_preamble, giving inner, a copy of ce.ce that carries the windowed weights, together with the windowed X and the windowed iv.
  2. Call Statistics.cor on inner and the windowed X, and return its result. The inner estimator alone decides the value, so the window and the weights are the whole of this method's contribution.

Arguments

  • ce: Windowed covariance 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

  • rho::MatNum: Correlation matrix assets x assets.

Related

source