← Back to Problems
The Covariance Matrix
Medium prediction Linear Algebra Probability & Statistics
Time limit: 4 s per test  ·  Memory: 256 MB

The daily returns of p assets are independent draws from a multivariate normal distribution with mean zero and an unknown covariance matrix Sigma. In every test case, Sigma is the sum of a low-rank factor component and a diagonal idiosyncratic component, scaled by heterogeneous asset volatilities; the number of factors, the loadings, the idiosyncratic variances and the volatilities are not disclosed and vary between test cases.

You observe n days of returns, with n only slightly larger than p. Estimate Sigma.

Input

The first line contains n and p. Each of the next n lines contains p real numbers, the returns of that day, with at most 6 digits after the decimal point.

Output

p lines of p real numbers: your estimate of Sigma. It must be symmetric and positive definite; otherwise the case scores 0.

Scoring

Your estimate is scored by Stein's loss against the true covariance,

L(S_hat) = ln det(S_hat) + tr(S_hat^{-1} Sigma),

normalized between two anchors: the diagonal matrix of sample variances scores 0 and the true Sigma scores 1,

score = clip((L(D) - L(S_hat)) / (L(D) - L(Sigma)), 0, 1).

The case score is this value; estimates worse than the diagonal baseline score 0.

Constraints

30 <= p <= 100

1.2 p <= n <= 3 p

Python 3.13 i Execution environment Isolated microVM · 1 vCPU · no internet access Time and memory limits are set per problem Available packages numpy 2.5.0scipy 1.18.0pandas 3.0.0scikit-learn 1.9.0statsmodels 0.15.0cvxpy 1.9.2