A desk can trade n assets whose returns have covariance matrix Sigma (symmetric, positive definite). Find the fully invested portfolio with the smallest variance: weights w_1, ..., w_n minimizing w' Sigma w subject to w_1 + ... + w_n = 1. Shorting is allowed: weights may be negative.
The first line contains n. The next n lines each contain n numbers: the covariance matrix.
n real numbers on one line: the optimal weights, each with absolute or relative error at most 1e-9.
2 <= n <= 400
The covariance matrix is symmetric positive definite with entries given to 8 decimal places
This is a standard problem: a submission scores full points if it produces the correct output for every test case, and zero otherwise.
Numeric answers are accepted if they are within an absolute tolerance of 1e-09 or a relative tolerance of 1e-09 of the expected value.
2 0.01733436 -0.00241317 -0.00241317 0.28196566
9.350680092314e-01 6.493199076857e-02
4 0.08564242 0.00000000 0.00000000 -0.00935349 0.00000000 0.08564242 0.00000000 0.00000000 0.00000000 0.00000000 0.08564242 -0.01038007 -0.00935349 0.00000000 -0.01038007 0.08564242
2.498295476748e-01 2.195231386197e-01 2.531557877635e-01 2.774915259420e-01