User Expected Earnings in Portfolio Analytics

I'm having trouble including custom expected results in Portfolio Analytics. Typically, expected profits are some professional expectations / views or are calculated separately from fundamental indicators. Portfolio analytics allows you to create custom moment functions to calculate moments from past returns, but I donโ€™t understand how to incorporate already calculated returns into the optimization problem. Any help is appreciated, and here is a small example of a dataset:

#Download package and sample returns library(PortfolioAnalytics) library(PerformanceAnalytics) data(edhec) returns <- tail(edhec[,1:4], 10) #Example expected return xts that I'm usually working with. Calculated separately. N <- 10 M <- 4 views <- as.xts(data.frame(matrix(rnorm(N*M,mean=0,sd=0.05), N, M)), order.by = index(returns)) colnames(views) <- colnames(returns) 

Allows you to create a basic portfolio with specific goals.

 pf <- portfolio.spec(assets = colnames(returns)) pf <- add.constraint(portfolio = pf, type = "full_investment") pf <- add.constraint(portfolio = pf, type = "long_only") pf <- add.objective(portfolio = pf, type = "return", name = "mean") pf <- add.objective(portfolio = pf, type = "risk", name = "StdDev") 

Now I would like to optimize the pf portfolio in each period and take into account the views (expected results for this period), but at the moment I am running out of ideas.

+8
optimization r portfolio r-portfolioanalytics
source share
1 answer

Now I realized, after I established the generosity, that the questions have already been answered here . I will summarize how much I can understand this.

When you call optimize.portfolio , there is an optional momentFUN parameter that defines the moments of your portfolio. One of his arguments is momentargs , which you can go through optimize.portfolio .

First you need to select a set of expected results. I will read the last entry in your views time series:

 my.expected.returns = views["2009-08-31"] 

You will also need your own covariance matrix. I calculated it from your returns :

 my.covariance.matrix = cov(returns) 

Finally, you need to define momentargs , which is a list consisting of mu (expected results), sigma (your covariance matrix) and the third and fourth moments (which we set to zero):

 num_assets = ncol(current.view) momentargs = list() momentargs$mu = my.expected.returns momentargs$sigma = my.covariance.matrix momentargs$m3 = matrix(0, nrow = num_assets, ncol = num_assets ^ 2) momentargs$m4 = matrix(0, nrow = num_assets, ncol = num_assets ^ 3) 

Now you are ready to optimize your portfolio:

 o = optimize.portfolio(R = returns, portfolio = pf, momentargs = momentargs) 
+2
source share

All Articles