Variance from covariance
Statistics.var — Method
Statistics.var(ce::AbstractCovarianceEstimator, X::MatNum; dims::Int = 1, kwargs...)Compute the variance vector from the diagonal of the covariance matrix.
This method extracts the diagonal of the covariance matrix returned by Statistics.cov(ce, X; dims = dims, kwargs...) and reshapes it into a row or column vector depending on dims.
Mathematical definition
\[\begin{align} \hat{\sigma}_i^2 &= \hat{\mathbf{\Sigma}}_{ii}\,. \end{align}\]
Where:
- $\hat{\sigma}_i^2$: Variance of asset $i$.
- $\hat{\mathbf{\Sigma}}$: Estimated covariance matrix.
- $\hat{\mathbf{\Sigma}}_{ii}$: $i$-th diagonal element of $\hat{\mathbf{\Sigma}}$.
Arguments
ce: Covariance estimator.X: Data matrix of asset returns (observations × assets).dims: Dimension along which to perform the computation.kwargs...: Additional keyword arguments passed to the covariance estimator.
Returns
var::Matrix{<:Number}: Variance vector, shaped as(1, N)ifdims == 1or(N, 1)ifdims == 2.
Related
Statistics.std — Method
Statistics.std(ce::AbstractCovarianceEstimator, X::MatNum; dims::Int = 1, kwargs...)Compute the standard deviation vector from the diagonal of the covariance matrix.
This method extracts the diagonal of the covariance matrix returned by Statistics.cov(ce, X; dims = dims, kwargs...), takes the element-wise square root, and reshapes it into a row or column vector depending on dims.
Mathematical definition
\[\begin{align} \hat{\sigma}_i &= \sqrt{\hat{\mathbf{\Sigma}}_{ii}}\,. \end{align}\]
Where:
- $\hat{\sigma}_i$: Standard deviation of asset $i$.
- $\hat{\mathbf{\Sigma}}$: Estimated covariance matrix.
- $\hat{\mathbf{\Sigma}}_{ii}$: $i$-th diagonal element of $\hat{\mathbf{\Sigma}}$.
Arguments
ce: Covariance estimator.X: Data matrix of asset returns (observations × assets).dims: Dimension along which to perform the computation.kwargs...: Additional keyword arguments passed to the covariance estimator.
Returns
sd::Matrix{<:Number}: Standard deviation vector, shaped as(1, N)ifdims == 1or(N, 1)ifdims == 2.
Related