1

我正在尝试使用以下代码优化 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即尝试根据与之相关的风险来优化投资组合。

4

1 回答 1

1

当您尝试在该行中为您的投资组合提供相同的名称时,可能会导致该问题:

portf_maxret<-add.objective(portfolio=portf_maxret, type="risk", name="StdDev")

尝试更改portf_maxret为其他内容并将其用作优化中的投资组合名称

于 2018-01-24T14:55:15.217 回答