Calculate Global Minimum Variance Portfolio Using R

In this and the next couple of posts, I’ll give examples of how to calculate optimized portfolios using R and the vanguard funds in my retirement account. Today, I’ll show you how to calculate the global minimum variance portfolio, which was the first major result in Markowitz’s portfolio theory. Given a collection of assets, their global minimum variance portfolio is the portfolio with the smallest portfolio volitility.

Step 0. Load libraries and define helper functions

Step 1. I choose assets from three broad classes: stocks, bonds, and commodities. For stocks, I choose funds that cover total US market, total international markets, and real estate. For bonds, I choose funds that invest in the total US bond market and inflation protected securities. For commodities, I choose funds that invest in gold and other precious metals and their mining companies and oil & gas and energy companies. First, I download the monthly adjusted closing price data of these funds between June 2000 and Oct 2014 from Yahoo.

Step 2. Calculate monthly continuously compounded returns as difference in log prices.

Step 3. Calculate the sample average returns of the underlying assets and the sample covariance matrix of the returns.

Step 4. Finally, we can calculate the global minimum variance portfolio using a helper function written by Eric Zivot and Hezky Varon from U of Washington.