High Order Prior
PortfolioOptimisers.HighOrderPriorEstimator — Type
struct HighOrderPriorEstimator{__T_pe, __T_kte, __T_ske} <: AbstractHighOrderPriorEstimatorHigh order prior estimator for asset returns.
HighOrderPriorEstimator is a composite estimator that computes high order moments (coskewness and cokurtosis) for asset returns, in addition to low order moments (mean and covariance). It combines a low order prior estimator, a cokurtosis estimator, and a coskewness estimator to produce a HighOrderPrior result containing all relevant moments for advanced portfolio analytics.
Fields
pe: Prior estimator.
kte: Cokurtosis estimator.
ske: Coskewness estimator.
Constructors
HighOrderPriorEstimator(; pe::Onl{<:AbstractLowOrderPriorEstimator_A_F_AF} = EmpiricalPrior(), kte::Option{<:CokurtosisEstimator} = Cokurtosis(; alg = FullMoment() ), ske::Option{<:CoskewnessEstimator} = Coskewness(; alg = FullMoment() )) -> HighOrderPriorEstimatorKeywords correspond to the struct's fields.
Propagated parameters
When factory is called on this type, the following @fprop-tagged fields are automatically propagated:
pe: Recursively updated viafactory.kte: Recursively updated viafactory.ske: Recursively updated viafactory.
View parameters
When port_opt_view is called on this type, the following @vprop-tagged fields are automatically subset to the selected indices:
pe: Recursively viewed viaport_opt_view.kte: Recursively viewed viaport_opt_view.ske: Recursively viewed viaport_opt_view.
Examples
julia> HighOrderPriorEstimator()HighOrderPriorEstimator pe ┼ EmpiricalPrior │ 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) │ me ┼ SimpleExpectedReturns │ │ w ┴ nothing │ horizon ┼ nothing │ fill_limit ┴ nothing kte ┼ Cokurtosis │ me ┼ SimpleExpectedReturns │ │ 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) │ alg ┼ FullMoment() │ w ┼ nothing │ cache ┴ nothing ske ┼ Coskewness │ me ┼ SimpleExpectedReturns │ │ 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) │ alg ┼ FullMoment() │ w ┼ nothing │ cache ┴ nothingRelated
AbstractHighOrderPriorEstimatorAbstractLowOrderPriorEstimator_A_F_AFHighOrderPriorEmpiricalPriorCokurtosisEstimatorCoskewnessEstimatorCokurtosisCoskewnesspriorfactoryport_opt_view
References
PortfolioOptimisers.prior — Function
prior(pe::HighOrderPriorEstimator, X::MatNum, F::Option{<:MatNum} = nothing, pnl::Option{<:AssetPanel} = nothing; dims::Int = 1, kwargs...)Compute high order prior moments for asset returns using a composite estimator.
prior estimates the mean, covariance, coskewness, and cokurtosis of asset returns using the specified high order prior estimator. It first computes low order moments (mean and covariance) using the embedded prior estimator, then computes coskewness and cokurtosis tensors using the provided coskewness and cokurtosis estimators. Optionally, factor returns F can be provided for factor-based estimation. The result is returned as a HighOrderPrior object.
Mathematical definition
In addition to the first and second moments, the high order estimator computes the coskewness matrix $\mathbf{M}_3$ and the square cokurtosis matrix $\mathbf{\Sigma}_4$:
\[\begin{align} \mathbf{W} &= (\mathbf{Z} \otimes \boldsymbol{1}_N^\intercal) \odot (\boldsymbol{1}_N^\intercal \otimes \mathbf{Z})\,, \\ \mathbf{M}_3 &= \frac{1}{T} \mathbf{Z}^\intercal \mathbf{W}\,, \\ \mathbf{\Sigma}_4 &= \frac{1}{T} \mathbf{W}^\intercal \mathbf{W}\,. \end{align}\]
Where:
- $\mathbf{Z}$: $T \times N$ matrix of returns with each column's mean removed.
- $\mathbf{W}$: $T \times N^2$ matrix of pairwise products of the centred returns.
- $\mathbf{M}_3$: $N \times N^2$ coskewness matrix,
sk. - $\mathbf{\Sigma}_4$: $N^2 \times N^2$ square cokurtosis matrix,
kt. - $\boldsymbol{1}_N$: $N \times 1$ vector of ones.
- $T$: Number of observations.
- $\otimes$: Kronecker product.
- $\odot$: Hadamard product.
$\mathbf{\Sigma}_4$ is the square form and is $N^2 \times N^2$. It is not the $N \times N^3$ cokurtosis matrix $\mathbf{M}_4$ of the same source, which the library never builds.
pe.kte computes kt and pe.ske computes sk, so a non-default alg — a semi-comoment, an exponentially weighted one — replaces the displays above rather than refining them. V is the negative spectral coskewness of sk, and either estimator set to nothing drops its moment from the result.
Algorithm
- Orient
XandFtoobservations × variableswithdims_oriented. - Compute the low order block
prwithpe.pe, passingFthrough. - Compute the square cokurtosis
ktwithpe.kte. Anothingestimator gives anothingmoment. - Compute the coskewness
skand its negative spectral formVwithpe.ske. Anothingestimator givesnothingfor both. - Build the structure matrices at the asset count
size(pr.X, 2)withdup_elim_sum_matrices. Take all three when steps 3 and 4 both produced a moment, takeL2andS2alone when step 3 produced one and step 4 did not, and take none otherwise.D2servesskand the pairL2,S2serveskt, which is why the second case leavesD2asnothing. - Assemble the
HighOrderPriorthrough its keyword constructor, carryingpe.ske.mpasskmpwhen step 4 produced ansk. Every@argcheckof the constructor runs on the shapes steps 3 to 5 produced.
Arguments
pe: High order prior estimator.X: Asset returns matrix (observations × assets).F: Optional factor returns matrix (observations × factors).pnl: OptionalAssetPanel, the panel the carrier held. A wrapping prior forwards it unchanged, so that it can compose an estimator that is fitted on a panel. An estimator that reads no panel ignores it.dims: Dimension along which to perform the computation.kwargs...: Additional keyword arguments passed to underlying estimators.
Validation
dims in (1, 2).
Returns
pr::HighOrderPrior: Result object containing asset returns, mean vector, covariance matrix, coskewness tensor, cokurtosis tensor, and related quantities.
Related
References
- [5]
- D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025).
- [30]
- D. Cajas. Convex Optimization of Portfolio Kurtosis. Available at SSRN 4202967 (2022).