R language is a free statistical computing environment; hence there are multiple ways/packages to achieve a particular statistical/quantitative output. I am going to discuss here a concise list of R packages that one can use for the modeling of financial risks and/or portfolio optimization with utmost efficiency and effectiveness. The intended audience for this article is financial market analysts interested in using R, and also for quantitatively inclined folks with a background in finance, statistics, and mathematics.

Given the rise in the frequency of crises (the frequency of occurrence of financial market crises has certainly increased during the last 18 years or so; since the 1999 bubble burst), the modeling and measurement of financial market risk have gained tremendously in importance and the focus of portfolio allocation has shifted from the average side of the (mean, SD) coin to the SD side. Hence, it has become necessary to devise and employ methods and techniques that are better able to cope with the empirically observed extreme fluctuations in the financial markets. Analysts should go beyond the ordinarily encountered standard tools and techniques. It is better to have a larger set of tools (one of them is certainly R language) available than to be forced to rely on a more restricted set of methods.

Exploratory Analysis of Financial Market Data

Packages fBasics, evir and timeSeries - are used for reviewing the Stylized facts for univariate series. Use these packages for exploratory data analysis such as percentage returns, box plot of returns, autocorrelations, partial autocorrelations and to investigate basic properties of financial returns and related quantities.

Packages mts and zoo – are used for reviewing the Stylized facts for multivariate series. Use these packages to analyze the characteristics of multivariate return series, such as co-movement between multiple equity markets etc.

Modeling For suitable Return Distribution

Packages fBasics and GeneralizedHyperbolic – are used for univariate analysis for generalized hyperbolic distribution (GHD) and its special cases, namely the hyperbolic (HYP) and normal inverse Gaussian (NIG) distributions.

Packages ghyp and QRM – can handle both univariate and multivariate cases for HYP, GHD, NIG and student’s t-distributions. These can also be used to choose the risk measures such as, the standard deviation, the VaR, or the ES, and whether the portfolio should be a minimum risk, a tangency, or a target return portfolio.

Packages SkewHyperbolic and VarianceGamma - SkewHyperbolic is solely for the modelling and fitting of the skew hyperbolic Student’s t distribution. VarianceGamma can be considered as a twin package to the SkewHyperbolic package, but its focus is on the variance gamma distribution.

Packages Davies, fBasics, gld and lmomco – are used for the generalized lambda distribution (GLD) for risk modelling and data analysis.

Modeling For Extreme Value Theory

Packages evd and evdbays – are used univariate and multivariate parametric extreme value distributions. evdbayes provides functions and methods for the Bayesian analysis of extreme value models, where Markov chain Monte Carlo (MCMC) techniques are utilized.

Packages extRemes and in2extRemes – use them for distribution models such as the generalized extreme value, the Gumbel, the generalized Pareto, and the exponential distributions. The fit can be accomplished to either block maxima data or the threshold excesses.

Package fExtremes – use it for data preprocessing, EDA, the GEV distribution, the GPD, and the calculation of risk measures.

Packages Renext and RenextGUI – they deal explicitly with EVT. A GUI is contained in RenextGUI.

Modeling volatility

Packages bayesGARCH, ccgarch, fGarch, GEVStableGarch, gogarch, lgarch (log_garch), rugarch and rmgarch – are a comprehensive suite of packages for GARCH-type models for both univariate and multivariate analysis.

Modeling dependence

Package BLCOP – The first two letters in the name, BL, stand for Black–Litterman approach and the last three, COP, are for Copula. Hence, use this package for implementing the Black–Litterman approach to portfolio optimization and the framework of copula opinion pooling.

Packages copula and fCopulae – use them for broad implementation of the copula concept. Archimedean, elliptical, and extreme value copulae can be implemented.

Package gumbel – use it solely for Gumbel copula.

Modeling For Robust Portfolio Optimization

Package covRobust – use it for implementation of the covariance and location estimator introduced by Wang and Raftery.

Package fPortfolio – use it for conducting many different kinds of robust portfolio optimization task.

Packages MASS, lattice, robustbase, robust, rrcov and stats – use these packages for robust estimation for the location vector and scatter, Huber M-estimators, dispersion, minimum covariance determinant, the orthogonalized Gnanadesikan–Kettenring estimators etc..

Package cccp - The package’s name is an acronym for “cone constrained convex programs” and as such is suitable for solving convex objective functions with second-order cone constraints.

Modeling For Diversification of Portfolio

Packages cccp, DEoptim, DEoptimR, and RcppDE, FRAPO and PortfolioAnalytics – use these packages for finding a portfolio allocation which gives equal marginal contributions to the ES for a given confidence level, the diversification ratio, concentration ratio, volatility-weighted average correlation and risk-measure-related approaches to portfolio optimization etc. They can also be used in other optimizations.

Modeling for Risk Optimal Portfolios

Packages fPortfolio – use this package for CVaR portfolios (mean excess loss, mean shortfall, and tail VaR), and for producing risk surface plots. Also used for optimizing the minimum-CVaR and minimum-variance portfolios.

Packages glpkAPI, linprog, lpSolve, lpSolveAPI and Rglpk - are used for linear programming. Large-scale linear programs as well as mixed integer programs can be solved.

Package Rsymphony - provides a high-level interface to the MILP solver SYMPHONY, where the branch, cut, and price approach for solving MILP problems are implemented.

Package PerformanceAnalytics – contains functions and methods for assessing the performance of a given portfolio allocation and the associated risks.

Modeling For Tactical Asset Allocation

Package BLCOP - functions and procedures for the Black–Litterman method. The package also provides functions/methods for determining an optimal portfolio allocation for given prior/posterior distributions.

Packages dse, fArma, and forecast – use them for model implementations for univariate and multivariate time series. Package fArma can be used to implement different types of ARMA models - AR, MA, ARMA, ARIMA, and ARFIMA.

Package MSBVAR – use it to estimate classical and Bayesian (structural) VAR models and carry out inferential analysis on them.

Packages urca and vars - use the former for the analysis of integrated and co-integrated time series, whereas the latter for the implementation of multivariate time series models and inferences associated with these.





