Package 'atRisk'

Title: At-Risk
Description: The at-Risk (aR) approach is based on a two-step parametric estimation procedure that allows to forecast the full conditional distribution of an economic variable at a given horizon, as a function of a set of factors. These density forecasts are then be used to produce coherent forecasts for any downside risk measure, e.g., value-at-risk, expected shortfall, downside entropy. Initially introduced by Adrian et al. (2019) <doi:10.1257/aer.20161923> to reveal the vulnerability of economic growth to financial conditions, the aR approach is currently extensively used by international financial institutions to provide Value-at-Risk (VaR) type forecasts for GDP growth (Growth-at-Risk) or inflation (Inflation-at-Risk). This package provides methods for estimating these models. Datasets for the US and the Eurozone are available to allow testing of the Adrian et al. (2019) model. This package constitutes a useful toolbox (data and functions) for private practitioners, scholars as well as policymakers.
Authors: Quentin Lajaunie [aut, cre], Guillaume Flament [aut, ctb], Christophe Hurlin [aut], Souzan Kazemi [rev]
Maintainer: Quentin Lajaunie <[email protected]>
License: GPL-3
Version: 0.1.0
Built: 2024-10-25 06:33:57 UTC
Source: CRAN

Help Index


Historical data for the eurozone (GDP and Financial Conditions) from 2008:Q4 to 2022:Q3

Description

data_euro contains: - Quarterly annualized GDP, from 2008:Q4 to 2022:Q3 - Financial Condition Index of the euro Area, from 2008:Q4 to 2022:Q3 - Composite Indicator of Systemic Stress, from 2008:Q4 to 2022:Q3 Sources : https://sdw.ecb.europa.eu/browseExplanation.do?node=9689686 https://webstat.banque-france.fr/ws_wsen/browseSelection.do?node=DATASETS_FCI https://fred.stlouisfed.org/series/CLVMEURSCAB1GQEA19

Usage

data("data_euro")

Format

A data frame with 57 observations on the following 4 variables.

DATE

Vector of dates.

GDP

Vector of annualized PIB.

FCI

Historical values of the Financial Condition Index (FCI).

CISS

Historical values of the Composite Indicator of Systemic Stress (CISS).


Historical parameters (skew-t) for the US from 1973:Q1 to 2022:Q3

Description

Data corresponding to historical parameters estimated over the period 1973:Q1 to 2022:Q3, based on the data_US file in the matrisk package, with the skew-t distribution, and calculated with the f_param_histo function. data_param_histo_US has been calculated using c(0.05,0.25,0.75,0.95) for the qt_trgt parameter, PIB_us_forward_1 as the dependent variable, NFCI_us_lag_1 as the explanatory variable, "skew-t" for the type_function parameter and c(0, 1, -0.5, 1.3) for the starting_values.

Usage

data("data_param_histo")

Format

A matrix with 187 rows and 5 columns (first column for the periods and the 4 following columns for the for parameters of the skew-t distribution).


Historical data for the US (GDP and Financial Conditions) from 1973:Q1 to 2022:Q3

Description

data_euro contains: - Quarterly annualized GDP, from 1973:Q1 to 2022:Q3 - National Financial Condition Index of the US, from 1973:Q1 to 2022:Q3 Sources : https://www.chicagofed.org/research/data/nfci/current-data https://fred.stlouisfed.org/series/A191RL1Q225SBEA

Usage

data("data_US")

Format

A data frame with 200 observations on the following 4 variables.

DATE

Vector of dates.

GDP

Vector of annualized PIB.

NFCI

Historical values of the National Financial Condition Index (NFCI).


Estimation of quantiles

Description

Predicted values based on each quantile regression (Koenker and Basset, 1978), at time=t_trgt, for each quantile in qt_trgt.

Usage

f_compile_quantile(qt_trgt, v_dep, v_expl, t_trgt)

Arguments

qt_trgt

Numeric vector, dim k, of k quantiles for different qt-estimations

v_dep

Numeric vector of the dependent variable

v_expl

Numeric vector of the (k) explanatory variable(s)

t_trgt

Numeric time target (optional)

Value

Numeric matrix with the predicted values based on each quantile regression, at time fixed in input

References

Koenker, Roger, and Gilbert Bassett Jr. "Regression quantiles." Econometrica: journal of the Econometric Society (1978): 33-50.

Examples

# Import data
data("data_euro")

# Data process
PIB_euro_forward_4 = data_euro["GDP"][c(5:length(data_euro["GDP"][,1])),]
FCI_euro_lag_4 = data_euro["FCI"][c(1:(length(data_euro["GDP"][,1]) - 4)),]
CISS_euro_lag_4 = data_euro["CISS"][c(1:(length(data_euro["GDP"][,1]) - 4)),]

quantile_target <- as.vector(c(0.10,0.25,0.75,0.90))
results_quantile_reg <- f_compile_quantile(qt_trgt=quantile_target,
v_dep=PIB_euro_forward_4,
v_expl=cbind(FCI_euro_lag_4, CISS_euro_lag_4),
t_trgt = 30)

Distribution

Description

This function is used to estimate the parameters of the distribution (mean and standard deviation for Gaussian, xi, omega, alpha, and nu for skew-t) based on the quantile regression results (Koenker and Basset, 1978). See Adrian et al. (2019) and Adrian et al. (2022) for more details on the estimation steps.

Usage

f_distrib(type_function, compile_qt, starting_values)

Arguments

type_function

String argument : "gaussian" for normal distribution or "skew-t" for t-student distribution

compile_qt

Numeric matrix containing different quantiles and associated values

starting_values

Numeric vector with initial values for optimization

Value

a data.frame with the parameters of the distribution

References

Adrian, Tobias, Nina Boyarchenko, and Domenico Giannone. "Vulnerable growth." American Economic Review 109.4 (2019): 1263-89.

Adrian, Tobias, et al. "The term structure of growth-at-risk. " American Economic Journal: Macroeconomics 14.3 (2022): 283-323.

Koenker, Roger, and Gilbert Bassett Jr. "Regression quantiles." Econometrica: journal of the Econometric Society (1978): 33-50.

Examples

# Import data
data("data_euro")

# Data process
PIB_euro_forward_4 = data_euro["GDP"][c(5:length(data_euro["GDP"][,1])),]
FCI_euro_lag_4 = data_euro["FCI"][c(1:(length(data_euro["GDP"][,1]) - 4)),]
CISS_euro_lag_4 = data_euro["CISS"][c(1:(length(data_euro["GDP"][,1]) - 4)),]

# for a gaussian
quantile_target <- as.vector(c(0.25,0.75))
results_quantile_reg <- f_compile_quantile(qt_trgt=quantile_target,
v_dep=PIB_euro_forward_4,
v_expl=cbind(FCI_euro_lag_4, CISS_euro_lag_4),
t_trgt = 30)

results_g <- f_distrib(type_function="gaussian",
compile_qt=results_quantile_reg,
starting_values=c(0, 1))

# for a skew-t
quantile_target <- as.vector(c(0.10,0.25,0.75,0.90))
results_quantile_reg <- f_compile_quantile(qt_trgt=quantile_target,
v_dep=PIB_euro_forward_4,
v_expl=cbind(FCI_euro_lag_4, CISS_euro_lag_4),
t_trgt = 30)

results_s <- f_distrib(type_function="skew-t",
compile_qt=results_quantile_reg,
starting_values=c(0, 1, -0.5, 1.3))

Expected Shortfall

Description

The function allows to calculate Expected-shortfall for a given distribution. It takes as parameters alpha (risk level), a distribution and the parameters associated with this distribution. For example, for a normal distribution, the user must enter the mean and the standard deviation. Currently, the function can calculate the Expected-shortfall for the normal distribution and for the skew-t distribution (Azzalini and Capitianio, 2003)

Usage

f_ES(alpha, type_function, params, accuracy = 0.005)

Arguments

alpha

Numeric argument for Expected-Shortfall, between 0 and 1

type_function

String argument : "gaussian" for normal distribution or "skew-t" for t-student distribution

params

Numeric vector containing parameters of the distribution

accuracy

Scalar value which regulates the accuracy of the ES (default value 1e-05)

Value

Numeric value for the expected-shortfall given the distribution and the alpha risk.

References

Azzalini, Adelchi, and Antonella Capitanio. "Distributions generated by perturbation of symmetry with emphasis on a multivariate skew t‐distribution." Journal of the Royal Statistical Society: Series B (Statistical Methodology) 65.2 (2003): 367-389.

Azzalini, Adelchi, and Maintainer Adelchi Azzalini. "Package ‘sn’." The skew-normal and skew-t distributions (2015): 1-3.

Examples

f_ES(0.95, "gaussian", params=c(0,1))
f_ES(0.95, "gaussian", params=c(0,1), accuracy=1e-05)
f_ES(0.9999, "gaussian", params=c(0,1), accuracy=1e-04)

Historical parameters and Risk Measures

Description

This function allows to calculate historical historical parameters and the VaR and ES for each historical period.

Usage

f_histo_RM(qt_trgt, v_dep, v_expl, type_function, starting_values, alpha)

Arguments

qt_trgt

Numeric vector, dim k, of k quantiles for different qt-estimations (k>=4)

v_dep

Numeric vector of the dependent variable

v_expl

Numeric vector of the (k) explanatory variable(s)

type_function

String argument : "gaussian" for normal distribution or "skew-t" for t-student distribution

starting_values

Numeric vector with initial values for optimization

alpha

Numeric argument for Expected-Shortfall, between 0 and 1

Value

A list with historical estimated coefficients, VaR(alpha) and ES(alpha)

Examples

# Import data
data("data_euro")

# Data process
PIB_euro_forward_4 = data_euro["GDP"][c(5:length(data_euro["GDP"][,1])),]
FCI_euro_lag_4 = data_euro["FCI"][c(1:(length(data_euro["GDP"][,1]) - 4)),]
CISS_euro_lag_4 = data_euro["CISS"][c(1:(length(data_euro["GDP"][,1]) - 4)),]

# for a skew-t
results_s <- f_histo_RM(qt_trgt= as.vector(c(0.10,0.25,0.75,0.90)),
v_dep=PIB_euro_forward_4,
v_expl=cbind(FCI_euro_lag_4, CISS_euro_lag_4),
type_function="skew-t",
starting_values=c(0, 1, -0.5, 1.3),
alpha=0.95)

Historical parameters

Description

This function allows to calculate historical parameters of distributions.

Usage

f_param_histo(qt_trgt, v_dep, v_expl, type_function, starting_values)

Arguments

qt_trgt

Numeric vector, dim k, of k quantiles for different qt-estimations (k>=4)

v_dep

Numeric vector of the dependent variable

v_expl

Numeric vector of the (k) explanatory variable(s)

type_function

String argument : "gaussian" for normal distribution or "skew-t" for t-student distribution

starting_values

Numeric vector with initial values for optimization

Value

A matrix with the historical parameters of the distribution

Examples

# Import data
data("data_US")

# Data process data_US
PIB_us_forward_1 = data_US["GDP"][c(2:length(data_US["GDP"][,1])),]
NFCI_us_lag_1 = data_US["NFCI"][c(1:(length(data_US["GDP"][,1]) - 1)),]

# Historical parameters for a skew-t distribution
results_s <- f_param_histo(qt_trgt= as.vector(c(0.10,0.25,0.75,0.90)),
v_dep=PIB_us_forward_1,
v_expl=NFCI_us_lag_1,
type_function="skew-t",
starting_values=c(0, 1, -0.5, 1.3))

Plot of historical distributions in 2D

Description

This function allows to create a plot in 2D of historical distributions.

Usage

f_plot_distrib_2D(
  m_param_histo,
  type_function,
  database,
  x_lab,
  y_lab,
  x_min,
  x_max
)

Arguments

m_param_histo

Numeric matrix containing the parameters of the f_param_histo function

type_function

String argument specifying the distribution type ("gaussian" or "skew-t")

database

Dataframe containing the data, with dates in the first column and dependent variable in the second column

x_lab

String optional argument for the x axis title (default value = x)

y_lab

String optionalargument for the y axis title (default value = y)

x_min

Numeric optional argument (default value = -15)

x_max

Numeric optional argument (default value = 10)

Value

A plot of historical distributions with the median, four quantiles (5th, 25th, 75th, 95th) and the realized dependent variable.

Examples

# Import data
data(data_US)

data(data_param_histo)

results_plot_2D <- f_plot_distrib_2D(m_param_histo=data_param_histo,
type_function="skew-t",
database=data_US,
x_lab="US GDP variation",
y_lab="Year")

Plot of historical distributions in 3D

Description

This function allows to create a plot in 3D of historical distributions.

Usage

f_plot_distrib_3D(
  m_param_histo,
  type_function,
  database,
  n_samples,
  x_min,
  x_max,
  x_lab,
  y_lab
)

Arguments

m_param_histo

Numeric matrix containing the parameters of the f_param_histo function

type_function

String argument specifying the distribution type ("gaussian" or "skew-t")

database

Dataframe containing the data, with dates in the first column and dependent variable in the second column

n_samples

Number optional of samples for the plot (default value = 1000)

x_min

Numeric optional argument (default value = -15)

x_max

Numeric optional argument (default value = 10)

x_lab

String optional argument for the x axis title (default value = x)

y_lab

String optional argument for the y axis title (default value = y)

Value

A plot in 3D of historical distributions

Examples

# Import data
data(data_US)

data(data_param_histo)

results_plot_3D <- f_plot_distrib_3D(m_param_histo=data_param_histo,
type_function="skew-t",
database=data_US,
x_lab="US GDP variation",
y_lab="Year")

Value-at-Risk

Description

The function allows to calculate Value-at-Risk for a given distribution. It takes as parameters alpha (risk level), a distribution and the parameters associated with this distribution. For example, for a normal distribution, the user must enter the mean and the standard deviation. Currently, the function can calculate the Value-at-Risk for the normal distribution and for the skew-t distribution (Azzalini and Capitianio, 2003)

Usage

f_VaR(alpha, type_function, params)

Arguments

alpha

Numeric argument for Expected-Shortfall, between 0 and 1

type_function

String argument : "gaussian" for normal distribution or "skew-t" for t-student distribution

params

Numeric vector containing parameters of the distribution

Value

Numeric value for the Value-at-Risk given the distribution and the alpha risk

References

Azzalini, Adelchi, and Antonella Capitanio. "Distributions generated by perturbation of symmetry with emphasis on a multivariate skew t‐distribution." Journal of the Royal Statistical Society: Series B (Statistical Methodology) 65.2 (2003): 367-389.

Azzalini, Adelchi, and Maintainer Adelchi Azzalini. "Package ‘sn’." The skew-normal and skew-t distributions (2015): 1-3.

Examples

f_VaR(0.95, "gaussian", params=c(0,1))