def negative_sharpe(<EOL>weights, expected_returns, cov_matrix, gamma=<NUM_LIT:0>, risk_free_rate=<NUM_LIT><EOL>):
mu = weights.dot(expected_returns)<EOL>sigma = np.sqrt(np.dot(weights, np.dot(cov_matrix, weights.T)))<EOL>L2_reg = gamma * (weights ** <NUM_LIT:2>).sum()<EOL>return -(mu - risk_free_rate) / sigma + L2_reg<EOL>
Calculate the negative Sharpe ratio of a portfolio

:param weights: asset weights of the portfolio
:type weights: np.ndarray
:param expected_returns: expected return of each asset
:type expected_returns: pd.Series
:param cov_matrix: the covariance matrix of asset returns
:type cov_matrix: pd.DataFrame
:param gamma: L2 regularisation parameter, defaults to 0. Increase if you want more
                non-negligible weights
:type gamma: float, optional
:param risk_free_rate: risk-free rate of borrowing/lending, defaults to 0.02
:type risk_free_rate: float, optional
:return: negative Sharpe ratio
:rtype: float