A number of preconfigured correlation matrix filters are available: getCorFilter.RMT for using random matrix theory, getCorFilter.Shrinkage returns a function for filltering the correlation matrix using a shrinkage estimator. A raw version is provided for comparison. These functions provide reasonable configurability, for example with getCorFilter.RMT, one can choose whether a histogram or a kernel density estimator is used to calculate the probability density function. With getCorFilter.Shrinkage one can select a constant correlation model or the identity as the model.
optimizePortfolio(h, window, cor.gen, ...)getCorFilter.Shrinkage(prior.fun = cov.prior.cc, ...)
getCorFilter.RMT(hint = c(4,1), ...)
getCorFilter.raw()
p.optimize(h, c.denoised)
The weights matrix can then be analyzed to calculate standard portfolio performance metrics. A simple analytics function is provided so that cumulative returns can be easily viewed, although for more sophisticated analysis other packages should be used.
In theory any compatible correlation matrix generator can be used (and has in
practice to test against proprietary risk models) and the function will
generate portfolio weights accordingly. To leverage the remainder of the
package, the getCorFilter.RMT function or getCorFilter.Shrinkage
should be called. These wrappers are somewhat superfluous but do provide
some utility by ensuring compatibility with the underlying RMT code that uses
transposed matrices (pre-zoo integration). Additionally, by way of closures
these functions are used to store hints to the optimizer and any final data
massaging, potentially cleaning up code but admittedly can be serviced via
the normal dots mechanism.
In the future, the default will be a direct handle to the underlying function once the rest of the code is converted to zoo.
The secondary function optimizePortfolio.RMT exists to optimize the
correlation matrix using RMT exclusively. This is a more direct route to
accessing the RMT functionality and might be more convenient to use. The
intention is that the base optimizePortfolio function becomes a generic
function that passes on to specific implementations, but the mechanics haven't
been worked out yet. It is also possible to extract the optimizer and pass
that in explicitly as a function.
data(sp500.subset)
h <- sp500.subset
ws <- optimizePortfolio(h, 190, getCorFilter.RMT() )
ws <- optimizePortfolio(h, 190, getCorFilter.Shrinkage() )Run the code above in your browser using DataLab