calc_cvar | R Documentation |
R
code.Calculate the Value at Risk (VaR) or the Conditional Value at Risk
(CVaR) of an xts time series of returns, using R
code.
calc_cvar(tseries, method = "var", confi = pnorm(-2))
tseries |
An xts time series of returns with multiple columns. |
method |
A string specifying the type of risk measure
(the default is |
confi |
The confidence level for calculating the
quantile (the default is |
The function calc_cvar()
calculates the Value at Risk (VaR)
or the Conditional Value at Risk (CVaR) of an xts time
series of returns, using R
The Value at Risk (VaR) and the Conditional Value at Risk (CVaR) are measures of the tail risk of returns.
If method = "var"
then calc_cvar()
calculates the Value at
Risk (VaR) as the quantile of the returns as follows:
\alpha = \int_{-\infty}^{\mathrm{VaR}(\alpha)} \mathrm{f}(r) \, \mathrm{d}r
Where \alpha
is the confidence level for calculating the quantile,
and \mathrm{f}(r)
is the probability density (distribution) of
returns.
If method = "cvar"
then calc_cvar()
calculates the Value at
Risk (VaR) as the Expected Tail Loss (ETL) of the returns as
follows:
\mathrm{CVaR} = \frac{1}{\alpha} \int_{0}^\alpha \mathrm{VaR}(p) \, \mathrm{d}p
Where \alpha
is the confidence level for calculating the quantile.
A vector with the risk measures of the columns of the input
time series tseries
.
## Not run:
# Calculate VTI and XLF returns
returns <- na.omit(rutils::etfenv$returns[, c("VTI", "XLF")])
# Calculate VaR
all.equal(HighFreq::calc_cvar(returns),
sapply(returns, quantile, probs=pnorm(-2)), check.attributes=FALSE)
# Calculate CVaR
all.equal(HighFreq::calc_cvar(returns, method="cvar", confi=0.02),
sapply(returns, function(x) mean(x[x < quantile(x, 0.02)])),
check.attributes=FALSE)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.