text: .
  def calc_neg_sharpe(weights, mean_returns, cov, rf): portfolio_return = np.sum(mean_returns * weights) * 252 portfolio_std = np.sqrt(np.dot(weights.T, np.dot(cov, weights))) * np.sqrt(252) sharpe_ratio = (portfolio_return - rf) / portfolio_std return -sharpe_ratio constraints = ({'type': 'eq', 'fun': lambda x: np.sum(x) - 1}) def max_sharpe_ratio(mean_returns, cov, rf): num_assets =).
  As a note, VaR is sometimes calculated in such a way that the mean returns of the portfolio are considered to be small enough that they can be entered into the equation with a zero value – this tends to make more sense when we are looking at VaR over short time periods like a daily or a weekly VaR figure, however when we start to look at annualised VaR figures it begins to make more sense to incorporate a “non-zero” return element.