from cvxpy import *
import numpy as np
from posdef import *

mu = np.matrix([[-0.01132331],[-0.05061149],[-0.00729714],[-0.06206554],[-0.01079347],[0.0025]])
Sigma = np.array(
	[[2.52879395e-03, 1.85425637e-03, 9.20436767e-04, 1.95914715e-03, 4.28396944e-03, 0.00000000e+00],
	 [1.85425637e-03, 2.15246031e-03, 9.42088127e-04, 1.58969365e-03, 3.30104182e-03, 0.00000000e+00],
	 [  9.20436767e-04, 9.42088127e-04, 2.17054891e-03, 7.91879289e-04, 1.39817285e-03, 0.00000000e+00],
	 [  1.95914715e-03, 1.58969365e-03, 7.91879289e-04, 1.67831424e-03, 3.77524505e-03, 0.00000000e+00],
	 [  4.28396944e-03, 3.30104182e-03, 1.39817285e-03, 3.77524505e-03, 8.72500053e-03, 0.00000000e+00],
	 [  0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.73472348e-18]])

print(isPD(Sigma))

min_return = 0.0
n = 6

w = Variable(n)
ret = mu.T*	w
risk = quad_form(w, Sigma)
min_ret = Parameter(sign='positive')
min_ret.value = min_return

prob = Problem(Minimize(risk),
               [ret >= min_ret,
               sum_entries(w) == 1,
               w >= 0])
prob.solve()
print(w.value)
