(self, n_assets, max_weight=1)
Construct.
Construct.
Construct .
def __init__(self, n_assets, max_weight=1):
        """Construct."""
        super().__init__()
        covmat_sqrt = cp.Parameter((n_assets, n_assets))
        b = cp.Parameter(n_assets, nonneg=True)

        w = cp.Variable(n_assets)

        term_1 = 0.5 * cp.sum_squares(covmat_sqrt @ w)
        term_2 = b @ cp.log(w)

        objective = cp.Minimize(term_1 - term_2)  # refer [2]
        constraint = [cp.sum(w) == 1, w >= 0, w <= max_weight]  # refer [2]

        prob = cp.Problem(objective, constraint)

        assert prob.is_dpp()

        self.cvxpylayer = CvxpyLayer(prob, parameters=[covmat_sqrt, b], variables=[w])
def __init__ ( self , n_assets , max_weight = 1 ) : super ( ) . __init__ ( ) covmat_sqrt = cp . Parameter ( ( n_assets , n_assets ) ) b = cp . Parameter ( n_assets , nonneg = True ) w = cp . Variable ( n_assets ) term_1 = 0.5 * cp . sum_squares ( covmat_sqrt @ w ) term_2 = b @ cp . log ( w ) objective = cp . Minimize ( term_1 - term_2 ) # refer [2] constraint = [ cp . sum ( w ) == 1 , w >= 0 , w <= max_weight ] # refer [2] prob = cp . Problem ( objective , constraint ) assert prob . is_dpp ( ) self . cvxpylayer = CvxpyLayer ( prob , parameters = [ covmat_sqrt , b ] , variables = [ w ] )