R Programming Language Certification Risk Assessment & Management 2 — Questions and Answers
Question 1: Which R package provides the `VaR()` function for computing Value at Risk directly from a return series?
- PerformanceAnalytics (Correct answer)
- quantmod
- xts
- TTR
Correct answer: PerformanceAnalytics
PerformanceAnalytics includes `VaR()` and `ES()` for portfolio risk metrics on time-series objects.
Question 2: In Monte Carlo simulation for risk assessment in R, which function generates samples from a multivariate normal distribution?
- MASS::mvrnorm() (Correct answer)
- stats::rnorm()
- base::sample()
- stats::runif()
Correct answer: MASS::mvrnorm()
`MASS::mvrnorm()` generates random samples from a multivariate normal distribution with a specified mean vector and covariance matrix.
Question 3: What does a Q-Q plot (created with `qqnorm()` in R) help assess in risk modeling?
- Whether residuals follow a normal distribution (Correct answer)
- Autocorrelation in time series
- Heteroscedasticity of errors
- Multicollinearity among predictors
Correct answer: Whether residuals follow a normal distribution
A Q-Q plot compares the distribution of data against theoretical quantiles of a normal distribution to assess normality.
Question 4: Which R function fits a GARCH model commonly used to model volatility clustering in financial risk?
- rugarch::ugarchfit() (Correct answer)
- stats::arima()
- forecast::auto.arima()
- tseries::garch()
Correct answer: rugarch::ugarchfit()
The `rugarch` package's `ugarchfit()` provides a comprehensive framework for fitting univariate GARCH-family models.
Question 5: In sensitivity analysis, what does the `sensitivity::soboljansen()` function compute?
- Sobol sensitivity indices for variance-based global sensitivity (Correct answer)
- Pearson correlation coefficients
- Bootstrap confidence intervals
- Partial F-test statistics
Correct answer: Sobol sensitivity indices for variance-based global sensitivity
Sobol indices partition the variance of a model output to individual inputs, measuring each input's contribution to total output uncertainty.
Question 6: What is the primary purpose of using `set.seed()` before a risk simulation in R?
- To ensure reproducibility of random number generation (Correct answer)
- To speed up computation
- To initialize parallel processing
- To reset the memory allocation
Correct answer: To ensure reproducibility of random number generation
Setting a seed fixes the state of R's random number generator so that the same sequence of random numbers is produced each run.
Question 7: Which R construct is best suited for running 10,000 bootstrap iterations efficiently in a risk model?
- replicate(10000, expr) (Correct answer)
- for loop with append()
- repeat loop
- while loop with counter
Correct answer: replicate(10000, expr)
`replicate()` is a vectorized wrapper around `sapply()` designed specifically for repeated evaluation of an expression.
Which R package provides the `VaR()` function for computing Value at Risk directly from a return series?