如何解决在投资组合分析包中设置自定义预期收益
我想在我的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 举报,一经查实,本站将立刻删除。