Variance from covariance: private API
PortfolioOptimisers.variance_series — Method
variance_series(ce::AbstractCovarianceEstimator, X::MatNum; dims::Int = 1, kwargs...)Compute the point-in-time variance series, one row per observation.
Row t holds the variance of each asset estimated from observations 1 to t alone, so a caller that reads row t - 1 holds a variance that observation t did not enter. That is what a weight paired with observation t needs: a variance carrying the date-t squared residual would down-weight an asset for its own shock, and would correlate the weights with the residuals.
This method is the fallback that gives every AbstractCovarianceEstimator a series, so a member needs no method of its own to answer correctly. It refits on an expanding window, at a cost of one fit per observation. A member whose estimate is a recursion overrides it with a single forward pass.
Mathematical definition
\[\begin{align} \mathbf{V}_{ti} &= \hat{\sigma}_i^2\left(\mathbf{X}_{1:t}\right)\,. \end{align}\]
Where:
- $\mathbf{V}_{ti}$: Variance of asset $i$ after observation $t$.
- $\hat{\sigma}_i^2$: Variance of asset $i$, as
ceestimates it. - $\mathbf{X}_{1:t}$: First $t$ observations of the data matrix.
- $T$: Number of observations.
Algorithm
- Orient
Xso that the observations lie on the rows. - For each observation
t, callStatistics.var(ce, X[1:t, :]; dims = 1, kwargs...)and write the result into rowt. - Return the series, transposed when
dims == 2.
Arguments
ce: Covariance estimator.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.dims: Dimension along which to perform the computation.kwargs...: Additional keyword arguments passed to the variance estimator. A keyword carrying one entry per observation is passed unsliced, so an estimator that takes one must override this method.
Validation
dims in (1, 2).
Returns
val::Matrix{<:Number}: Variance series, shaped as(T, N)ifdims == 1or(N, T)ifdims == 2.
Examples
julia> X = [0.01 0.02; 0.03 0.04; 0.02 0.03];julia> PortfolioOptimisers.variance_series(SimpleVariance(), X)3×2 Matrix{Float64}: NaN NaN 0.0002 0.0002 0.0001 0.0001Row 1 is a fit on a single observation, so an estimator that needs two returns NaN there.
Related