R Programming Language Certification Risk Assessment & Management 4 — Questions and Answers
Question 1: Which R package and function performs stress testing by shocking factor exposures in a portfolio risk model?
- FactorAnalytics::stress.test() (Correct answer)
- stats::lm()
- xts::apply.monthly()
- TTR::EMA()
Correct answer: FactorAnalytics::stress.test()
`FactorAnalytics::stress.test()` applies user-defined factor shocks to estimate stressed portfolio returns and losses.
Question 2: In R, what is the purpose of `copula::fitCopula()` in multivariate risk modeling?
- To estimate the dependence structure between risk factors separately from their marginals (Correct answer)
- To fit ARIMA models to correlated series
- To compute pairwise Pearson correlations
- To test for heteroscedasticity
Correct answer: To estimate the dependence structure between risk factors separately from their marginals
Copulas separate the marginal distributions of individual risk factors from their joint dependence structure, enabling flexible multivariate modeling.
Question 3: Which R function from the `qrmtools` package draws samples from a fitted copula for simulation-based risk aggregation?
- rCopula() (Correct answer)
- fitCopula()
- pCopula()
- dCopula()
Correct answer: rCopula()
`rCopula()` generates random variates from a specified copula object, used to simulate dependent risk factor scenarios.
Question 4: What R technique addresses the look-ahead bias problem when backtesting a risk model on historical data?
- Rolling-window estimation using only past data at each evaluation point (Correct answer)
- Using the full dataset for model fitting before backtesting
- Applying k-fold cross-validation across the full time series
- Resampling returns with replacement
Correct answer: Rolling-window estimation using only past data at each evaluation point
Rolling-window estimation re-fits the model at each date using only data available up to that point, preventing future information from influencing past predictions.
Question 5: In R, the Kupiec test (`VaRTest()` in PerformanceAnalytics) evaluates VaR model accuracy by testing what?
- Whether the observed exception frequency matches the expected VaR confidence level (Correct answer)
- Whether returns are normally distributed
- Whether volatility is constant over time
- Whether the model has autocorrelated residuals
Correct answer: Whether the observed exception frequency matches the expected VaR confidence level
The Kupiec proportion-of-failures test checks if the number of VaR breaches in a backtest is statistically consistent with the chosen confidence level.
Question 6: Which R construct efficiently applies a rolling 252-day standard deviation calculation to a return series `xts_ret`?
- rollapply(xts_ret, 252, sd) (Correct answer)
- apply(xts_ret, 2, sd)
- cumsum(xts_ret^2)
- diff(xts_ret, 252)
Correct answer: rollapply(xts_ret, 252, sd)
`rollapply()` from the `zoo`/`xts` ecosystem applies any function over a sliding window of specified width.
Question 7: What is the role of `parallel::mclapply()` in large-scale Monte Carlo risk simulations in R?
- To distribute simulation iterations across multiple CPU cores simultaneously (Correct answer)
- To vectorize operations on a single core
- To cache intermediate results to disk
- To profile memory usage of the simulation
Correct answer: To distribute simulation iterations across multiple CPU cores simultaneously
`mclapply()` forks child processes to run list operations in parallel, dramatically reducing wall-clock time for CPU-bound simulations.
Which R package and function performs stress testing by shocking factor exposures in a portfolio risk model?