| Title: | Macroeconomic-at-Risk | 
| Version: | 0.1.0 | 
| Description: | The Macroeconomics-at-Risk (MaR) approach is based on a two-step semi-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 MaR 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. | 
| Depends: | R (≥ 2.10) | 
| License: | GPL-3 | 
| Encoding: | UTF-8 | 
| RoxygenNote: | 7.2.3 | 
| Imports: | stats, quantreg, sn, dfoptim, plot3D | 
| NeedsCompilation: | no | 
| Packaged: | 2023-04-28 21:12:07 UTC; quentin.lajaunie_ver | 
| Author: | Quentin Lajaunie [aut, cre], Guillaume Flament [aut], Christophe Hurlin [aut] | 
| Maintainer: | Quentin Lajaunie <quentin_lajaunie@hotmail.fr> | 
| Repository: | CRAN | 
| Date/Publication: | 2023-05-02 08:30:05 UTC | 
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). 
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). 
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, dist, params, accuracy = 1e-05)
Arguments
| alpha | Numeric argument for Expected-Shortfall, between 0 and 1 | 
| dist | String for the type of distribution (gaussian or skew-t) | 
| 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.95, "gaussian", params=c(0,1), accuracy=1e-04)
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, dist, params)
Arguments
| alpha | Numeric argument for Expected-Shortfall, between 0 and 1 | 
| dist | String for the type of distribution (gaussian or skew-t) | 
| 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))
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))
Historical distributions
Description
This function is based on f_distrib function (Adrian et al., 2019; Adrian et al., 2022) and is used to get historical estimation of empirical distributions and associated parameters. Results allow to realize a 3D graphical representation.
Usage
f_distrib_histo(
  qt_trgt,
  v_dep,
  v_expl,
  type_function,
  starting_values,
  step,
  x_min,
  x_max
)
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) | 
| type_function | String argument : "gaussian" for normal distribution or "skew-t" for t-student distribution | 
| starting_values | Numeric vector with initial values for optimization | 
| step | Numeric argument for accuracy graphics abscissa | 
| x_min | Numeric optional argument (default value = -15) | 
| x_max | Numeric optional argument (default value = 10) | 
Value
A list with:
| distrib_histo | Numeric matrix with historical values of x, y and t | 
| param_histo | Numeric matrix containing the parameters of the distribution for each period | 
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.
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)),]
results_histo <- f_distrib_histo(qt_trgt=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),
step=5, x_min=-10, x_max=5)
library(plot3D) # load
scatter3D(results_histo$distrib_histo[,3],
results_histo$distrib_histo[,1],
results_histo$distrib_histo[,2],
pch = 10,  theta = 70, phi = 10,
main = "Distribution of GDP Growth over time - Euro Area",
xlab = "Date",
ylab ="Pib",
zlab="", cex = 0.3)