Example #1 – stock portfolio optimization

Sometimes we refer to single-period portfolio optimization as Markowitz portfolio optimization. Our input datasets include the expected returns, the standard deviations, and the correlation matrix between financial assets, and our output will be an efficient frontier formed by those assets. In the rest of the chapter, we will use historical returns to represent expected returns and use the historical correlation in place of expected correlation.

In the following examples, we use an R package called fPortfolio. We use the following code to install the package:

install.packages("fPortfolio") 

To load various embedded datasets, we use the data() function (see the following example code):

library(fPortfolio) ...

Get Hands-On Data Science with Anaconda now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.