## High level use of package
# Select a portfolio using 200 total observations
data(sp500.subset)
h <- sp500.subset
# Optimize using a window of length 200 (there will be 51 total iterations)
ws <- optimizePortfolio(h, 150, getCorFilter.RMT() )
# Plot the performance of the resulting optimized portfolio
pf <- plotPerformance(h, ws, 150, y.min=-0.4)
# Compare the performance with a naive equal-weighted portfolio
ef <- compare.EqualWeighted(h, 150, y.min=-0.4)
# Also compare against the S&P 500
mf <- compare.Market('^GSPC',200,150, y.min=-0.4)
# Generate weights based on the constant correlation shrinkage estimator
ws <- optimizePortfolio(h, 150, getCorFilter.Shrinkage())
pf <- plotPerformance(h, ws, 150, y.min=-0.4)
## Low level use of the package
# View the theoretical Marcenko-Pastur distribution of eigenvalues of a
# random matrix
mp.theory(Q=4.2, sigma=1.1)
# Calculate the density of eigenvalues for a matrix of portfolio returns
h <- getRandomMatrix(20, 100)
hist <- mp.density.kernel(h)
# Fit an empirical distribution to a theoretical curve
hint <- c(6,2)
o <- optim(hint, mp.fit.kernel(hist))Run the code above in your browser using DataLab