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