我有下面的脚本会产生错误。有谁知道如何解决这个问题。我正在运行最新版本的 R&RStudio,所有软件包都是最新的。
library('quantmod')
library('PortfolioAnalytics')
library('PerformanceAnalytics')
ETF_Names <- c("IVV","IJH","IWM","EZU","EEM","SCZ","ILF","EPP")
ETF_All <- lapply(ETF_Names, function(x) getSymbols(x,from="2006-01-01",auto.assign = FALSE))
names(ETF_All) <- ETF_Names
ETF_MR <- do.call(merge,lapply(ETF_All,monthlyReturn))
colnames(ETF_MR) <- ETF_Names
ETF_spec <- portfolio.spec(assets = colnames(ETF_MR))
ETF_spec <- add.constraint(portfolio=ETF_spec, type="full_investment")
ETF_spec <- add.constraint(portfolio=ETF_spec, type="box", min=0, max=1)
ETF.ef <- create.EfficientFrontier(R=ETF_MR['2015'], portfolio=ETF_spec, type="mean-StdDev")
错误消息下方:
Error in gmv_opt(R = R, constraints = constraints, moments = moments, :
No solution found: Error in UseMethod("as.constraint") :
no applicable method for 'as.constraint' applied to an object of class "c('matrix', 'list')"
以前从未出现过问题(我最近刚刚更新了 RStudio 和相关软件包)。那就是错误弹出的时候。
希望有人可以帮助