Generic Non-Parametric Representation Codependence

The Generic Non-Parametric Representation Codependence (GNPR) combines how two assets move together, from the ranks of their returns, with how much their return distributions differ (Marti, Andler, Nielsen and Donnat, 2016). Two assets are close when they move together and their returns are distributed alike.

The formula for the Generic Non-Parametric Representation Codependence starts from the rank distance \(d_{1}^{2}\) of the ranks \(R_{i , t}\) of the returns over the T periods, equal to \((1 - \rho_{S}) / 2\) with \(\rho_{S}\) the Spearman correlation when there are no ties, and the squared Hellinger distance \(d_{0}^{2}\) between the histograms \(g_{i , b}\) of the returns of the two assets over their bins b:

\[d_{1}^{2} = \frac{3 \cdot \sum_{t=1}^{T} (R_{i,t} - R_{j,t})^{2}}{T \cdot \left(T^{2} - 1\right)}\] \[d_{0}^{2} = \frac{\sum_{b=1}^{B} \left(\sqrt{g_{i,b}} - \sqrt{g_{j,b}}\right)^{2}}{2}\]

The squared distance \(d^{2}\) weighs the two with theta, and the codependence \(c_{i , j}\) is one minus it:

\[d^{2} = \theta \cdot d_{1}^{2} + (1 - \theta) \cdot d_{0}^{2}\] \[c_{i,j} = 1 - d^{2}\]

A theta of 1 compares only how the assets move together, 0 only how their returns are distributed. Two assets with the same ranks but a different volatility are close at \(\theta = 1\) and apart at \(\theta = 0\).

It is the codependence that the hierarchical optimizers (HRP, HERC, NCO) and get_asset_clusters take, or the distance they cluster on. Hierarchical portfolio construction groups the assets by how much they move together and spreads the capital across the groups, so the codependence decides which assets end up together. The Pearson correlation captures only linear co-movement on average; the other codependences capture co-movement in ranks, in large moves only, in any form of dependence or in crashes. Each comes with a distance, zero for assets that move as one, that the clustering works on (Mantegna, 1999).

Also known as: GNPR, copula distance.

In the Finance Toolkit this is get_codependence_matrix with method="gnpr", the same function as Codependence Matrix.

Example · AAPL, MSFT, JNJ, XOM · 2021 to 2025

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

from financetoolkit import Toolkit

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

toolkit.portfolio.get_codependence_matrix(method="gnpr")

Which returns:

References

  • Paper Marti, G., Andler, S., Nielsen, F. and Donnat, P. (2016). “Clustering Financial Time Series: How Long Is Enough?” Proceedings of the Twenty-Fifth International Joint Conference on Artificial Intelligence (IJCAI-16), 2583-2589.
Share