qis.compute_cvar¶
- qis.compute_cvar(returns, confidence_level=0.95)[source]¶
Compute historical CVaR (expected shortfall) as a loss-positive quantity.
Each nonmissing observation has equal probability. Average exactly the worst
1 - confidence_levelprobability mass, with fractional weight on the boundary observation. This is the empirical Rockafellar–Uryasev expected shortfall, including distributions with ties. It is not the mean of every observation below an interpolated sample quantile, which can include the wrong tail mass.- Parameters:
returns (Series | DataFrame) – Period returns in decimal units. Series or DataFrame columns are treated independently, omitting NaNs. Supply returns at the required risk horizon (for example monthly simple returns for one-month CVaR). No return conversion, frequency resampling or annualisation is performed.
confidence_level (float) – Confidence probability strictly between zero and one.
- Returns:
Scalar for a Series, or a Series indexed by DataFrame columns. A positive value denotes a loss; an entirely profitable tail can produce a negative value. Empty or entirely missing samples produce NaN.
- Raises:
TypeError – If returns is not a pandas Series or DataFrame.
ValueError – If confidence_level is invalid, or a return is infinite or nonnumeric.
- Return type:
References
Rockafellar and Uryasev (2002), Conditional value-at-risk for general loss distributions, https://doi.org/10.1016/S0378-4266(02)00271-6.