skfolio.measures.cvar#
- skfolio.measures.cvar(returns, beta=0.95, sample_weight=None)[source]#
Compute the CVaR (conditional value at risk).
The CVaR (or Tail VaR) represents the mean shortfall at a specified confidence level (beta).
- Parameters:
- returnsndarray of shape (n_observations,) or (n_observations, n_assets)
Array of return values.
- betafloat, default=0.95
Confidence level between 0 and 1, inclusive. CVaR averages the worst
1 - betaprobability mass. At 0, CVaR is the negative mean of the usable returns. At 1, it is the largest loss with positive weight.- sample_weightndarray of shape (n_observations,), optional
Relative observation weights. Must be finite and nonnegative. If None, equal weights are assumed.
- Returns:
- valuefloat or ndarray of shape (n_assets,)
CVaR. If
returnsis a 1D-array, the result is a float. Ifreturnsis a 2D-array, the result is a ndarray of shape (n_assets,).
Notes
NaN handling: NaN returns are excluded from each column’s calculation. Remaining sample weights are rescaled to sum to one. The result is NaN if no observations or no positive weight remain.