我正在尝试使用以下代码优化 edhec 数据,但仅将 NA 作为优化权重
library(openxlsx)
library(PortfolioAnalytics)
library(PerformanceAnalytics)
library(plyr)
library(dplyr)
library(reshape2)
library(ROI)
library(ggplot2)
library(plotly)
library(car)
library(quantmod)
library(quadprog)
library(ROI.plugin.symphony)
require(ROI.plugin.glpk)
require(ROI.plugin.quadprog)
library(ROI.plugin.lpsolve)
library(Rglpk)
library(DEoptim)
library(fGarch)
library(pso)
library(GenSA)
library(nloptr)
data(edhec)
returns <- edhec[, 1:4]
colnames(returns) <- c("CA", "CTAG", "DS", "EM")
funds <- colnames(returns)
portf_maxret <- portfolio.spec(assets=funds)
portf_maxret <- add.constraint(portfolio=portf_maxret, type="return", return_target=.0075)
portf_maxret<-add.objective(portfolio=portf_maxret, type="risk", name="StdDev")
opt_maxret <- optimize.portfolio(R=returns, portfolio=portf_maxret,optimize_method="ROI", trace=TRUE)
opt_maxret 的输出是
***********************************
PortfolioAnalytics Optimization
***********************************
Call:
optimize.portfolio(R = returns, portfolio = portf_maxret, optimize_method = "ROI",
trace = TRUE)
Optimal Weights:
CA CTAG DS EM
NA NA NA NA
Objective Measure:
StdDev
NA
任何数据都会发生同样的情况,并且只有在我尝试设置时才会发生type="risk"
,optimize.portfolio
即尝试根据与之相关的风险来优化投资组合。