def __init__(self, expected_returns, cov_matrix, weight_bounds=(0, 1), gamma=0):
        """
        :param expected_returns: expected returns for each asset. Set to None if
                                 optimising for volatility only.
        :type expected_returns: pd.Series, list, np.ndarray
        :param cov_matrix: covariance of returns for each asset
        :type cov_matrix: pd.DataFrame or np.array
        :param weight_bounds: minimum and maximum weight of an asset, defaults to (0, 1).
                              Must be changed to (-1, 1) for portfolios with shorting.
        :type weight_bounds: tuple, optional
        :param gamma: L2 regularisation parameter, defaults to 0. Increase if you want more
                      non-negligible weights
        :type gamma: float, optional
        :raises TypeError: if ``expected_returns`` is not a series, list or array
        :raises TypeError: if ``cov_matrix`` is not a dataframe or array
        """
        # Inputs
        self.cov_matrix = cov_matrix
        if expected_returns is not None:
            if not isinstance(expected_returns, (pd.Series, list, np.ndarray)):
                raise TypeError("expected_returns is not a series, list or array")
            if not isinstance(cov_matrix, (pd.DataFrame, np.ndarray)):
                raise TypeError("cov_matrix is not a dataframe or array")
            self.expected_returns = expected_returns
        if isinstance(expected_returns, pd.Series):
            tickers = list(expected_returns.index)
        elif isinstance(cov_matrix, pd.DataFrame):
            tickers = list(cov_matrix.columns)
        else:
            tickers = list(range(len(expected_returns)))

        super().__init__(len(tickers), tickers, weight_bounds)

        if not isinstance(gamma, (int, float)):
            raise ValueError("gamma should be numeric")
        if gamma < 0:
            warnings.warn("in most cases, gamma should be positive", UserWarning)
        self.gamma = gamma
def __init__ ( self , expected_returns , cov_matrix , weight_bounds = ( 0 , 1 ) , gamma = 0 ) : self . cov_matrix = cov_matrix if expected_returns is not None : if not isinstance ( expected_returns , ( pd . Series , list , np . ndarray ) ) : raise TypeError ( "expected_returns is not a series, list or array" ) if not isinstance ( cov_matrix , ( pd . DataFrame , np . ndarray ) ) : raise TypeError ( "cov_matrix is not a dataframe or array" ) self . expected_returns = expected_returns if isinstance ( expected_returns , pd . Series ) : tickers = list ( expected_returns . index ) elif isinstance ( cov_matrix , pd . DataFrame ) : tickers = list ( cov_matrix . columns ) else : tickers = list ( range ( len ( expected_returns ) ) ) super ( ) . __init__ ( len ( tickers ) , tickers , weight_bounds ) if not isinstance ( gamma , ( int , float ) ) : raise ValueError ( "gamma should be numeric" ) if gamma < 0 : warnings . warn ( "in most cases, gamma should be positive" , UserWarning ) self . gamma = gamma
:param expected_returns: expected returns for each asset. Set to None if
                                 optimising for volatility only.
        :type expected_returns: pd.Series, list, np.ndarray
        :param cov_matrix: covariance of returns for each asset
        :type cov_matrix: pd.DataFrame or np.array
        :param weight_bounds: minimum and maximum weight of an asset, defaults to (0, 1).
                              Must be changed to (-1, 1) for portfolios with shorting.
        :type weight_bounds: tuple, optional
        :param gamma: L2 regularisation parameter, defaults to 0. Increase if you want more
                      non-negligible weights
        :type gamma: float, optional
        :raises TypeError: if ``expected_returns`` is not a series, list or array
        :raises TypeError: if ``cov_matrix`` is not a dataframe or array