在投资组合分析包中设置自定义预期收益

问题描述

我想在我的Portfolio Analytics R包中指定我自己的期望收益以用于optimize.portfolio,而不是使用认的样本均值。

我在optimize.portfolio中使用momentargs参数设置了自定义返回值,并运行了优化器,但将结果绘制成图表,在使用样本矩和自定义矩进行优化之间没有任何区别。

下面的示例代码。我究竟做错了什么?谢谢!

# Download packages and sample return series (most recent 120 months of first 6 edhec assets)
library(PortfolioAnalytics)
library(PerformanceAnalytics)
data(edhec)
returns <- tail(edhec[,1:6],120)


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


# Define custom moments for use in optimize.portfolio 
# Set return equal to exp_ret and covariance to sample covariance
# excluding third and fourth moments,package documentation says if excluded will default to sample method
exp_ret <- c(0.004,0.002,0.005,0.009,0.004)
custom_moments <- list()
custom_moments$mu <- exp_ret
custom_moments$sigma <- cov(returns)


# Run optimization to maximize Sharpe ratio,using custom moments and the ROI solver
mvo_custom <- optimize.portfolio(R=returns,portfolio=pf,optimize_method = "ROI",trace = TRUE,maxSR=TRUE,momentargs = custom_moments)

# Run optimization using sample moments as a comparison
mvo_sample <- optimize.portfolio(R=returns,maxSR=TRUE)
# Show output                          
print(mvo_custom)
print(mvo_sample)


# Chart the results. Why are the charts the same for both optimizations?
chart.EF.Weights(mvo_custom,match.col = "StdDev",main = "Custom mu ROI")
chart.EF.Weights(mvo_sample,main = "Sample mu ROI")

chart.EfficientFrontier(mvo_custom,n.portfolios = 20,xlim = c(0,0.03),ylim = c(0,0.006),RAR.text = "Sharpe Ratio",tangent.line = TRUE,rf = 0.01/12,type = "l",# ef line 
                        chart.assets = TRUE,labels.assets = TRUE,main = "Efficient Frontier: custom mu")

chart.EfficientFrontier(mvo_sample,main = "Efficient Frontier: sample mu")

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...