本文介绍了投资组合分析包中的自定义预期收益的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将自定义预期收益"纳入投资组合分析"数据包时遇到麻烦.通常,预期回报是一些专业的期望/观点,或者与基本指标分开计算. Portfolio Analytics(分析)允许创建自定义的矩函数来根据过去的收益计算矩,但是我不知道如何将已经计算的收益纳入优化问题.感谢您的帮助,这是一个小的示例数据集:

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")

现在,我想在每个时期优化投资组合pf,并考虑客户观点(该时期的预期回报),但是此时我已经没有足够的想法了.

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.

推荐答案

设置赏金后,我现在意识到问题已经得到回答.我将尽我所能总结出最好的总结.

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.

调用optimize.portfolio时,有一个可选参数momentFUN,用于定义投资组合的时刻.它的参数之一是momentargs,您可以在optimize.portfolio中传递它.

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.

首先,您需要选择一组预期收益.我假设您在views时间序列中的最后一个条目:

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"] 

您还需要自己的协方差矩阵.我将根据您的returns:

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

my.covariance.matrix = cov(returns)

最后,您需要定义momentargs,它是由mu(您的期望收益),sigma(您的协方差矩阵)以及第三和第四时刻(我们将其设置)组成的列表到零):

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)

这篇关于投资组合分析包中的自定义预期收益的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!