R / PortfolioAnalytics optimize.portfolio()

时间:2017-02-02 21:13:25

标签: r r-portfolioanalytics r-optimization

我花了几个小时试图了解成功利用PortfolioAnalytics包中的 optimize.portfolio()功能所需的内容,但我收到了多个错误,尽管尝试了各种optimize_methods(例如& #34; DEoptim"" ROI&#34)

安装PortfolioAnalytics后,我在指定组合约束后尝试运行optimize.portfolio(),但收到以下错误:

  

错误:%search()||中的paste0("包:",插件)% requireNamespace(插件,....不是TRUE

尝试下载"插件",但我收到:

Warning in install.packages : package ‘plugin’ is not available (for R version 3.3.1)

我首选的optimize_method是" 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")

尽管下载了多个软件包(为什么我在第一次安装&#34; PortfolioAnalytics&#34;?时不会自动安装所需的软件包),但是当我运行&#34; DEOPtim&#34时,我收到以下错误;:

  

seq.default中的错误(from = round(min,rounding),to = round(max,rounding),:&#39; from&#39;不能是NA,NaN或无限

供参考,以下是我加载的所有软件包:

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)

2 个答案:

答案 0 :(得分:6)

我遇到了同样的问题,转到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插件包。

答案 1 :(得分:0)

对我来说有帮助的包裹:

library(ROI.plugin.quadprog)