cvar¶
Defined in fynance.metrics
- cvar(X, alpha=0.05, method='historical')[source]
Conditional Value-at-Risk (Expected Shortfall) of a price/equity curve.
The expected loss beyond the VaR threshold — the mean of the returns in the
alpha-tail — a coherent risk measure (unlike VaR, which is not subadditive). Reported as a positive number, same convention asvar.- Parameters:
- Xarray_like
Time-series of price, performance or index (a single curve).
- alphafloat, optional
Tail probability, in
(0, 1). Default is 0.05.- method{‘historical’, ‘gaussian’, ‘cornish_fisher’}, optional
Estimation method. Default is ‘historical’.
- Returns:
- float
Conditional Value-at-Risk, positive for a typical loss-bearing distribution. Always \(\geq\)
varat the samealpha.
See also
var,cdar,roll_cvar,tail_dependence
Notes
Let \(R\) be the per-period returns of
X(see_returns_from_prices), \(n\) their count and \(\mu,\sigma\) their sample mean/std.method='historical': mean of thek = max(1, floor(alpha n))smallest observed returns (_tail_k) — the tail mean underlyingvar’s historical quantile.method='gaussian': closed form [2] \(CVaR = -\mu + \sigma \frac{\varphi(z_\alpha)}{\alpha}\), with \(\varphi\) the standard normal pdf and \(z_\alpha = \Phi^{-1}(\alpha)\).method='cornish_fisher': the tail mean of the Cornish-Fisher [1] -adjusted quantile function over \(p \in (0, \alpha]\),\[CVaR_{CF} = -\frac{1}{\alpha}\int_0^{\alpha} \left(\mu + \sigma \, z_{CF}(p)\right) dp\]approximated on a fixed probability grid (see
_cf_tail_constants); collapses to the same value as'gaussian'when sample skewness and excess kurtosis are both zero.
References
[1]Favre, L., and Galeano, J.-A., 2002, Mean-Modified Value-at-Risk Optimization with Hedge Funds, Journal of Alternative Investments.
[2]Rockafellar, R.T., and Uryasev, S., 2000, Optimization of Conditional Value-at-Risk, Journal of Risk, 2, 21-42.
Examples
>>> import numpy as np >>> X = np.array([100., 99., 103., 95., 101., 98., 104., 90., 108., 97., ... 102.]) >>> round(cvar(X, alpha=0.2, method='historical'), 4) 0.1182 >>> cvar(X, alpha=0.2, method='historical') >= var(X, alpha=0.2, method='historical') True