[R] Returning highs and lows in R

2010-10-28 Thread Jason Kwok
I'm having trouble returning a rolling n period highest value for a data set. For each day I want to calculate the highest value over the last 3 days. I am using the following packages: zoo, xts, quantmod and TTR. Thanks, Jason GLD.Close 2010-10-01128.91 2010-10-04128.46

Re: [R] Returning highs and lows in R

2010-10-28 Thread Jorge Ivan Velez
Hi Jason, Please consider the following example: require(zoo) z2 - zoo(rnorm(6)) z2 1 2 3 4 5 6 -0.53305704 -1.09374867 1.55171109 -0.05830751 -0.25987647 -0.02009973 rollapply(z2, 3, max, by = 1) 2 3

Re: [R] Returning highs and lows in R

2010-10-28 Thread Peter Ehlers
On 2010-10-28 09:27, Jason Kwok wrote: I'm having trouble returning a rolling n period highest value for a data set. For each day I want to calculate the highest value over the last 3 days. I am using the following packages: zoo, xts, quantmod and TTR. Isn't that exactly what rollmax() does?

Re: [R] Returning highs and lows in R

2010-10-28 Thread Bert Gunter
Jason: Please read AND FOLLOW the posting guide on how to ask clear questions. Here, you need to more carefully define what you mean by the last 3 days. Do you mean:(a) the last 3 values in the series (including or excluding the present one?) or the last 3 calendar days -- e.g. for 10-05, only

Re: [R] Returning highs and lows in R

2010-10-28 Thread Jason Kwok
Thanks for the help. I'm looking to calculate rolling max and means for the last 3 observations in my data including AND not including the current observation. I'm not sure how to offset the observations used. For the 3 period max, I would like to return the max value over the last 3

Re: [R] Returning highs and lows in R

2010-10-28 Thread Jason Kwok
I figured out how to offset my observations by 1 period by using the rollapply(xx,3,max,align=right), which would calculate the mean for (current observation, obs - 1 and obs -2 ). How would I further offset by 1 more period? Thanks, Jason On Thu, Oct 28, 2010 at 1:29 PM, Jason Kwok

Re: [R] Returning highs and lows in R

2010-10-28 Thread Jason Kwok
I was able to get what I wanted using the lag function to offset an addition period. lag(rollapply(xx,3,max),-2) or lag(rollapply(xx,3,max,align=right),-1) Thanks. Jason On Thu, Oct 28, 2010 at 1:49 PM, Jason Kwok jayk...@gmail.com wrote: I figured out how to offset my observations by 1

Re: [R] Returning highs and lows in R

2010-10-28 Thread Gabor Grothendieck
On Thu, Oct 28, 2010 at 2:02 PM, Jason Kwok jayk...@gmail.com wrote: I was able to get what I wanted using the lag function to offset an addition period. lag(rollapply(xx,3,max),-2) or lag(rollapply(xx,3,max,align=right),-1) Another possibility is to apply the function over the last 4 points

Re: [R] Returning highs and lows in R

2010-10-28 Thread Gabor Grothendieck
On Thu, Oct 28, 2010 at 7:59 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Thu, Oct 28, 2010 at 2:02 PM, Jason Kwok jayk...@gmail.com wrote: I was able to get what I wanted using the lag function to offset an addition period. lag(rollapply(xx,3,max),-2) or