[R-SIG-Finance] rollapply and cummin
ggrothendieck at gmail.com
Thu Aug 23 06:46:31 CEST 2007
The usual case is that the function used in rollapply returns a single
number; however, if you really want to return a vector of 5 numbers try
the latest version of rollapply which was fixed about 2 weeks ago and
is not yet on CRAN but can be downloaded from the development
repository. From within R:
# ... now run your commands ...
On 8/22/07, Voss, Kent <VOSSK at kochind.com> wrote:
> I am getting some unexpected results using rollapply and the cummin function that I am hoping someone can help me understand. I'm just trying to get a rolling cumulative minimum of a time series. Think of it as the maximum loss over a rolling window.
> Here's an example
> # Create a dummy sequence to use with a set of dates used to create a zoo object
> x <- c(0,rep(c(seq(1,5,by=1),seq(-1,-3, by=-1)),2))
> DateList <- as.Date(seq(ISOdate(1990,1,1), length.out=length(x), by="1 day"), '%Y-%m-%d')
> z <- zoo(x,DateList)
> # Doing the following gets expected results, a rolling 5 day sum. So far so good
> zl <- rollapply(z, 5, align='left',sum)
> # The following however creates an n x n matrix where n = the length of z, that I can't quite figure out
> zl <- rollapply(z, 5, align='left',cummin)
> Now I'm pretty new at this stuff, so I'm sure there's something I'm missing, but I can't make heads or tails around the results of the cummin. Any help would be greatly appreciated. Thanks in advance.
> "EMF <kochind.com>" made the following annotations.
> The information in this e-mail and any attachments is confidential and intended solely for the attention and use of the named addressee(s). It must not be disclosed to any person without proper authority. If you are not the intended recipient, or a person responsible for delivering it to the intended recipient, you are not authorized to and must not disclose, copy, distribute, or retain this message or any part of it.
> [[alternative HTML version deleted]]
> R-SIG-Finance at stat.math.ethz.ch mailing list
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
More information about the R-SIG-Finance