Cokurtosis: private API
PortfolioOptimisers._cokurtosis — Function
_cokurtosis(X::MatNum, mp::AbstractMatrixProcessingEstimator, w::Option{<:ObsWeights}) -> MatNumBuilds the square cokurtosis matrix of a deviation matrix.
_cokurtosis returns the $N^{2} \times N^{2}$ matrix. The matrix processing estimator repairs it in place before the return.
Mathematical definition
The pairwise expansion of the deviation matrix has the rows:
\[\begin{align} \mathbf{Z}_{t,\cdot} &= (\boldsymbol{1}^\intercal \otimes \boldsymbol{y}_t^\intercal) \odot (\boldsymbol{y}_t^\intercal \otimes \boldsymbol{1}^\intercal)\,. \end{align}\]
The $N^{2} \times N^{2}$ square cokurtosis matrix is:
Unweighted:
\[\begin{align} \hat{\mathbf{K}} &= \frac{1}{T} \mathbf{Z}^\intercal \mathbf{Z}\,. \end{align}\]
Weighted:
\[\begin{align} \hat{\mathbf{K}} &= \frac{1}{\sum_{t=1}^{T} w_t} (\boldsymbol{w} \odot \mathbf{Z})^\intercal \mathbf{Z}\,. \end{align}\]
Where:
- $\hat{\mathbf{K}}$: The $N^{2} \times N^{2}$ square cokurtosis matrix. Its entry $\hat{\mathbf{K}}_{(i-1)N+j,\,(k-1)N+l}$ is the fourth comoment of the deviations of the assets $i$, $j$, $k$ and $l$, so the matrix is symmetric. This is $\mathbf{\Sigma}_{4}$ of Section 2 of [66], which Appendix A of that work computes with the formula above. It is not $\mathbf{M}_{4}$ of Section 2.3 of [64], which is $N \times N^{3}$, and the library never builds $\mathbf{M}_{4}$. The weighted form is an addition of this library.
- $\mathbf{Y}$: $T \times N$ deviation matrix.
FullMomenttakes the centred returns, andSemiMomentclips every positive entry of them to zero. - $\boldsymbol{y}_t$: $N \times 1$ deviation vector of observation $t$, the $t$-th row of $\mathbf{Y}$. Its $i$-th entry is $y_{t,\,i}$.
- $\mathbf{Z}$: $T \times N^{2}$ pairwise expansion of $\mathbf{Y}$, whose $t$-th row is $\mathbf{Z}_{t,\cdot}$ and whose entry $\mathbf{Z}_{t,\,(i-1)N+j}$ is the product $y_{t,\,i} \, y_{t,\,j}$.
- $\boldsymbol{w}$: $T \times 1$ observation weights vector.
- $w_{t}$: Observation weight of observation $t$.
- $T$: Number of observations.
- $N$: Number of assets.
- $\boldsymbol{1}$: The $N \times 1$ vector of ones.
- $\otimes$: The Kronecker product.
- $\odot$: The element-wise product. When the operands differ in shape, it broadcasts along the row axis.
Algorithm
- Build
o, the $1 \times N$ row of ones. - Build
z, the pairwise expansionkron(o, X) ⊙ kron(X, o). Its column(i - 1) * N + jis the element-wise product of the columnsiandjofX. - Without weights, form
ckurtastranspose(z) * z / T. - With weights, form
ckurtastranspose(w .* z) * z / sum(w). The weights multiply the left factor alone, so each summand carries one weight and not four. - Run
matrix_processing!onckurtin place, and return it. With weights, runsample_matrix_processing!with the count of the weights fromobservation_weight_count, so that the denoising step reads the effective number of observations and notsize(X, 1).
Arguments
X: The deviation matrix (observations × assets). The caller centres it.mp: The matrix processing estimator.w: The optional observation weights. The unweighted method takesnothingthrough itsargs....
Returns
ckurt::MatNum: Square cokurtosis matrixassets² x assets².mpprocesses it in place.
Related
References
References
- [64]
- E. Jondeau and M. Rockinger. Optimal portfolio allocation under higher moments. Notes d'Études et de Recherche 108 (Banque de France, 2004).
- [66]
- D. Cajas. Convex Optimization of Portfolio Kurtosis. Available at SSRN 4202967 (2022).