我花了好几个小时试图了解成功使用PortfolioAnalytics包中的optimize.portfolio()函数需要什么,但尽管尝试了各种优化方法(例如"DEoptim"、"ROI"),我还是收到了多个错误。
安装PortfolioAnalytics后,我尝试在指定投资组合约束后运行optimize.portfolio(),但收到以下错误:
错误:paste0("package:",plugin)%in%search()||requireNamespace(plugin,……不是TRUE
尝试下载"插件",但我收到:
Warning in install.packages : package ‘plugin’ is not available (for R version 3.3.1)
我喜欢的优化方法是"ROI",我已经安装了"ROI"包,但我仍然收到需要"插件"的错误
我试着通过手动安装"DEoptim"来解决这个问题,但我仍然无法成功运行optimize.portfolio():
pspec <- portfolio.spec(assets=names(fxreturns))
pspec <- add.constraint(pspec,type = "diversification", div_target = 0.5)
pspec <- add.constraint(pspec,type = "return",return_target=0.05)
pspec <- add.constraint(pspec,type = "leverage")
optimize.portfolio(fxreturns,portfolio = pspec,optimize_method = "DEoptim")
尽管下载了多个软件包(为什么当我第一次安装"PortfolioAnalytics"时,R不会自动安装所需的软件包?),但当我运行"DEoptim"时,我收到了以下错误:
序列错误。默认值(from=round(最小,四舍五入),to=round
为了参考,这里是我加载的所有包:
library(quantmod)
library(tseries)
library(PerformanceAnalytics)
library(PortfolioAnalytics)
library(xts)
library(timeSeries)
library(TTR)
require(Rblpapi)
require(reshape2)
require(xlsx)
require(Hmisc)
require(ROI)
require(data.table)
require(DEoptim)
我遇到了同样的问题,转到PortfolioAnalytics cran页面并安装了他们所有的建议:
library(foreach)
library(DEoptim)
library(iterators)
library(fGarch)
library(Rglpk)
library(quadprog)
library(ROI)
library(ROI.plugin.glpk)
library(ROI.plugin.quadprog)
library(ROI.plugin.symphony)
library(pso)
library(GenSA)
library(corpcor)
library(testthat)
library(nloptr)
library(MASS)
library(robustbase)
不确定是哪一个成功了,但我怀疑是ROI插件包。
对我帮助的包:
library(ROI.plugin.quadprog)