R-投资组合分析优化无效

问题描述

im目前正致力于创建最低的Variance投资组合,并决定使用 PortfolioAnalytics包的函数optimize.portfolio。 不幸的是,在提取权重时,所有权重均为NA,尽管我的退货中没有一个具有任何NA值,这(从我的观点来看)是导致最终权重为NA的唯一原因。 我的数据集包含多个资产(+5000),每个资产都有60个观测值(每月)。

   library(PortfolioAnalytics)
   library(ROI)  
   #index returns is an xts object consisting of 3800 stock Ids(columns) and 60 observations in
   # monthly interval: To exemplifiy my problem,I set all values in index_returns to 1,to make 
   # sure that no NA values exist.
   index_returns
   any(is.na(index_returns)) # --> evaluates to FALSE
  port_spec <- portfolio.spec(assets =colnames(index_returns) )
  
  # Add a full investment constraint such that the weights sum to 1
  port_spec <- add.constraint(portfolio = port_spec,type = "full_investment")
  
  # Add a long only constraint such that the weight of an asset is between 0 and 1
  port_spec <- add.constraint(portfolio = port_spec,type = "long_only")
  
  # Add an objective to min portfolio variance
  port_spec <- add.objective(portfolio = port_spec,type = "risk",name = "var")
  
  # Solve the optimization problem
  opt <- optimize.portfolio(R = index_returns,trace=TRUE,portfolio = port_spec,optimize_method = "ROI")
  extractWeights(opt) #evaluates to NA for all assets

有人知道为什么会发生这种情况吗,并且对如何处理此问题有任何建议。我知道,由于列数多于行数,此优化问题很可能会遇到可逆性问题,但是除了这个概念之外,我正在努力解决我的问题。
我非常感谢任何帮助!预先感谢

解决方法

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

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

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