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-12-24 06:43:19 UTC |
Source: | CRAN |
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
data("data_euro")
data("data_euro")
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).
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.
data("data_param_histo")
data("data_param_histo")
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).
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
data("data_US")
data("data_US")
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).
Predicted values based on each quantile regression (Koenker and Basset, 1978), at time=t_trgt, for each quantile in qt_trgt.
f_compile_quantile(qt_trgt, v_dep, v_expl, t_trgt)
f_compile_quantile(qt_trgt, v_dep, v_expl, t_trgt)
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) |
Numeric matrix with the predicted values based on each quantile regression, at time fixed in input
Koenker, Roger, and Gilbert Bassett Jr. "Regression quantiles." Econometrica: journal of the Econometric Society (1978): 33-50.
# 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)
# 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)
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.
f_distrib(type_function, compile_qt, starting_values)
f_distrib(type_function, compile_qt, starting_values)
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 |
a data.frame with the parameters of the distribution
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.
# 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))
# 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))
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)
f_ES(alpha, type_function, params, accuracy = 0.005)
f_ES(alpha, type_function, params, accuracy = 0.005)
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) |
Numeric value for the expected-shortfall given the distribution and the alpha risk.
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.
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)
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)
This function allows to calculate historical historical parameters and the VaR and ES for each historical period.
f_histo_RM(qt_trgt, v_dep, v_expl, type_function, starting_values, alpha)
f_histo_RM(qt_trgt, v_dep, v_expl, type_function, starting_values, alpha)
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 |
A list with historical estimated coefficients, VaR(alpha) and ES(alpha)
# 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)
# 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)
This function allows to calculate historical parameters of distributions.
f_param_histo(qt_trgt, v_dep, v_expl, type_function, starting_values)
f_param_histo(qt_trgt, v_dep, v_expl, type_function, starting_values)
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 |
A matrix with the historical parameters of the distribution
# 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))
# 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))
This function allows to create a plot in 2D of historical distributions.
f_plot_distrib_2D( m_param_histo, type_function, database, x_lab, y_lab, x_min, x_max )
f_plot_distrib_2D( m_param_histo, type_function, database, x_lab, y_lab, x_min, x_max )
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) |
A plot of historical distributions with the median, four quantiles (5th, 25th, 75th, 95th) and the realized dependent variable.
# 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")
# 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")
This function allows to create a plot in 3D of historical distributions.
f_plot_distrib_3D( m_param_histo, type_function, database, n_samples, x_min, x_max, x_lab, y_lab )
f_plot_distrib_3D( m_param_histo, type_function, database, n_samples, x_min, x_max, x_lab, y_lab )
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) |
A plot in 3D of historical distributions
# 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")
# 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")
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)
f_VaR(alpha, type_function, params)
f_VaR(alpha, type_function, params)
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 |
Numeric value for the Value-at-Risk given the distribution and the alpha risk
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.
f_VaR(0.95, "gaussian", params=c(0,1))
f_VaR(0.95, "gaussian", params=c(0,1))