Type: Package
Title: Joint Quantile and Expected Shortfall Regression
Version: 0.6.2
Date: 2023-05-12
Description: Simultaneous modeling of the quantile and the expected shortfall of a response variable given a set of covariates, see Dimitriadis and Bayer (2019) <doi:10.1214/19-EJS1560>.
License: GPL-3
Encoding: UTF-8
Imports: quantreg, Rcpp, stats, Formula
LinkingTo: Rcpp, RcppArmadillo
RoxygenNote: 7.2.3
NeedsCompilation: yes
Packaged: 2023-05-13 08:05:33 UTC; sebastian
Author: Sebastian Bayer [aut, cre], Timo Dimitriadis [aut]
Maintainer: Sebastian Bayer <sebastian.bayer@uni-konstanz.de>
Repository: CRAN
Date/Publication: 2023-05-13 08:30:02 UTC

Specification Function

Description

G1

Usage

G1_fun(z, type)

Arguments

z

Data

type

Choice of the G1 function:

  • 1: G1(z) = z

  • 2: G1(z) = 0


Specification Function

Description

G1_prime

Usage

G1_prime_fun(z, type)

Arguments

z

Data

type

Choice of the G1_prime function:

  • 1: G1_prime(z) = 1

  • 2: G1_prime(z) = 0


Specification Function

Description

G1_prime_prime

Usage

G1_prime_prime_fun(z, type)

Arguments

z

Data

type

Choice of the G1_prime_prime function:

  • 1: G1_prime(z) = 0

  • 2: G1_prime(z) = 0


Specification Function

Description

G2_curly

Usage

G2_curly_fun(z, type)

Arguments

z

Data

type

Choice of the G2_curly function:

  • 1: -log(-z), z < 0

  • 2: -sqrt(-z), z < 0

  • 3: -1/z, z < 0

  • 4: log(1 + exp(z))

  • 5: exp(z)


Specification Function

Description

G2

Usage

G2_fun(z, type)

Arguments

z

Data

type

Choice of the G2 function:

  • 1: -1/z, z < 0

  • 2: 0.5/sqrt(-z), z < 0

  • 3: 1/z^2, z < 0

  • 4: 1 / (1 + exp(-z))

  • 5: exp(z)


Specification Function

Description

G2_prime

Usage

G2_prime_fun(z, type)

Arguments

z

Data

type

Choice of the G2_prime function:

  • 1: 1/z^2, z < 0

  • 2: 0.25 / (-z)^(3/2), z < 0

  • 3: -2/z^3, z < 0

  • 4: exp(z) / (1 + exp(z))^2

  • 5: exp(z)


Specification Function

Description

G2_prime_prime

Usage

G2_prime_prime(z, type)

Arguments

z

Data

type

Choice of the G2_prime_prime function:

  • 1: -2/z^3, z < 0

  • 2: 0.375 / (-z)^(5/2), z < 0

  • 3: 6/z^4, z < 0

  • 4: -(exp(z) * (exp(z) - 1)) / (exp(z) + 1)^3

  • 5: exp(z)


Vectorized call to the G1 / G2 functions

Description

Vectorized call to the G1 / G2 functions

Usage

G_vec(z, g, type)

Arguments

z

Vector

g

String, either G1, G1_prime, G2_curly, G2 or G2_curly

type

Numeric, for G1: 1-2; G2: 1-5 (see G1_fun, G1_prime_fun, G2_curly_fun, G2_fun, G2_prime_fun)


Cumulative Density Function at Quantile

Description

Returns the cumulative density function evaluated at quantile predictions. For a correctly specified model this should yield a value close to the quantile level.

Usage

cdf_at_quantile(y, x, q)

Arguments

y

Vector of dependent data

x

Matrix of covariates including the intercept

q

Vector of quantile predictions


Conditional Mean and Sigma

Description

Estimate the conditional mean and sigma of the dependent data conditional on covariates x

Usage

conditional_mean_sigma(y, x)

Arguments

y

Vector of dependent data

x

Matrix of covariates including the intercept


Conditional truncated variance

Description

Estimate the variance of y given x and given y <= 0. If approach is:

  1. ind - Variance of all y where y <= 0.

  2. scl_N or scl_sp - Assumes a location-scale model: y = x'b + (x'g)e. First, it estimates b and g using PMLE. Then, it computes the conditional truncated variance by integrating the truncated density of y.

Usage

conditional_truncated_variance(y, x, approach)

Arguments

y

Vector of dependent data

x

Matrix of covariates including the intercept

approach

ind, scl_N or scl_sp


Density Quantile Function

Description

Estimate the density quantile function

Usage

density_quantile_function(y, x, u, alpha, sparsity, bandwidth_estimator)

Arguments

y

Vector of dependent data

x

Matrix of covariates

u

Quantile residuals

alpha

Probability level

sparsity

iid or ind

bandwidth_estimator

Bofinger, Chamberlain or Hall-Sheather

References

For the iid and nid method, see Koenker (1994), and Hendricks and Koenker (1992). For the bandwidth types, see Bofinger (1975), Chamberlain (1994), and Hall and Sheather(1988).


Joint Loss Function

Description

Computes the joint (VaR, ES) loss

Usage

esr_loss(r, q, e, alpha, g1 = 2L, g2 = 1L, return_mean = TRUE)

Arguments

r

Vector of returns

q

Vector of quantiles

e

Vector of expected shortfalls

alpha

Probability level

g1

1, 2, see G1_fun

g2

1, 2, 3, 4, 5, see G2_curly_fun, G2_fun

return_mean

If TRUE returns the average tick loss, else the individual values

References

Fissler and Ziegel (2016)


Joint (VaR, ES) loss for a linear predictor

Description

Returns the loss for the parameter vector b

Usage

esr_rho_lp(b, y, xq, xe, alpha, g1 = 2L, g2 = 1L)

Arguments

b

Parameter vector

y

Vector of dependent data

xq

Matrix of covariates for the quantile part

xe

Matrix of covariates for the expected shortfall part

alpha

Probability level

g1

1, 2 (see G1_fun)

g2

1, 2, 3, 4, 5 (see G2_curly_fun, G2_fun)


Joint Quantile and Expected Shortfall Regression

Description

Estimates a joint linear regression model for the pair (VaR, ES):

Q_\alpha(Y | Xq) = Xq'\beta_q

ES_\alpha(Y | Xe) = Xe'\beta_e

Usage

esreg(...)

## S3 method for class 'formula'
esreg(
  formula,
  data = parent.frame(),
  alpha,
  g1 = 2L,
  g2 = 1L,
  early_stopping = 10,
  ...
)

## Default S3 method:
esreg(xq, xe, y, alpha, g1 = 2L, g2 = 1L, early_stopping = 10, ...)

Arguments

...

Further arguments (does not apply here)

formula

Formula: y ~ x1 + x2 ... | x1 + x2 ... where the first part after the response variable specifies the quantile equation and the second the expected shortfall part. If only one set of regressors is provided it is used for both model specifications.

data

data.frame that holds the variables

alpha

Probability level

g1

1, 2 (see G1_fun, G1_prime_fun), defaults to 1

g2

1, 2, 3, 4, 5 (see G2_curly_fun, G2_fun, G2_prime_fun). defaults to 2

early_stopping

Stop the iterated local search if there is no improvement in early_stopping steps.

xq

Explanatory variables for the quantile regression equation

xe

Explanatory variables for the expected shortfall regression equation

y

Response vector

Value

An esreg object

References

A Joint Quantile and Expected Shortfall Regression Framework

See Also

vcov.esreg for covariance estimation

Examples

# Simulate data (DGP-(2) in the linked paper)
set.seed(0)
x <- rchisq(1000, df=1)
y <- -x + (1 + 0.5 * x) * rnorm(1000)

# True quantile and expected shortfall regression parameters (for alpha=0.025)
alpha=0.025
true_pars <- c(-1.959964, -1.979982, -2.337803, -2.168901)

# Estimate the model using the standard settings
fit <- esreg(y ~ x, alpha=alpha)

# Compare the different variance-covariance estimators
cov1 <- vcov(object=fit, sparsity="iid", sigma_est="ind")
cov2 <- vcov(object=fit, sparsity="nid", sigma_est="scl_N")
cov3 <- vcov(object=fit, sparsity="nid", sigma_est="scl_sp")

print("Comparison of the variance-covariance estimators")
print(cbind(Truth=true_pars,
            Estimate=coef(fit),
            SE_iid_ind=sqrt(diag(cov1)),
            SE_nid_N=sqrt(diag(cov2)),
            SE_nid_sp=sqrt(diag(cov3))))

# Compares estimates using different G2 functions
fit1 <- esreg(y ~ x, alpha=alpha, g2=1)
fit2 <- esreg(y ~ x, alpha=alpha, g2=2)
fit3 <- esreg(y ~ x, alpha=alpha, g2=3)
fit4 <- esreg(y ~ x, alpha=alpha, g2=4)
fit5 <- esreg(y ~ x, alpha=alpha, g2=5)
fits <- sapply(list(fit1, fit2, fit3, fit4, fit5), coef)
colnames(fits) <- sapply(1:5, function(i) esreg:::.G_function_names(1, i)[2])
print("Comparison of the five G2 functions")
print(rbind(Truth=true_pars, t(fits)))

# Usage of different covariates
x <- rchisq(1000, df=1)
noise <- rnorm(1000)
y <- -x + (1 + 0.5 * x) * rnorm(1000)
fit <- esreg(y ~ x | x + noise, alpha=0.025)
print("Using different covariates for VaR and ES")
print(summary(fit))


Estimating function

Description

This function matches the estfun function of the sandwich package and returns the estimating functions for the fitted model. It can for instance be used for an OPG estimator of the sigma matrix. For esreg, the dimension of the estimating functions is n x (kq + ke).

Usage

estfun.esreg(x, ...)

Arguments

x

An esreg object

...

Further arguments (does not apply here)


Lambda Matrix

Description

Estimate the lambda matrix.

Usage

lambda_matrix(object, sparsity, bandwidth_estimator, misspec)

Arguments

object

An esreg object

sparsity

The estimator to be used for the sparsity in \Lambda, see density_quantile_function

  • iid - Piecewise linear interpolation of the distribution

  • nid - Hendricks and Koenker sandwich

bandwidth_estimator

The bandwidth estimator to be used for the iid and nid sparsity estimator, see density_quantile_function

  • Bofinger

  • Chamberlain

  • Hall-Sheather

misspec

if TRUE, the estimator accounts for potential misspecification in the model


Sigma Matrix

Description

Estimate the sigma matrix.

Usage

sigma_matrix(object, sigma_est, misspec)

Arguments

object

An esreg object

sigma_est

The estimator to be used for \Sigma, see conditional_truncated_variance

  • ind - Variance over all negative residuals

  • scl_N - Scaling with the normal distribution

  • scl_sp - Scaling with the kernel density function

misspec

if TRUE, the estimator accounts for potential misspecification in the model


Covariance Estimation

Description

Estimate the variance-covariance matrix of the joint (VaR, ES) estimator

Usage

## S3 method for class 'esreg'
vcov(object, method = "asymptotic", ...)

Arguments

object

An esreg object

method

For asymptotic use vcovA, for boot use vcovB

...

All possible values which can be passed to vcovA and vcovB


Asymptotic Covariance Estimation

Description

Estimate the variance-covariance matrix of the joint (VaR, ES) estimator by the sandwich formula:

\lambda^{-1} \Sigma \lambda^{-1}

Several estimators are available for both matrices and the default options are selected to take into account possible misspecifications in the underlying data.

Usage

vcovA(
  object,
  sigma_est = "scl_sp",
  sparsity = "nid",
  misspec = TRUE,
  bandwidth_estimator = "Hall-Sheather"
)

Arguments

object

An esreg object

sigma_est

The estimator to be used for \Sigma, see conditional_truncated_variance

  • ind - Variance over all negative residuals

  • scl_N - Scaling with the normal distribution

  • scl_sp - Scaling with the kernel density function

sparsity

The estimator to be used for the sparsity in \Lambda, see density_quantile_function

  • iid - Piecewise linear interpolation of the distribution

  • nid - Hendricks and Koenker sandwich

misspec

if TRUE, the estimator accounts for potential misspecification in the model

bandwidth_estimator

The bandwidth estimator to be used for the iid and nid sparsity estimator, see density_quantile_function

  • Bofinger

  • Chamberlain

  • Hall-Sheather


Bootstrap Covariance Estimation

Description

Estimate the variance-covariance matrix of the joint (VaR, ES) estimator using the bootstrap.

Usage

vcovB(object, bootstrap_method = "iid", B = 1000)

Arguments

object

An esreg object

bootstrap_method

The bootstrap sampling scheme to be used

  • iid - The iid bootstrap of Efron (1979)

B

The number of bootstrap iterations