Cokurtosis Matrix

Calculate the cokurtosis matrix M4 of the assets, the fourth co-moments of their returns: how often assets have extreme returns at the same time.

The kurtosis of a portfolio with weights w is w’M4(w ⊗ w ⊗ w) / σ_p⁴, the input of kurtosis-aware optimizations and the modified (Cornish-Fisher) VaR of a portfolio.

The formula is as follows:

\[m_{\text{ijkl}} = \Sigma_{t} w_{t} (r_{ti} - \mu_{i}) (r_{tj} - \mu_{j}) (r_{tk} - \mu_{k}) (r_{tl} - \mu_{l})\] \[\text{Sample:}\;\; w_{t} = \frac{1}{T};\;\; \text{exponential:}\;\; w_{t} = \frac{\lambda^{T - t}}{\sum \lambda^{T - s}} \;\text{with}\; \lambda = 1 - \frac{2}{\text{span} + 1};\;\; \text{semi:}\;\; w_{t} = 1 / T \;\text{with} \;\min(r_{ti} - \mu_{i},\; 0) \;\text{in place of every deviation},\;\; \text{the lower semi cokurtosis};\;\; \text{CCC-GARCH:}\;\; w_{t} = \frac{1}{T \;\text{on the standardized residuals of the CCC-GARCH}(1,\; 1) \;\text{model at the next-period volatilities}} \;(\text{see}\; \text{get\_coskewness\_matrix}),\;\; \text{the next-period cokurtosis of the model}\] \[\text{standardized:}\;\; \frac{m_{\text{ijkl}}}{\sigma_{i} \sigma_{j} \sigma_{k} \sigma_{l}} \;\text{with}\; \sigma^{2} = \Sigma_{t} w_{t} (r_{t} - \mu)^{2}\]

Also known as: cokurtosis, fourth co-moment matrix, M4, semi cokurtosis.

Example · AAPL, MSFT · 2021 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_cokurtosis_matrix:

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["AAPL", "MSFT"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

# The cokurtosis of each pair of assets with AAPL twice
toolkit.portfolio.get_cokurtosis_matrix().loc[:, ("AAPL", "AAPL")]

Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:

What is the cokurtosis matrix of the returns of Apple and Microsoft from 2021 to 2025?

Which returns:

Parameters

get_cokurtosis_matrix accepts the following parameters.

ParameterTypeDescriptionExample
methodstrThe estimator of the co-moments. Options are: “sample” (equal weights), “exponential” (exponentially weighted), “semi” (lower semi co-moment), “ccc_garch” (CCC-GARCH scenarios). Defaults to “sample”."sample"
periodstrThe frequency of the returns. Options are: “daily” (daily returns), “weekly” (weekly returns), “monthly” (monthly returns), “quarterly” (quarterly returns), “yearly” (yearly returns). Defaults to “daily”."weekly"
spanintThe span in periods of the exponential weights. Defaults to 180.180
standardized_momentsboolWhether to divide by the product of the standard deviations, so the diagonal \(m_{\text{iiii}}\) is the kurtosis of each asset (3 for a normal distribution, not the excess). Defaults to True.True
include_benchmarkboolWhether to include the benchmark as an asset. Defaults to False.True
roundingint | NoneThe number of decimals to round the results to. Defaults to None, which uses the Toolkit’s rounding.2
show_columnsstr | list[str] | NoneThe columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column.None, which keeps every column

References

  • Paper Jondeau, E. and Rockinger, M. (2006). “Optimal Portfolio Allocation under Higher Moments.” European Financial Management, 12(1), 29-55.
  • Paper Cajas, D. (2022). “Convex Optimization of Portfolio Kurtosis.” SSRN 4202967.
  • Library Shares similar logic as PerformanceAnalytics (R)’s M4.MM (sample)
  • Library Shares similar logic as PerformanceAnalytics (R)’s M4.ewma (exponential)
  • Library Shares similar logic as Riskfolio-Lib’s cokurt_matrix (sample and semi, as N² × N²)
  • Library Shares similar logic as PortfolioAnalytics (R)’s CCCgarch.MM (CCC-GARCH)
Share