def negative_cvar(weights, returns, s=<NUM_LIT>, beta=<NUM_LIT>, random_state=None):
np.random.seed(seed=random_state)<EOL>portfolio_returns = (weights * returns).sum(axis=<NUM_LIT:1>)<EOL>dist = scipy.stats.gaussian_kde(portfolio_returns)<EOL>sample = dist.resample(s)<EOL>var = portfolio_returns.quantile(<NUM_LIT:1> - beta)<EOL>return -sample[sample < var].mean()<EOL>
Calculate the negative CVaR. Though we want the "min CVaR portfolio", we
actually need to maximise the expected return of the worst q% cases, thus
we need this value to be negative.

:param weights: asset weights of the portfolio
:type weights: np.ndarray
:param returns: asset returns
:type returns: pd.DataFrame or np.ndarray
:param s: number of bootstrap draws, defaults to 10000
:type s: int, optional
:param beta: "significance level" (i. 1 - q), defaults to 0.95
:type beta: float, optional
:param random_state: seed for random sampling, defaults to None
:type random_state: int, optional
:return: negative CVaR
:rtype: float