Custom expected returns in the Portfolio Analytics package

谁说我不能喝 提交于 2020-05-28 15:44:46

问题


I have trouble incorporating custom expected returns in Portfolio Analytics package. Usually expected returns are some professional expectations / views or calculated separately from fundamental indicators. Portfolio Analytics allow to create custom moments function to calculate moments from past returns, but I don't understand how to incorporate already calculated returns to optimization problem. Any help is appreciated and here is small example 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)

Lets create basic portfolio with some objectives.

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 portfolio pf at each period and take account views (expected returns for that period) but I'm running out of ideas at this point.


回答1:


I realise now, after setting the bounty, that the questions has already been answered here. I'll summarise as best as I can understand it.

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

First, you need to choose a set of expected returns. I'll assume the last entry in your views time series:

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

You'll also need your own covariance matrix. I'll compute it from your returns:

my.covariance.matrix = cov(returns)

Finally, you'll need to define momentargs, which is a list consisting of mu (your expected returns), sigma (your covariance matrix), and third and fourth moments (which we'll 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're ready to optimize your portfolio:

o = optimize.portfolio(R = returns, portfolio = pf, momentargs = momentargs)



回答2:


When you optimize with ROI and you pass your expectations as momentargs = expectations you need to add

add.objective(eff.port, type = "return", name = "mean")

As in the function code of optimize.portfolio line 382 or so, it is stated that it only takes the momentargs argument when the objective is return. Even if you already stated it as a constraint.



来源:https://stackoverflow.com/questions/43135233/custom-expected-returns-in-the-portfolio-analytics-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!