title: R, please Check my longest Drawdowns function
body: <p>I can't get performanceAnalytics to work with my zoo series and I've decided to write my own script.</p>
  
  <p>It's supposed to get  cummax(equity)-equity  as input if you want to calculate de longest Drawdowns. It also gives the max drawdown value on these periods.</p>
  
  <p>corrected version is below.</p>
  
  <p>Please, Could you check my script. It doesn't work as expected. Some maxDD are zero.
  I hope it can be useful to other people. I've seen many messages at forums where people looks for something like this.</p>
  
  <p>I've corrected it with Richie suggestions:</p>
  
  <pre><code>  findDD &lt;- function(DD, n=5){
    rr &lt;- rle(sign(coredata(DD)))
    lens &lt;- rr$length
    lens[!rr$value] &lt;- 0
    ll &lt;- head(order(lens, decreasing=TRUE),n)
    sumas &lt;- cumsum(c(1,rr$length)) # I need to access the original lenghts 
    maxDD &lt;- sapply(ll,FUN = function(x) max(window(DD,start=index(DD)[sumas[x]],end=index(DD)[sumas[x+1]-1])))
    data.frame(start=index(DD)[sumas[ll]],end=index(DD)[sumas[ll+1]-1], length=(index(DD)[sumas[ll+1]-1]-index(DD)[sumas[ll]])+1, maxDD)
  }
  </code></pre>
  
  <p>I've also corrected a problem that prevented me from getting an ordered answer because I was writting index(DD[]) instead of index(DD)[]</p>
  
  <p>Now it seems to work but I'm not sure.</p>
  
  <p>to Joshua:
  At the beginning my data was zoo with chron index
  Now I've transformed it to xts with posixct index, </p>
  
  <pre><code>"2010-01-11 18:00:00" 9338.37028375963
  "2010-01-11 18:15:00" 8086.45780960387
  "2010-01-11 18:30:00" 7762.75622449016
  "2010-01-11 18:45:00" 8358.3609798313
  "2010-01-11 19:00:00" 8598.69695502083
  "2010-01-11 19:15:00" 8568.56256494502
  "2010-01-11 19:30:00" 8488.4281748692
  ...
  </code></pre>
  
  <p>still doesn't work with performanceAnalytics, though I can graph it and make any calculations by my own.
  Drawdown(myData) gives a xts series with all its data values NaN.
  I've been looking at findDrawdown code and it's different to mine because it measures relative drawdowns instead of absolute drawdowns.</p>
  
  <p>Anyway, I hope my script could be useful to someone.</p>