duplicated entries in indices error in optimize.portfolio in PortfolioAnalytics package
<p>When I try to run the <code>optimize.portfolio</code> function using <code>ROI</code> I get the error.</p>

<pre><code>Error in ROI::V_bound(li = seq.int(1L, N), lb = as.numeric(lb), ui = seq.int(1L,  : duplicated entries in indices.
</code></pre>

<p>And when I use <code>DEoptim</code> I get. </p>

<pre><code>Error in sample.int(length(x), size, replace, prob) : 
  invalid first argument
</code></pre>

<p>When the stock data is collected using <code>getSymbols</code> there's a warning about the length of the returns objects. The <a href="https://support.rstudio.com/hc/en-us/community/posts/200640258-Using-RStudio-with-quantmod-the-getSymbols-function-fails" rel="nofollow">research I did</a> suggests this isn't the problem though. </p>

<p>The code I'm using is below. Any help would be appreciated. </p>

<pre><code>library(quantmod)
library(PortfolioAnalytics)
library(DEoptim)
library(ROI)
require(ROI.plugin.glpk)
require(ROI.plugin.quadprog)

symbols &lt;- c("MSFT", "MMM", "AMZN")

e &lt;- new.env() 
getSymbols(symbols, src="yahoo", env=e)
stocks &lt;- do.call(merge, eapply(e, Cl)[symbols])

ret &lt;- diff(log(df))
ret &lt;- ret[2:(nrow(df)),]

portfolio &lt;- portfolio.spec(ret)
portfolio

portfolio &lt;- add.constraint(portfolio = portfolio, type = "weight_sum", min_sum=0.99,max_sum=1.01)
portfolio &lt;- add.constraint(portfolio = portfolio, type = "long_only")
portfolio &lt;- add.objective(portfolio=portfolio, type="risk", name="StdDev")

optimise &lt;- optimize.portfolio(R = ret, portfolio = portfolio, optimize_method = "ROI")
</code></pre>