(n_assets, max_weight)
return CvxpyLayer(prob, parameters=[covmat_sqrt], variables=[w])
Construct cvxpylayers problem.
Construct cvxpylayers problem.
Construct cvxpylayers problem .
def _construct_problem(n_assets, max_weight):
        """Construct cvxpylayers problem."""
        covmat_sqrt = cp.Parameter((n_assets, n_assets))
        w = cp.Variable(n_assets)

        risk = cp.sum_squares(covmat_sqrt @ w)
        prob = cp.Problem(cp.Minimize(risk), [cp.sum(w) == 1,
                                              w >= 0,
                                              w <= max_weight])

        return CvxpyLayer(prob, parameters=[covmat_sqrt], variables=[w])
def _construct_problem ( n_assets , max_weight ) : covmat_sqrt = cp . Parameter ( ( n_assets , n_assets ) ) w = cp . Variable ( n_assets ) risk = cp . sum_squares ( covmat_sqrt @ w ) prob = cp . Problem ( cp . Minimize ( risk ) , [ cp . sum ( w ) == 1 , w >= 0 , w <= max_weight ] ) return CvxpyLayer ( prob , parameters = [ covmat_sqrt ] , variables = [ w ] )