title: Rolling maximum value (rolling width) rollapply is not working
body: <pre><code> x&lt;- xts(c(1, 1.1, 1.2, 1.3, 1.4, -.9, 1.2), Sys.Date()-7:1)
  </code></pre>
  
  <p>in <code>x</code> i want a column which comes up with below mentioned result.</p>
  
  <pre><code>x
             [,1]           max high
  2013-07-07  1.0              1.0
  2013-07-08  1.1              1.1 
  2013-07-09  1.2              1.2
  2013-07-10  1.3              1.3
  2013-07-11  1.4              1.4
  2013-07-12  0.9              1.4
  2013-07-13  1.2              1.4
  </code></pre>
  
  <p>if i use <code>rollapply function</code> i have to keep width fixed but i want maximum value till date for each date. <code>rollapply</code> is not working.
  i would like to use something like rollapply(x, [1:i], max) where i will represent no. of row.
  I've got the answer that to get max.high i should use cummax and its working very well. As i've been barred from putting new questions in this forum, i'm adding my question with this one. I don't know if it the right way, but i don't have other ways to do it.</p>
  
  <blockquote>
    <p>x&lt;- xts(c(100,98,105,100,99,98,96,95,94,93,99,100,106), Sys.Date()-13:1)
    colnames(x)&lt;- "value"
    x$max&lt;- cummax(x$value)
    x$trade&lt;- ifelse(x$max*0.95>=x$value,1,0)
    x
              value max trade trade1
    2013-07-05   100 100     0      0
    2013-07-06    98 100     0      0
    2013-07-07   105 105     0      0
    2013-07-08   100 105     0      0
    2013-07-09    99 105     1      1
    2013-07-10    98 105     1      0
    2013-07-11    96 105     1      0
    2013-07-12    95 105     1      0
    2013-07-13    94 105     1      1
    2013-07-14    93 105     1      0
    2013-07-15    99 105     1     -1
    2013-07-16   100 105     0      0
    2013-07-17   106 106     0     -1</p>
  </blockquote>
  
  <p>Till the column trade, my code works but i need another column trade1 which is based on the logic that trade1 column will be 1 if value is atleast less than 5% from column max, and then it will again give me 1 when value column  is atleast than 10% from column max, and when the value is up by 5% or more from the value 94 (as the value column was 94 when trade1 column was 1), the trade1 column should give me -1 and again when column value is up by 10% or more from the value 99 (as again the value column was 99 when trade1 column was 1)</p>
  
  <p>If any one require more clarity i'll again try to do that. 
  regards
  Anup </p>