estimate_risk_roll {portvine}R Documentation

(Un-)conditional rolling risk estimation using vine copulas

Description

As this is the main workhorse function with a lot going on under the hood it is advised to have a look at the vignettes or even better the package website as they provide a detailed hands on and theoretical documentation of what this function is doing and how it is intended to be used. For a short summarized explanation have a look at the Details section below.

Usage

estimate_risk_roll(
  data,
  weights = NULL,
  marginal_settings,
  vine_settings,
  alpha = 0.05,
  risk_measures = c("VaR", "ES_mean"),
  n_samples = 1000,
  cond_vars = NULL,
  cond_u = 0.05,
  n_mc_samples = 1000,
  trace = FALSE,
  cutoff_depth = NULL,
  prior_resid_strategy = FALSE
)

Arguments

data

Matrix, data.frame or other object coercible to a data.table storing the numeric asset returns in the named columns (at least 3). Moreover missing values must be imputed beforehand.

weights

Corresponding named non-negative weights of the assets (conditioning variables must have weight 0). Default NULL gives equal weight of 1 to each non conditional asset. Alternatively one can use a matrix with as many rows as vine windows for changing weights. The matrix must have column names corresponding to the assets and conditional assets have to have weight 0.

marginal_settings

marginal_settings S4 object containing the needed information for the ARMA-GARCH i.e. marginal models fitting. Note that the marginal_settings and vine_settings objects have to match as described further below.

vine_settings

vine_settings S4 object containing the needed information for the vine copula model fitting. Note that the marginal_settings and vine_settings objects have to match as described further below.

alpha

Numeric vector specifying the confidence levels in (0,1) at which the risk measures should be calculated.

risk_measures

Character vector with valid choices for risk measures to estimate. Currently available are the Value at Risk VaR which is implemented in est_var() and 3 estimation methods of the Expected Shortfall ES_mean, ES_median and ES_mc all implemented in est_es() .

n_samples

Positive count of samples to be used at the base of the risk measure estimation.

cond_vars

Names of the variables to sample conditionally from (currently \le 2 variables).

cond_u

Numeric vector specifying the corresponding quantiles in (0,1) of the conditional variable(s) conditioned on which the conditional risk measures should be calculated. Additionally always the conditioning values corresponding to the residual of one time unit prior are used as conditional variables (cond_u = 'prior_resid' in the risk measure output) if the flagprior_resid is set to TRUE, otherwise the conditioning values corresponding to the realized residual are used (cond_u = 'resid' in the risk measure output). The latter case corresponds to the default.

n_mc_samples

Positive count of samples for the Monte Carlo integration if the risk measure ES_mc is used. (See est_es())

trace

If set to TRUE the algorithm will print a little information while running.

cutoff_depth

Positive count that specifies the depth up to which the edges of the to be constructed D-vine copula are considered in the algorithm that determines the ordering for the D-vine fitting using partial correlations. The default NULL considers all edges and seems in most use cases reasonable. This argument is only relevant if D-vines are used.

prior_resid_strategy

Logical flag that indicates whether as the additionally used conditioning values the prior day residual (if this flag is TRUE) or the realized residuals are used. The default are the realized residuals. Note that the resulting conditional risk measures use realized data so they are only for comparisons as they suffer from information leakage.

Details

Roughly speaking the function performs the following steps for the unconditional risk measure estimation:

Additionally one can perform conditional risk measure estimation with up to two conditional log return series like market indices. Using this approach does not change the marginal models part but for the copula a D-vine with a special ordering i.e. the index or the indices are fixed as the rightmost leafs is fitted. One then simulates conditional forecasted portfolio log returns which then results in conditional risk measure estimates that can be particularly interesting in stress testing like situations. One conditions on a pre-specified quantile level (cond_u) of the conditioning assets (cond_vars) and for comparison one also conditions either on the behavior of the conditioning asset one time unit before (prior_resid_strategy = TRUE) or the realized behavior of the conditioning asset (prior_resid_strategy = FALSE).

Value

In the unconditional case an S4 object of class portvine_roll and in the conditional case its child class cond_portvine_roll. For details see portvine_roll.

Matching marginal and vine settings

First of all there must be at least 2 marginal windows. Thus train_size + refit_size slot in the marginal_settings class object must be smaller than the overall input data size. Moreover the refit_size of the marginal models must be dividable by the refit_size of the vine copula models e.g. possible combinations are 50 and 50, 50 and 25, 50 and 10. Furthermore the train_size of the vines must be smaller or equal to the train_size of the marginal models.

Parallel processing

This function uses the future framework for parallelization that allows maximum flexibility for the user while having safe speedups for example regarding random number generation. The default is of course the standard non parallel sequential evaluation. The user has to do nothing in order for this default to work. If the user wants to run the code in parallel there are many options from parallel on a single machine up to a high performance compute (HPC) cluster, all of this with just one setting switch i.e. by calling the function future::plan() with the respective argument before the function call. Common options are future::plan("multisession") which works on all major operating systems and uses all available cores to run the code in parallel local R sessions. To specify the number of workers use future::plan("multisession", workers = 2). To go back to sequential processing and to shut down the parallel sessions use future::plan("sequential"). For more information have a look at future::plan(). The two following loops are processed in parallel by default if a parallel future::plan() is set:

In addition the function allows for nested parallelization which has to be done with care. So in addition to the 2 loops above one can further run each computation for each time unit in the vine windows in parallel which might be especially interesting if the n_samples argument is large. Then the default parallelization has to be tweaked to not only parallelize the first level of parallelization which are the 2 loops above. This can be achieved e.g. via future::plan(list(future::tweak(future::multisession, workers = 4), future::tweak(future::multisession, workers = 2))). This setting would run the 2 primary loops in 4 parallel R sessions and in addition each of the 4 primary parallel sessions would itself use 2 sessions within the nested parallel loop over the time units in the vine window. This results in a need for at least 2 times 4 so 8 threads on the hardware side. More details can be found in the extensive documentation of the future framework.

Author(s)

Emanuel Sommer

See Also

portvine_roll, marginal_settings, vine_settings, est_var(), est_es()

Examples

# For better illustrated examples have a look at the vignettes
# and/or the package website.

data("sample_returns_small")
ex_marg_settings <- marginal_settings(
  train_size = 900,
  refit_size = 50
)
ex_vine_settings <- vine_settings(
  train_size = 100,
  refit_size = 50,
  family_set = c("gaussian", "gumbel"),
  vine_type = "dvine"
)
# unconditionally
risk_roll <- estimate_risk_roll(
  sample_returns_small,
  weights = NULL,
  marginal_settings = ex_marg_settings,
  vine_settings = ex_vine_settings,
  alpha = c(0.01, 0.05),
  risk_measures = c("VaR", "ES_mean"),
  n_samples = 10,
  trace = FALSE
)
# conditional on one asset
risk_roll_cond <- estimate_risk_roll(
  sample_returns_small,
  weights = NULL,
  marginal_settings = ex_marg_settings,
  vine_settings = ex_vine_settings,
  alpha = c(0.01, 0.05),
  risk_measures = c("VaR", "ES_mean"),
  n_samples = 10,
  cond_vars = "GOOG",
  cond_u = c(0.05, 0.5),
  trace = FALSE,
  prior_resid_strategy = TRUE
)

# have a superficial look
risk_roll_cond
# a slightly more detailed look
summary(risk_roll_cond)

# actually use the results by extracting important fitted quantities
fitted_vines(risk_roll_cond)
fitted_marginals(risk_roll_cond)

# and of course most importantly the risk measure estimates
risk_estimates(
  risk_roll,
  risk_measures = "ES_mean",
  alpha = 0.05, exceeded = TRUE
)
risk_estimates(
  risk_roll_cond,
  risk_measures = "ES_mean",
  alpha = 0.05, exceeded = TRUE,
  cond_u = c("prior_resid", 0.5)
)


[Package portvine version 1.0.3 Index]