var¶
Defined in fynance.metrics
- var(X, alpha=0.05, method='historical')[source]
Value-at-Risk of a price/equity curve’s per-period returns.
The loss quantile at confidence level
1 - alpha: with probabilityalpha, a period’s return falls below-VaR. Reported as a positive number (the magnitude of the loss quantile), following the usual risk-desk convention.- Parameters:
- Xarray_like
Time-series of price, performance or index (a single curve).
- alphafloat, optional
Tail probability, in
(0, 1). Default is 0.05 (95% VaR).- method{‘historical’, ‘gaussian’, ‘cornish_fisher’}, optional
Estimation method. Default is ‘historical’.
- Returns:
- float
Value-at-Risk, positive for a typical loss-bearing distribution.
See also
cvar,cdar,roll_var,tail_dependence
Notes
Let \(R\) be the per-period returns of
X(see_returns_from_prices) and \(n\) their count.method='historical': the empirical quantile, taken as thek-th smallest observed return (_tail_k,k = max(1, floor(alpha n))) — an actually realized scenario, no interpolation between two observations.method='gaussian': \(VaR = -(\mu + \sigma z_\alpha)\) with \(z_\alpha = \Phi^{-1}(\alpha)\) the standard normal quantile, \(\mu, \sigma\) the sample mean/std of \(R\).method='cornish_fisher': as'gaussian'but with \(z_\alpha\) replaced by the Cornish-Fisher expansion [1] that corrects for sample skewness \(s\) and excess kurtosis \(k\):\[z_{CF} = z + \frac{z^2 - 1}{6}s + \frac{z^3 - 3z}{24}k - \frac{2z^3 - 5z}{36}s^2\]Reduces to the Gaussian quantile when \(s = k = 0\).
References
[1]Favre, L., and Galeano, J.-A., 2002, Mean-Modified Value-at-Risk Optimization with Hedge Funds, Journal of Alternative Investments.
Examples
>>> import numpy as np >>> X = np.array([100., 99., 103., 95., 101., 98., 104., 90., 108., 97., ... 102.]) >>> round(var(X, alpha=0.2, method='historical'), 4) 0.1019 >>> round(var(X, alpha=0.2, method='gaussian'), 4) 0.0723