Learn R Programming

quarks (version 1.0.4)

rollcast: Rolling one-step forecasts of Value at Risk and Expected Shortfall

Description

Computes rolling one-step forecasts of Value at Risk and Expected Shortfall (also called Conditional Value at Risk) by means of plain historical simulation as well as age- and volatility-weighted historical simulation.

Usage

rollcast(
  x,
  p = 0.95,
  method = c("plain", "age", "vwhs"),
  lambda = c(0.94, 0.98),
  nout = NULL,
  nwin = NULL
)

Arguments

x

a numeric vector of asset returns

p

confidence level for VaR calculation; default is 0.95%

method

method to be used for calculation; default is 'plain'

lambda

decay factor for the calculation of weights; default is 0.94 for method = 'age' and 0.98 for method = 'vwhs'

nout

number of out-of-sample observations; default is NULL

nwin

window size for rolling one-step forecasting; default is NULL

Value

Returns a list with the following elements:

VaR

numerical vector containing out-of-sample forecasts of Value at Risk

ES

numerical vector containing out-of-sample forecasts of Expected Shortfall (Conditional Value at Risk)

xout

numerical vector containing out-of-sample returns

Examples

Run this code
# NOT RUN {
prices <- DAX30$price.close
returns <- diff(log(prices))
n <- length(returns)
nout <- 250 # number of obs. for out-of-sample forecasting
retout <- returns[(n - nout + 1):n]


### Example 1 - plain historical simulation
results1 <- rollcast(x = returns, p = 0.99, method = 'plain', nout = 250,
                     nwin = 500)
matplot(1:nout, cbind(-retout, results1$VaR, results1$ES),
  type = 'hll',
  xlab = 'number of out-of-sample obs.', ylab = 'losses, VaR and ES',
  main = 'Plain HS - 99% VaR and ES for the DAX30 return series'
)

### Example 2 - age weighted historical simulation
results2 <- rollcast(x = returns, p = 0.99, method = 'age', nout = 250,
                     nwin = 500)
matplot(1:nout, cbind(-retout, results2$VaR, results2$ES),
  type = 'hll',
  xlab = 'number of out-of-sample obs.', ylab = 'losses, VaR and ES',
  main = 'Age weighted HS - 99% VaR and ES for the DAX30 return series'
)

### Example 3 - volatility weighted historical simulation
results3 <- rollcast(x = returns, p = 0.99, method = 'vwhs', nout = 250,
                     nwin = 500)
matplot(1:nout, cbind(-retout, results3$VaR, results3$ES),
  type = 'hll',
  xlab = 'number of out-of-sample obs.', ylab = 'losses, VaR and ES',
  main = 'Vol. weighted HS - 99% VaR and ES for the DAX30 return series'
)
# }

Run the code above in your browser using DataLab