Calmcode - cvxpy two: constrain

Constrain

1 2 3 4 5 6 7 8

The new code, with constraints, now looks like this;

x = cp.Variable(len(mean_stock))

stock_return = mean_stock * x
stock_risk = cp.quad_form(x, cov_stock)
p = 1

objective = cp.Maximize(stock_return - p * stock_risk)
constraints = [x >= 0, cp.sum(x) == 1]
prob = cp.Problem(objective=objective, constraints=constraints)
prob.solve(), x.value