Random Matrix Statistics
Fit the Marčenko-Pastur distribution to the eigenvalues of the correlation matrix of the assets, to see how much of it random returns alone could produce.
The eigenvalues of the correlation matrix of T periods of N unrelated returns with variance \(\sigma^{2}\) fall between the edges \(\lambda -\) and \(\lambda +\) of the Marčenko-Pastur distribution; an eigenvalue above \(\lambda +\) is signal (the market, sectors, styles), the ones below it are indistinguishable from noise and are what the denoised covariance estimators average, remove or shrink (López de Prado, 2020, chapter 2).
The formula is as follows:
\[f(\lambda) = \frac{q}{(2 \pi \sigma^{2} \lambda) \sqrt{(\lambda + - \lambda) (\lambda - \lambda -)}} \;\text{for}\; \lambda - \leq \lambda \leq \lambda +,\;\; \text{with}\;\; q = \frac{T}{N}\] \[\lambda \pm = \sigma^{2}\left(1 \pm \sqrt{\frac{1}{q}}\right)^{2}\] \[\sigma^{2} \;\text{minimizes}\; \Sigma_{x} (f(x) - k(x))^{2} \;\text{over}\; \text{1,000} \;\text{points}\; x \;\text{between}\; \lambda - \text{and}\; \lambda +,\;\; \text{with } k \text{ a Gaussian kernel density of the eigenvalues (bandwidth 0.01)},\;\; \text{from}\; \sigma^{2} = 0.5 \;\text{and between}\; 0.00001 \;\text{and}\; 0.99999 (\text{López} \,\mathrm{d}e \;\text{Prado},\; 2020,\; \text{section}\; 2.4)\]- signal eigenvalues: \(\lambda_{k} > \lambda +\)
Also known as: Marchenko-Pastur, Marcenko-Pastur fit, random matrix theory, RMT, eigenvalue spectrum, noise eigenvalues, signal eigenvalues.
Example · AAPL, MSFT, JNJ, XOM, 4 more · 2021 to 2025
Install the Finance Toolkit with pip install financetoolkit -U, then call get_random_matrix_statistics:
from financetoolkit import Toolkit
toolkit = Toolkit(
["AAPL", "MSFT", "JNJ", "XOM", "JPM", "PG", "KO", "NVDA"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2021-01-01",
end_date="2025-12-31",
)
toolkit.portfolio.get_random_matrix_statistics(output="eigenvalues")
Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:
Which eigenvalues of the correlation matrix of Apple, Microsoft, Johnson & Johnson, ExxonMobil, JPMorgan Chase, Procter & Gamble, Coca-Cola and Nvidia from 2021 to 2025 stand out from noise?
Which returns:
| Item | Eigenvalue | Explained Variance | Signal |
|---|---|---|---|
| Eigenvalue 1 | 2.8517 | 0.3565 | 1 |
| Eigenvalue 2 | 1.7914 | 0.2239 | 1 |
| Eigenvalue 3 | 1.0929 | 0.1366 | 0 |
| Eigenvalue 4 | 0.6160 | 0.0770 | 0 |
| Eigenvalue 5 | 0.5604 | 0.0701 | 0 |
| Eigenvalue 6 | 0.4080 | 0.0510 | 0 |
| Eigenvalue 7 | 0.3617 | 0.0452 | 0 |
| Eigenvalue 8 | 0.3178 | 0.0397 | 0 |
8 rows
Parameters
get_random_matrix_statistics accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
output | str | Options are: “summary” (one row: the Periods, Assets, Noise Variance \(\sigma^{2}\), Lower Edge \(\lambda -\), Upper Edge \(\lambda +\), Largest Eigenvalue, the number of Signal Eigenvalues and their Signal Share of the trace N), “eigenvalues” (every eigenvalue from the largest, its Explained Variance \(\lambda / N\) and whether it is Signal). Defaults to “summary”. | "summary" |
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" |
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 Marčenko, V. A. and Pastur, L. A. (1967). “Distribution of Eigenvalues for Some Sets of Random Matrices.” Mathematics of the USSR-Sbornik, 1(4), 457-483.
- Paper Laloux, L., Cizeau, P., Potters, M. and Bouchaud, J.-P. (2000). “Random Matrix Theory and Financial Correlations.” International Journal of Theoretical and Applied Finance, 3(3), 391-397.
- Paper López de Prado, M. (2020). “Machine Learning for Asset Managers.” Cambridge University Press, chapter 2.
- Library Shares similar logic as RiskLabAI’s find_max_eval
- Library Shares similar logic as RiskLabAI’s marcenko_pastur_pdf