1% Generated by roxygen2: do not edit by hand 2% Please edit documentation in R/VaR.R 3\name{VaR} 4\alias{VaR} 5\alias{VaR.CornishFisher} 6\title{calculate various Value at Risk (VaR) measures} 7\usage{ 8VaR( 9 R = NULL, 10 p = 0.95, 11 ..., 12 method = c("modified", "gaussian", "historical", "kernel"), 13 clean = c("none", "boudt", "geltner", "locScaleRob"), 14 portfolio_method = c("single", "component", "marginal"), 15 weights = NULL, 16 mu = NULL, 17 sigma = NULL, 18 m3 = NULL, 19 m4 = NULL, 20 invert = TRUE, 21 SE = FALSE, 22 SE.control = NULL 23) 24} 25\arguments{ 26\item{R}{an xts, vector, matrix, data frame, timeSeries or zoo object of 27asset returns} 28 29\item{p}{confidence level for calculation, default p=.95} 30 31\item{\dots}{any other passthru parameters} 32 33\item{method}{one of "modified","gaussian","historical", "kernel", see 34Details.} 35 36\item{clean}{method for data cleaning through \code{\link{Return.clean}}. 37Current options are "none", "boudt", "geltner", or "locScaleRob".} 38 39\item{portfolio_method}{one of "single","component","marginal" defining 40whether to do univariate, component, or marginal calc, see Details.} 41 42\item{weights}{portfolio weighting vector, default NULL, see Details} 43 44\item{mu}{If univariate, mu is the mean of the series. Otherwise mu is the 45vector of means of the return series, default NULL, see Details} 46 47\item{sigma}{If univariate, sigma is the variance of the series. Otherwise 48sigma is the covariance matrix of the return series, default NULL, see 49Details} 50 51\item{m3}{If univariate, m3 is the skewness of the series. Otherwise m3 is 52the coskewness matrix (or vector with unique coskewness values) of the 53returns series, default NULL, see Details} 54 55\item{m4}{If univariate, m4 is the excess kurtosis of the series. Otherwise 56m4 is the cokurtosis matrix (or vector with unique cokurtosis values) of the 57return series, default NULL, see Details} 58 59\item{invert}{TRUE/FALSE whether to invert the VaR measure. see Details.} 60 61\item{SE}{TRUE/FALSE whether to ouput the standard errors of the estimates of the risk measures, default FALSE.} 62 63\item{SE.control}{Control parameters for the computation of standard errors. Should be done using the \code{\link{RPESE.control}} function.} 64} 65\description{ 66Calculates Value-at-Risk(VaR) for univariate, component, and marginal cases 67using a variety of analytical methods. 68} 69\note{ 70The option to \code{invert} the VaR measure should appease both 71academics and practitioners. The mathematical definition of VaR as the 72negative value of a quantile will (usually) produce a positive number. 73Practitioners will argue that VaR denotes a loss, and should be internally 74consistent with the quantile (a negative number). For tables and charts, 75different preferences may apply for clarity and compactness. As such, we 76provide the option, and set the default to TRUE to keep the return 77consistent with prior versions of PerformanceAnalytics, but make no value 78judgment on which approach is preferable. 79 80The prototype of the univariate Cornish Fisher VaR function was completed by 81Prof. Diethelm Wuertz. All corrections to the calculation and error 82handling are the fault of Brian Peterson. 83} 84\section{Background }{ 85 86 87This function provides several estimation methods for 88the Value at Risk (typically written as VaR) of a return series and the 89Component VaR of a portfolio. Take care to capitalize VaR in the commonly 90accepted manner, to avoid confusion with var (variance) and VAR (vector 91auto-regression). VaR is an industry standard for measuring downside risk. 92For a return series, VaR is defined as the high quantile (e.g. ~a 95% or 99% 93quantile) of the negative value of the returns. This quantile needs to be 94estimated. With a sufficiently large data set, you may choose to utilize 95the empirical quantile calculated using \code{\link{quantile}}. More 96efficient estimates of VaR are obtained if a (correct) assumption is made on 97the return distribution, such as the normal distribution. If your return 98series is skewed and/or has excess kurtosis, Cornish-Fisher estimates of VaR 99can be more appropriate. For the VaR of a portfolio, it is also of interest 100to decompose total portfolio VaR into the risk contributions of each of the 101portfolio components. For the above mentioned VaR estimators, such a 102decomposition is possible in a financially meaningful way. 103} 104 105\section{Univariate VaR estimation methods }{ 106 107 108The VaR at a probability level \eqn{p} (e.g. 95\%) is the \eqn{p}-quantile of 109the negative returns, or equivalently, is the negative value of the 110\eqn{c=1-p} quantile of the returns. In a set of returns for which 111sufficently long history exists, the per-period Value at Risk is simply the 112quantile of the period negative returns : 113 114 \deqn{VaR=q_{.99}}{VaR=quantile(-R,p)} 115 116where \eqn{q_{.99}} is the 99\% empirical quantile of the negative return series. 117 118This method is also sometimes called \dQuote{historical VaR}, as it is by 119definition \emph{ex post} analysis of the return distribution, and may be 120accessed with \code{method="historical"}. 121 122When you don't have a sufficiently long set of returns to use non-parametric 123or historical VaR, or wish to more closely model an ideal distribution, it is 124common to us a parmetric estimate based on the distribution. J.P. Morgan's 125RiskMetrics parametric mean-VaR was published in 1994 and this methodology 126for estimating parametric mean-VaR has become what most literature generally 127refers to as \dQuote{VaR} and what we have implemented as \code{\link{VaR}}. 128See \cite{Return to RiskMetrics: Evolution of a 129Standard}\url{https://www.msci.com/documents/10199/dbb975aa-5dc2-4441-aa2d-ae34ab5f0945}. 130 131 132Parametric mean-VaR does a better job of accounting for the tails of the 133distribution by more precisely estimating shape of the distribution tails of 134the risk quantile. The most common estimate is a normal (or Gaussian) 135distribution \eqn{R\sim N(\mu,\sigma)} for the return series. In this case, 136estimation of VaR requires the mean return \eqn{\bar{R}}, the return 137distribution and the variance of the returns \eqn{\sigma}. In the most 138common case, parametric VaR is thus calculated by 139 140\deqn{\sigma=variance(R)}{sigma=var(R)} 141 142\deqn{VaR=-\bar{R} - \sqrt{\sigma} \cdot z_{c} }{VaR= -mean(R) - sqrt(sigma)*qnorm(c)} 143 144where \eqn{z_{c}} is the \eqn{c}-quantile of the standard normal distribution. Represented in \R by \code{qnorm(c)}, 145and may be accessed with \code{method="gaussian"}. 146 147Other forms of parametric mean-VaR estimation utilize a different 148distribution for the distribution of losses to better account for the 149possible fat-tailed nature of downside risk. The now-archived package 150\code{VaR} contained methods for simulating and estimating lognormal and 151generalized Pareto distributions to overcome some of the problems with 152nonparametric or parametric mean-VaR calculations on a limited sample size or 153on potentially fat-tailed distributions. There was also a 154VaR.backtest function to apply simulation methods to create a more robust 155estimate of the potential distribution of losses. Less commonly a covariance 156matrix of multiple risk factors may be applied. This functionality should 157probably be 158 159The limitations of mean Value-at-Risk are well covered in the literature. 160The limitations of traditional mean-VaR are all related to the use of a 161symetrical distribution function. Use of simulations, resampling, or Pareto 162distributions all help in making a more accurate prediction, but they are 163still flawed for assets with significantly non-normal (skewed or kurtotic) 164distributions. Zangari (1996) and Favre and Galeano(2002) provide a modified 165VaR calculation that takes the higher moments of non-normal distributions 166(skewness, kurtosis) into account through the use of a Cornish Fisher 167expansion, and collapses to standard (traditional) mean-VaR if the return 168stream follows a standard distribution. This measure is now widely cited and 169used in the literature, and is usually referred to as \dQuote{Modified VaR} 170or \dQuote{Modified Cornish-Fisher VaR}. They arrive at their modified VaR 171calculation in the following manner: 172 173\deqn{z_{cf}=z_{c}+\frac{(z_{c}^{2}-1)S}{6}+\frac{(z_{c}^{3}-3z_{c})K}{24}-\frac{(2z_{c}^{3}-5z_{c})S^{2}}{36}}{ 174 z_cf=z_c+[(z_c^2-1)S]/6+[(z_c^3-3z_c)K]/24-[(2z_c^3-5z_c)S^2]/36} 175 176\deqn{Cornish-Fisher VaR =-\bar{R} - \sqrt(\sigma) \cdot z_{cf}}{VaR= -mean(R) - sqrt(sigma)*z_cf} 177 178where \eqn{S} is the skewness of \eqn{R} and \eqn{K} is the excess kurtosis of \eqn{R}. 179 180Cornish-Fisher VaR collapses to traditional mean-VaR when returns are 181normally distributed. As such, the \code{\link{VaR}} and \code{\link{VaR}} 182functions are wrappers for the \code{VaR} function. The Cornish-Fisher 183expansion also naturally encompasses much of the variability in returns that 184could be uncovered by more computationally intensive techniques such as 185resampling or Monte-Carlo simulation. This is the default method for the 186\code{VaR} function, and may be accessed by setting \code{method="modified"}. 187 188 189Favre and Galeano also utilize modified VaR in a modified Sharpe Ratio as the 190return/risk measure for their portfolio optimization analysis, see 191\code{\link{SharpeRatio.modified}} for more information. 192} 193 194\section{Component VaR }{ 195 196 197By setting \code{portfolio_method="component"} you may calculate the risk 198contribution of each element of the portfolio. The return from the function 199in this case will be a list with three components: the univariate portfolio 200VaR, the scalar contribution of each component to the portfolio VaR (these 201will sum to the portfolio VaR), and a percentage risk contribution (which 202will sum to 100\%). 203 204Both the numerical and percentage component contributions to VaR may contain 205both positive and negative contributions. A negative contribution to 206Component VaR indicates a portfolio risk diversifier. Increasing the 207position weight will reduce overall portoflio VaR. 208 209If a weighting vector is not passed in via \code{weights}, the function will 210assume an equal weighted (neutral) portfolio. 211 212Multiple risk decomposition approaches have been suggested in the literature. 213A naive approach is to set the risk contribution equal to the stand-alone risk. 214This approach is overly simplistic and neglects important diversification 215effects of the units being exposed differently to the underlying risk 216factors. An alternative approach is to measure the VaR contribution as the 217weight of the position in the portfolio times the partial derivative of the 218portfolio VaR with respect to the component weight. \deqn{C_i \mbox{VaR} = 219w_i \frac{ \partial \mbox{VaR} }{\partial w_i}.}{C[i]VaR = 220w[i]*(dVaR/dw[i]).} Because the portfolio VaR is linear in position size, we 221have that by Euler's theorem the portfolio VaR is the sum of these risk 222contributions. Gourieroux (2000) shows that for VaR, this mathematical 223decomposition of portfolio risk has a financial meaning. It equals the 224negative value of the asset's expected contribution to the portfolio return 225when the portfolio return equals the negative portfolio VaR: 226 227\deqn{C_i \mbox{VaR} = = -E\left[ w_i r_{i} | r_{p} = - \mbox{VaR}\right]}{C[i]VaR = -E( w[i]r[i]|rp=-VaR ) } 228 229For the decomposition of Gaussian VaR, the estimated mean and covariance 230matrix are needed. For the decomposition of modified VaR, also estimates of 231the coskewness and cokurtosis matrices are needed. If \eqn{r} denotes the 232\eqn{Nx1} return vector and \eqn{mu} is the mean vector, then the \eqn{N 233\times N^2} co-skewness matrix is \deqn{ m3 = E\left[ (r - \mu)(r - \mu)' 234\otimes (r - \mu)'\right]}{m3 = E[ (r - mu)(r - mu)' \%x\% (r - \mu)']} The 235\eqn{N \times N^3} co-kurtosis matrix is 236 237\deqn{ m_{4} = 238 E\left[ (r - \mu)(r - \mu)' \otimes (r - \mu)'\otimes (r - \mu)' 239 \right] }{E[ (r - \mu)(r - \mu)' \%x\% (r - \mu)'\%x\% (r - \mu)']} 240 241where \eqn{\otimes}{\%x\%} stands for the Kronecker product. The matrices can 242be estimated through the functions \code{skewness.MM} and \code{kurtosis.MM}. 243More efficient estimators have been proposed by Martellini and Ziemann (2007) 244and will be implemented in the future. 245 246As discussed among others in Cont, Deguest and Scandolo (2007), it is 247important that the estimation of the VaR measure is robust to single 248outliers. This is especially the case for modified VaR and its 249decomposition, since they use higher order moments. By default, the portfolio 250moments are estimated by their sample counterparts. If \code{clean="boudt"} 251then the \eqn{1-p} most extreme observations are winsorized if they are 252detected as being outliers. For more information, see Boudt, Peterson and 253Croux (2008) and \code{\link{Return.clean}}. If your data consist of returns 254for highly illiquid assets, then \code{clean="geltner"} may be more 255appropriate to reduce distortion caused by autocorrelation, see 256\code{\link{Return.Geltner}} for details. 257 258Epperlein and Smillie (2006) introduced a non-parametric kernel estimator for 259component risk contributions, which is available via \code{method="kernel"} 260and \code{portfolio_method="component"}. 261} 262 263\section{Marginal VaR }{ 264 265 266Different papers call this different things. In the Denton and Jayaraman 267paper referenced here, this calculation is called Incremental VaR. We have 268chosen the more common usage of calling this difference in VaR's in 269portfolios without the instrument and with the instrument as the 270\dQuote{difference at the Margin}, thus the name Marginal VaR. This is 271incredibly confusing, and hasn't been resolved in the literature at this 272time. 273 274Simon Keel and David Ardia (2009) attempt to reconcile some of the 275definitional issues and address some of the shortcomings of this measure in 276their working paper titled \dQuote{Generalized Marginal Risk}. Hopefully 277their improved Marginal Risk measures may be included here in the future. 278} 279 280\examples{ 281 282if(!( Sys.info()[['sysname']]=="Windows") ){ 283# if on Windows, cut and paste this example 284 285 data(edhec) 286 287 # first do normal VaR calc 288 VaR(edhec, p=.95, method="historical") 289 290 # now use Gaussian 291 VaR(edhec, p=.95, method="gaussian") 292 293 # now use modified Cornish Fisher calc to take non-normal distribution into account 294 VaR(edhec, p=.95, method="modified") 295 296 # now use p=.99 297 VaR(edhec, p=.99) 298 # or the equivalent alpha=.01 299 VaR(edhec, p=.01) 300 301 # now with outliers squished 302 VaR(edhec, clean="boudt") 303 304 # add Component VaR for the equal weighted portfolio 305 VaR(edhec, clean="boudt", portfolio_method="component") 306 307} # end Windows check 308 309} 310\references{ 311Boudt, Kris, Peterson, Brian, and Christophe Croux. 2008. 312Estimation and decomposition of downside risk for portfolios with non-normal 313returns. 2008. The Journal of Risk, vol. 11, 79-103. 314 315Cont, Rama, Deguest, Romain and Giacomo Scandolo. Robustness and sensitivity 316analysis of risk measurement procedures. Financial Engineering Report No. 3172007-06, Columbia University Center for Financial Engineering. 318 319Denton M. and Jayaraman, J.D. Incremental, Marginal, and Component VaR. 320Sunguard. 2004. 321 322Epperlein, E., Smillie, A. Cracking VaR with kernels. RISK, 2006, vol. 19, 32370-74. 324 325Gourieroux, Christian, Laurent, Jean-Paul and Olivier Scaillet. Sensitivity 326analysis of value at risk. Journal of Empirical Finance, 2000, Vol. 7, 327225-245. 328 329Keel, Simon and Ardia, David. Generalized marginal risk. Aeris CAPITAL 330discussion paper. 331 332Laurent Favre and Jose-Antonio Galeano. Mean-Modified Value-at-Risk 333Optimization with Hedge Funds. Journal of Alternative Investment, Fall 2002, 334v 5. 335 336Martellini, L. and Ziemann, V., 2010. Improved estimates of higher-order 337comoments and implications for portfolio selection. Review of Financial 338Studies, 23(4):1467-1502. 339 340Return to RiskMetrics: Evolution of a Standard 341\url{https://www.msci.com/documents/10199/dbb975aa-5dc2-4441-aa2d-ae34ab5f0945} 342 343Zangari, Peter. A VaR Methodology for Portfolios that include Options. 1996. 344RiskMetrics Monitor, First Quarter, 4-12. 345 346Rockafellar, Terry and Uryasev, Stanislav. Optimization of Conditional VaR. 347The Journal of Risk, 2000, vol. 2, 21-41. 348 349Dowd, Kevin. Measuring Market Risk, John Wiley and Sons, 2010. 350 351Jorian, Phillippe. Value at Risk, the new benchmark for managing financial risk. 3523rd Edition, McGraw Hill, 2006. 353 354Hallerback, John. "Decomposing Portfolio Value-at-Risk: A General Analysis", 3552003. The Journal of Risk vol 5/2. 356 357Yamai and Yoshiba (2002). "Comparative Analyses of Expected Shortfall and 358 Value-at-Risk: Their Estimation Error, Decomposition, and Optimization", 359 Bank of Japan. 360} 361\seealso{ 362\code{\link{SharpeRatio.modified}} \cr 363\code{\link{chart.VaRSensitivity}} \cr 364\code{\link{Return.clean}} 365} 366\author{ 367Brian G. Peterson and Kris Boudt 368} 369