title: ES calculation produces unreliable result (inverse risk) for column: 1
body: <p>I keep getting this error: <code>ES calculation produces unreliable result (inverse risk) for column: 1</code> message when using <code>DEoptim</code>. Maybe I am overlooking something so I need some help figuring this out. I have searched across the web but cant seem to find the answer.</p>
  
  <p>I have a <code>xts</code> object called <code>RETS</code> containing 127 rows and 4 columns which have log returns:</p>
  
  <pre><code>library("quantmod")
  library("PerformanceAnalytics")
  library("DEoptim")
  
  e &lt;- new.env()
  getSymbols("SPY;QCOR;CLNT;SRNE", from="2007-06-30", to="2007-12-31", env=e)
  # combine the adjusted close values in one xts object
  dataset1 &lt;- do.call(merge, eapply(e, Ad))
  # calculate returns
  RETS &lt;- na.omit(CalculateReturns(dataset1, method="log"))
  # objective function
  optRR.gt3 &lt;- function(x, ret) {
    retu &lt;- ret %*% x
    obj &lt;- -CVaR(as.ts(-retu))/CVaR(as.ts(retu))
    obj &lt;- ifelse(obj&gt;0,-obj,obj)
    weight.penalty &lt;- 100*(1-sum(x))^2 
    small.weight.penalty &lt;- 100*sum(x[x&lt;0.03])
    return(obj + weight.penalty + small.weight.penalty)
  }
  # I am Trying to optimize the function: optRR.gt3, which minimizes CVaR
  ctrl &lt;- list(itermax=250, F=0.2, CR=0.8)
  set.seed(21)
  res &lt;- DEoptim(optRR.gt3, lower=rep(0,ncol(RETS)), upper=rep(1,ncol(RETS)), control=ctrl, ret=RETS)
  #ES calculation produces unreliable result (risk over 100%) for column: 1 : 3.01340769101382
  #ES calculation produces unreliable result (inverse risk) for column: 1 : -0.239785868862194
  #ES calculation produces unreliable result (inverse risk) for column: 1 : -0.11639331543788
  #ES calculation produces unreliable result (risk over 100%) for column: 1 : 1.06315102355445
  #ES calculation produces unreliable result (risk over 100%) for column: 1 : 1.05285415441624
  #ES calculation produces unreliable result (risk over 100%) for column: 1 : 2.19356415811659
  #ES calculation produces unreliable result (inverse risk) for column: 1 : -0.0384963731133424
  #Error in DEoptim(optRR.gt3, lower = rep(0, ncol(RETS)), upper = rep(1,  : 
  #  NaN value of objective function! 
  #Perhaps adjust the bounds.
  </code></pre>
  
  <p>I have run this code with other series of log returns and it works, but I sometimes run it against a series and get the error such as this one.</p>