Rank-one covariance
RankOneCovariance is the covariance estimate of the short-term loss-control portfolio. It keeps only the first principal component of a short window of price relatives, and scales it against the total variance of the centred window. The matrix has rank one, so it is positive semi-definite and always singular.
PortfolioOptimisers.RankOneCovariance — Type
struct RankOneCovariance{__T_shift, __T_cache} <: AbstractCovarianceEstimatorEstimates the covariance of a short window as a rank-one matrix along the principal direction of its price relatives.
Lai et al. [102] define the estimate for short-term portfolio optimisation, where the window holds a few observations of many assets. The matrix is positive semidefinite and singular, so it has no Cholesky factor. A consumer reads it as a quadratic form, as Variance does under QuadRiskExpr.
Mathematical definition
\[\begin{align} \mathbf{X}^\intercal \mathbf{X} \boldsymbol{u}_1 &= \theta_1 \boldsymbol{u}_1\,, \\ \hat{\mathbf{\Sigma}}_{\mathrm{MP}} &= \mathbf{X}^\intercal \left( \mathbf{I} - \frac{1}{w} \boldsymbol{1} \boldsymbol{1}^\intercal \right) \mathbf{X}\,, \\ \zeta_1^\star &= \theta_1 \left( \frac{\operatorname{tr}(\hat{\mathbf{\Sigma}}_{\mathrm{MP}})}{N (w - 1)} \right)^{-1/2}\,, \\ \hat{\mathbf{\Sigma}}_{\mathrm{RO}} &= \zeta_1^\star \boldsymbol{u}_1 \boldsymbol{u}_1^\intercal\,. \end{align}\]
Where:
- $\mathbf{X}$: $w \times N$ window of price relatives, one row per observation, not centred.
- $w$: Number of observations in the window.
- $N$: Number of assets.
- $\theta_1$: Largest eigenvalue of $\mathbf{X}^\intercal \mathbf{X}$, the square of the largest singular value of $\mathbf{X}$.
- $\boldsymbol{u}_1$: Unit eigenvector of $\mathbf{X}^\intercal \mathbf{X}$ at $\theta_1$, the principal right singular vector of $\mathbf{X}$.
- $\hat{\mathbf{\Sigma}}_{\mathrm{MP}}$: Scatter matrix of the window, the sum of the outer products of its centred rows.
- $\mathbf{I}$: Identity matrix.
- $\zeta_1^\star$: Energy of the estimate along $\boldsymbol{u}_1$.
- $\hat{\mathbf{\Sigma}}_{\mathrm{RO}}$: Rank-one covariance estimate of a window, the matrix that
RankOneCovariancecomputes.
This is Algorithm 1 of [102]. Equations 42 and 49 of [102] write the trace of $\hat{\mathbf{\Sigma}}_{\mathrm{MP}}$ in the basis of the singular vectors of $\mathbf{X}$, as $\operatorname{tr}(D)$, which is the same number. The quotient $\operatorname{tr}(\hat{\mathbf{\Sigma}}_{\mathrm{MP}}) / (N (w - 1))$ is the mean of the $N$ sample variances of the window. So $\zeta_1^\star$ is $\theta_1$ over the root of the mean variance. That value minimises the trade-off of equation 48 between the magnitude of $\theta_1 \boldsymbol{u}_1 \boldsymbol{u}_1^\intercal$ and the magnitude of $\hat{\mathbf{\Sigma}}_{\mathrm{MP}}$.
Equation 47 divides the trace of a matrix by its rank, and equation 49 puts the rank of $\hat{\mathbf{\Sigma}}_{\mathrm{MP}}$ at $w - 1$. That is the rank of a short window, $w \leq N + 1$, which is the case that [102] studies. On a longer window the rank is at most $N$, but the definition keeps $w - 1$, as Algorithm 1 and the code that accompanies [102] do. When every row of the window is the same, $\operatorname{tr}(\hat{\mathbf{\Sigma}}_{\mathrm{MP}}) = 0$ and $\zeta_1^\star$ is not defined.
Fields
shift: Number added to every entry of the returns to form the price relatives $\mathbf{X}$. The default1turns returns into price relatives, which the estimate reads, and0decomposes the rows as given.
cache: Optional partial-fit state. It isnothinguntilpartial_fit!writes one. When the caller gives no data matrix, the batch verb of the estimator reads it. Each propagation channel does one thing with it.factorykeeps it unchanged, because a factory call resolves the configuration, not the sample.port_opt_viewcopies the entries of the selected assets into a new state, so the viewed estimator holds the state of those assets alone.obs_weights_viewremoves it, because a state has no slice on the observation axis. Only a type with an observation-weights field has that channel. A type with no such field falls through to the identity method, so it keeps its state. A family whose state has no exact asset slice removes it on both axes and names the reason.
Constructors
RankOneCovariance(; shift::Real = 1, cache::Option{<:AbstractPartialFitState} = nothing) -> RankOneCovarianceKeywords correspond to the struct's fields.
Validation
isfinite(shift). ADomainErroris thrown otherwise.
Propagated parameters
factory passes its arguments on to this @fprop field:
cache: Carried unchanged throughfactory.
View parameters
port_opt_view takes the view of this @vprop field at the selected indices:
cache: Sliced to the selected assets throughport_opt_view.
Examples
julia> RankOneCovariance()RankOneCovariance shift ┴ Int64: 1Related
AbstractCovarianceEstimatorShortTermLossControlPortfolio: the programme that reads the estimate.VarianceQuadRiskExpr
References
- [102] Z.-R. Lai, L. Tan, X. Wu and L. Fang. Loss control with rank-one covariance estimate for short-term portfolio optimization. Journal of Machine Learning Research 21, 1–37 (2020). Algorithm 1 and equations 42 to 49.
Statistics.cov — Method
Statistics.cov(ce::RankOneCovariance, X::MatNum; dims::Int = 1, kwargs...)Computes the rank-one covariance of a window of returns, assets × assets.
RankOneCovariance states the mathematics.
Algorithm
- Orient
Xtoobservations × assetswithdims_oriented. - Add
ce.shiftto every entry ofXto form the price relativesXs. - Subtract the column means from
Xs, and sum the squares of the result. The sumtrDis the trace of the scatter matrix. - Compute the singular value decomposition of
Xs. Taketheta, the square of the largest singular value, andu, its right singular vector. - Compute
zeta = theta * sqrt(N * (w - 1) / trD). When every row ofXsis the same, or whentrDis zero,zetais zero. The method compares the rows, because the column means of equal rows carry round-off, andtrDof a constant window is often a tiny positive number. - Return
zeta .* (u .* transpose(u)). The method forms the outer product entry by entry, so the matrix is exactly symmetric.
Arguments
ce: The rank-one covariance estimator.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.dims: Dimension along which the computation runs.kwargs...: Additional keyword arguments. The method ignores them, because the estimate reads no mean and no observation weights.
Validation
dims in (1, 2).size(X, 1) >= 2after orientation. AnArgumentErroris thrown otherwise, because one row has no centred energy.
Returns
sigma::Matrix: The rank-one covariance matrix, positive semidefinite and symmetric. It is the zero matrix when every row of the window is the same.
Related
Statistics.cor — Method
Statistics.cor(ce::RankOneCovariance, X::MatNum; dims::Int = 1, kwargs...)Computes the correlation matrix of the rank-one covariance of a window of returns, assets × assets.
Mathematical definition
\[\begin{align} \rho_{ij} &= \frac{\hat{\Sigma}_{ij}}{\sqrt{\hat{\Sigma}_{ii} \hat{\Sigma}_{jj}}} = \operatorname{sign}(u_{1i} u_{1j})\,. \end{align}\]
Where:
- $\rho_{ij}$: Correlation between assets $i$ and $j$.
- $\hat{\Sigma}_{ij}$: Entry of $\hat{\mathbf{\Sigma}}_{\mathrm{RO}}$ in row $i$ and column $j$.
- $u_{1i}$: Entry $i$ of the principal vector $\boldsymbol{u}_1$ of
RankOneCovariance.
The second equality holds when $\zeta_1^\star > 0$ and both assets have a non-zero entry in $\boldsymbol{u}_1$. Otherwise the variance of one of the two assets is zero, and $\rho_{ij}$ is not defined.
Algorithm
- Compute
sigmawith thecovmethod ofRankOneCovariance. - Take the sign of every entry of
sigma. - Set the diagonal to one.
Arguments
ce: The rank-one covariance estimator.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.dims: Dimension along which the computation runs.kwargs...: Additional keyword arguments. The method passes them tocov, which ignores them.
Validation
- Every check of the
covmethod applies.
Returns
rho::Matrix: The correlation matrix, with ones on the diagonal and $\pm 1$ off it. An entry whose correlation is not defined is zero.
Related
References
- [102]
- Z.-R. Lai, L. Tan, X. Wu and L. Fang. Loss control with rank-one covariance estimate for short-term portfolio optimization. Journal of Machine Learning Research 21, 1–37 (2020).