Coskewness Matrix
Calculate the coskewness matrix M3 of the assets, the third co-moments of their returns: how the return of one asset moves with the joint variation of two others.
The skewness of a portfolio with weights w is w’M3(w ⊗ w) / σ_p³, so M3 is the input of mean-variance-skewness optimizations and the modified (Cornish-Fisher) VaR of a portfolio.
The formula is as follows:
\[m_{ijk} = \Sigma_{t} w_{t} (r_{ti} - \mu_{i}) (r_{tj} - \mu_{j}) (r_{tk} - \mu_{k})\] \[\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{only returns below the average count});\;\; \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}},\;\; z_{i,t} \sigma_{i,T} + \frac{1}{s(z_{i}) (\text{Bollerslev},\; 1990 ; \;\text{see}\; \text{get\_covariance\_estimate})},\;\; \text{the next-period coskewness of the model}\] \[\text{standardized:}\;\; \frac{m_{ijk}}{\sigma_{i} \sigma_{j} \sigma_{k}} \;\text{with}\; \sigma^{2} = \Sigma_{t} w_{t} (r_{t} - \mu)^{2}\]Also known as: coskewness, third co-moment matrix, M3.
Example · AAPL, MSFT, JNJ · 2021 to 2025
Install the Finance Toolkit with pip install financetoolkit -U, then call get_coskewness_matrix:
from financetoolkit import Toolkit
toolkit = Toolkit(
["AAPL", "MSFT", "JNJ"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2021-01-01",
end_date="2025-12-31",
)
# The coskewness of each pair of assets with AAPL
toolkit.portfolio.get_coskewness_matrix().loc[:, "AAPL"]
Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:
What is the coskewness matrix of the returns of Apple, Microsoft and Johnson & Johnson from 2021 to 2025?
Which returns:
| Item | AAPL | MSFT | JNJ |
|---|---|---|---|
| AAPL | 0.4539 | 0.3026 | 0.0257 |
| MSFT | 0.3026 | 0.1980 | -0.0169 |
| JNJ | 0.0257 | -0.0169 | -0.1682 |
3 rows
Parameters
get_coskewness_matrix accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
method | str | The 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" |
period | str | The 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" |
span | int | The span in periods of the exponential weights. Defaults to 180. | 180 |
standardized_moments | bool | Whether to divide by the product of the standard deviations, so the diagonal \(m_{\text{iii}}\) is the skewness of each asset and the entries are comparable across frequencies. Defaults to True. | True |
include_benchmark | bool | Whether to include the benchmark as an asset. Defaults to False. | True |
rounding | int | None | The number of decimals to round the results to. Defaults to None, which uses the Toolkit’s rounding. | 2 |
show_columns | str | list[str] | None | The 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 Martellini, L. and Ziemann, V. (2010). “Improved Estimates of Higher-Order Comoments and Implications for Portfolio Selection.” The Review of Financial Studies, 23(4), 1467-1502.
- Library Shares similar logic as PerformanceAnalytics (R)’s M3.MM (sample)
- Library Shares similar logic as PerformanceAnalytics (R)’s M3.ewma (exponential)
- Library Shares similar logic as PortfolioAnalytics (R)’s CCCgarch.MM (CCC-GARCH)