Skip to content
13

High Order Prior

PortfolioOptimisers.HighOrderPriorEstimator Type
julia
struct HighOrderPriorEstimator{__T_pe, __T_kte, __T_ske} <: AbstractHighOrderPriorEstimator

High 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: Low order prior estimator (AbstractLowOrderPriorEstimator_A_F_AF).

  • kte: Cokurtosis estimator (CokurtosisEstimator or Nothing).

  • ske: Coskewness estimator (CoskewnessEstimator or Nothing).

Constructors

julia
HighOrderPriorEstimator(;
    pe::AbstractLowOrderPriorEstimator_A_F_AF = EmpiricalPrior(),
    kte::Option{<:CokurtosisEstimator} = Cokurtosis(;
        alg = Full()
    ),
    ske::Option{<:CoskewnessEstimator} = Coskewness(;
        alg = Full()
    )
) -> HighOrderPriorEstimator

Keywords correspond to the struct's fields.

Examples

julia
julia> HighOrderPriorEstimator()
HighOrderPriorEstimator
   pe ┼ EmpiricalPrior
      │        ce ┼ PortfolioOptimisersCovariance
      │           │   ce ┼ Covariance
      │           │      │    me ┼ SimpleExpectedReturns
      │           │      │       │   w ┴ nothing
      │           │      │    ce ┼ GeneralCovariance
      │           │      │       │   ce ┼ StatsBase.SimpleCovariance: StatsBase.SimpleCovariance(true)
      │           │      │       │    w ┴ nothing
      │           │      │   alg ┴ Full()
      │           │   mp ┼ DenoiseDetoneAlgMatrixProcessing
      │           │      │     pdm ┼ Posdef
      │           │      │         │      alg ┼ UnionAll: NearestCorrelationMatrix.Newton
      │           │      │         │   kwargs ┴ @NamedTuple{}: NamedTuple()
      │           │      │      dn ┼ nothing
      │           │      │      dt ┼ nothing
      │           │      │     alg ┼ nothing
      │           │      │   order ┴ DenoiseDetoneAlg()
      │        me ┼ SimpleExpectedReturns
      │           │   w ┴ nothing
      │   horizon ┴ nothing
  kte ┼ Cokurtosis
      │    me ┼ SimpleExpectedReturns
      │       │   w ┴ nothing
      │    mp ┼ DenoiseDetoneAlgMatrixProcessing
      │       │     pdm ┼ Posdef
      │       │         │      alg ┼ UnionAll: NearestCorrelationMatrix.Newton
      │       │         │   kwargs ┴ @NamedTuple{}: NamedTuple()
      │       │      dn ┼ nothing
      │       │      dt ┼ nothing
      │       │     alg ┼ nothing
      │       │   order ┴ DenoiseDetoneAlg()
      │   alg ┴ Full()
  ske ┼ Coskewness
      │    me ┼ SimpleExpectedReturns
      │       │   w ┴ nothing
      │    mp ┼ DenoiseDetoneAlgMatrixProcessing
      │       │     pdm ┼ Posdef
      │       │         │      alg ┼ UnionAll: NearestCorrelationMatrix.Newton
      │       │         │   kwargs ┴ @NamedTuple{}: NamedTuple()
      │       │      dn ┼ nothing
      │       │      dt ┼ nothing
      │       │     alg ┼ nothing
      │       │   order ┴ DenoiseDetoneAlg()
      │   alg ┴ Full()

Related

source
PortfolioOptimisers.prior Function
julia
prior(pe::HighOrderPriorEstimator, X::MatNum, F::Option{<:MatNum} = 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.

Arguments

  • pe: High order prior estimator.

  • X: Asset returns matrix (observations × assets).

  • F: Optional factor returns matrix (observations × factors).

  • dims: Dimension along which to perform the computation.

  • kwargs...: Additional keyword arguments passed to underlying estimators.

Returns

  • pr::HighOrderPrior: Result object containing asset returns, mean vector, covariance matrix, coskewness tensor, cokurtosis tensor, and related quantities.

Validation

  • dims in (1, 2).

Related

source
PortfolioOptimisers.block_vec_pq Function
julia
block_vec_pq(A::MatNum, p::Integer, q::Integer)

Block vectorisation operator.

block_vec_pq transforms a matrix A into a block vectorised form, partitioning A into blocks of size (p, q) and stacking the vectorised blocks row-wise. This is useful for higher-order moment computations and tensor manipulations in portfolio analytics.

Arguments

  • A: Input matrix of size (m * p, n * q), where m and n are integers.

  • p: Number of rows in each block.

  • q: Number of columns in each block.

Returns

  • A_vec::Matrix: Block vectorised matrix of size (m * n, p * q).

Validation

  • size(A, 1) must be an integer multiple of p.

  • size(A, 2) must be an integer multiple of q.

Examples

julia
julia> A = [1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16];

julia> PortfolioOptimisers.block_vec_pq(A, 2, 2)
4×4 Matrix{Int64}:
  1   5   2   6
  9  13  10  14
  3   7   4   8
 11  15  12  16

Related

source
PortfolioOptimisers.elimination_matrix Function
julia
elimination_matrix(n::Int, diag::Bool = true)

Construct the elimination matrix for a symmetric matrix of size n × n.

The elimination matrix L extracts the unique (lower triangular) elements of a symmetric matrix. Used internally in coskewness and cokurtosis computation.

Arguments

  • n: Size of the symmetric matrix.

  • diag: Whether to include the diagonal elements.

Returns

  • Sparse elimination matrix.

Related

source
PortfolioOptimisers.summation_matrix Function
julia
summation_matrix(n::Int, diag::Bool = true)

Construct the summation matrix for a symmetric matrix of size n × n.

The summation matrix S adds up contributions from both triangular halves of a symmetric matrix. Used internally in coskewness and cokurtosis computation.

Arguments

  • n: Size of the symmetric matrix.

  • diag: Whether to include the diagonal elements.

Returns

  • Sparse summation matrix.

Related

source
PortfolioOptimisers.dup_elim_sum_matrices Function
julia
dup_elim_sum_matrices(n::Int)

Construct duplication, elimination, and summation matrices for symmetric matrix vectorisation.

dup_elim_sum_matrices returns the duplication matrix D, elimination matrix L, and summation matrix S for symmetric matrices of size N × N. These matrices are used in higher-order moment computations, tensor manipulations, and efficient vectorisation of symmetric matrices in portfolio analytics.

Arguments

  • n: Size of the symmetric matrix (integer).

Returns

  • D::SparseMatrixCSC{Int64, Int64}: Duplication matrix (n^2 × m), where m = n(n+1)/2.

  • L::SparseMatrixCSC{Int64, Int64}: Elimination matrix (m × n^2).

  • S::SparseMatrixCSC{Int64, Int64}: Summation matrix (m × n^2).

Validation

  • n must be a positive integer.

Examples

julia
julia> D, L, S = PortfolioOptimisers.dup_elim_sum_matrices(3);

julia> D
9×6 SparseArrays.SparseMatrixCSC{Int64, Int64} with 9 stored entries:
 1
  1
  1
  1
  1
  1
  1
  1
  1

julia> L
6×9 SparseArrays.SparseMatrixCSC{Int64, Int64} with 6 stored entries:
 1
  1
  1
  1
  1
  1

julia> S
6×9 SparseArrays.SparseMatrixCSC{Int64, Int64} with 6 stored entries:
 1
  2
  2
  1
  2
  1

Related

source
PortfolioOptimisers.duplication_matrix Function
julia
duplication_matrix(n::Int, diag::Bool = true)

Construct the duplication matrix for a symmetric matrix of size n × n.

The duplication matrix D maps the vech (half-vectorisation) of a symmetric matrix to its full vec. Used internally in coskewness and cokurtosis computation.

Arguments

  • n: Size of the symmetric matrix.

  • diag: Whether to include the diagonal elements.

Returns

  • Sparse duplication matrix.

Related

source