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

        ret = rets @ w
        prob = cp.Problem(cp.Maximize(ret), [cp.sum(w) == 1,
                                             w >= 0,
                                             w <= max_weight])

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