Re: [R] rollapply() produces NAs

2017-05-29 Thread Sepp via R-help
This is the function in plain text because it looked messy before: VaRfun <- function(x, lambda = 0.94) { #create data.frame and order returns such that the lates return is the first df <- data.frame(weight = c(1:length(x)), return = rev(x)) K <- nrow(df) constant <-

Re: [R] rollapply() produces NAs

2017-05-28 Thread Jeff Newmiller
You will get better help if you read the Posting Guide mentioned at the foot if every posting including this one carefully and pay attention. A) You need to post in plain text, as your code came through the mailing list damaged. B) You need to include sample data and make your code run from a

Re: [R] rollapply() produces NAs

2017-05-28 Thread Sepp via R-help
This is exactly what I want. However, with my function it produces a vector of NAs ... Gabor Grothendieck schrieb am 16:23 Sonntag, 28.Mai 2017: Maybe you want this.It computes VaRfun(r[c(i-500, i-1)] for each i for which the argument to r makes sense.

Re: [R] rollapply() produces NAs

2017-05-28 Thread Gabor Grothendieck
Maybe you want this.It computes VaRfun(r[c(i-500, i-1)] for each i for which the argument to r makes sense. rollapply(r, width = list(c(-500, -1)), FUN = VaRfun), On Sat, May 27, 2017 at 5:29 PM, Sepp via R-help wrote: > Hello, > I am fairly new to R and trying to

[R] rollapply() produces NAs

2017-05-27 Thread Sepp via R-help
Hello, I am fairly new to R and trying to calculate value at risk with exponentially decreasing weights.My function works for a single vector of returns but does not work with rollapply(), which is what I want to use. The function I am working on should assig exponentially decreasing weights to

Re: [R] rollapply and difftime

2016-05-26 Thread Nordlund, Dan (DSHS/RDA)
al Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Morway, > Eric > Sent: Thursday, May 26, 2016 5:00 PM > To: R mailing list > Subject: [R] rollapply and difftime > > Technically, the code below works and results in a column that I'm intereste

Re: [R] rollapply and difftime

2016-05-26 Thread Jeff Newmiller
What about just diff( dts ) or as.numeric( diff( dts ), units="days" ) ? -- Sent from my phone. Please excuse my brevity. On May 26, 2016 5:09:20 PM PDT, "MacQueen, Don" wrote: >You want the number of days between dates? >Does this do the trick? > >dts <- Sys.Date()+

Re: [R] rollapply and difftime

2016-05-26 Thread MacQueen, Don
You want the number of days between dates? Does this do the trick? dts <- Sys.Date()+ c(1,2,3,5,6,9) dts[-1] - dts[-length(dts)] Time differences in days [1] 1 1 2 1 3 -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On

[R] rollapply and difftime

2016-05-26 Thread Morway, Eric
Technically, the code below works and results in a column that I'm interested in working with for further processing. However, it is both inefficient on lengthy (>100 yr) daily time series and is, frankly, not the R way of doing things. Using the 'Daily' data.frame provided below, I'm interested

Re: [R] rollapply() by time, not entries (width)

2012-10-27 Thread R. Michael Weylandt
I might suggest you take a look at period.apply() in the xts package. Cheers, Michael On Fri, Oct 26, 2012 at 7:33 PM, Jaguar83 jagelf...@gmail.com wrote: Hi all- Thank you for reading my post. Please bear in mind that I'm very much a newbie with R! My question is this: I'm trying to use

Re: [R] rollapply() by time, not entries (width)

2012-10-27 Thread Joshua Ulrich
On Sat, Oct 27, 2012 at 6:52 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: I might suggest you take a look at period.apply() in the xts package. I don't think that will work because it sounds like J wants analysis on overlapping intervals, and period.apply works on non-overlapping

[R] rollapply() by time, not entries (width)

2012-10-26 Thread Jaguar83
Hi all- Thank you for reading my post. Please bear in mind that I'm very much a newbie with R! My question is this: I'm trying to use rollapply() on an irregular time series so I can't simply use the width parameter (I don't think). Rather than last 5 entries, I'd like to rollapply on last 6

Re: [R] rollapply - odd behaviour of NAs

2010-03-01 Thread Gabor Grothendieck
See the align= argument to rollapply. On Mon, Mar 1, 2010 at 4:37 PM, herr dittmann herrdittm...@yahoo.co.uk wrote: Dear expeRts, The rollapply(tseries) function puzzles me. When applying a function over a rolling window, I am getting NAs at odd places: dow -

Re: [R] Rollapply

2010-01-14 Thread Brecknock, Peter
. -Original Message- From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] Sent: Wednesday, January 13, 2010 4:02 PM To: Brecknock, Peter Cc: r-help@r-project.org Subject: Re: [R] Rollapply See: http://tolstoy.newcastle.edu.au/R/help/04/03/1446.html On Wed, Jan 13, 2010 at 3:45 PM

[R] Rollapply

2010-01-13 Thread Pete B
Hi I would like to understand how to extend the function (FUN) I am using in rollapply below. ## With the following simplified data, test1 yields parameters for a rolling regression data = data.frame(Xvar=c(70.67,70.54,69.87,69.51,70.69,72.66,72.65,73.36),

Re: [R] Rollapply

2010-01-13 Thread Gabor Grothendieck
See: http://tolstoy.newcastle.edu.au/R/help/04/03/1446.html On Wed, Jan 13, 2010 at 3:45 PM, Pete B peter.breckn...@bp.com wrote: Hi I would like to understand how to extend the function (FUN) I am using in rollapply below. ## With the following

[R] rollapply() to portions of a matrix

2008-07-31 Thread rcoder
Hi everyone, I have a rollapply statement that applies a function, in steps, over a data matrix as follows: #Code start testm-rollapply(mat, 100, by=100, min, na.rm=F) #Code end This moves down matrix 'mat' and calculates the minimum value over a 100 row range, every 100 rows (i.e. no

Re: [R] rollapply() to portions of a matrix

2008-07-31 Thread Gabor Grothendieck
rollapply over an index. Modify this appropriately: z - zoo(101:109, 11:19) f - function(ix) if (ix[1] 5) min(z[ix]) else max(z[ix]) rollapply(zoo(seq_along(z)), 3, by = 3, f) 2 5 8 101 104 109 On Thu, Jul 31, 2008 at 3:36 PM, rcoder [EMAIL PROTECTED] wrote: Hi everyone, I have a

Re: [R] rollapply() opertation on time series

2008-07-29 Thread rcoder
Hi Gabor, Thanks for your reply. Assuming I have a time series that is ready made (i.e. not constructed it using a zoo function) will the procedure below still retain the dates in the matrix? Thanks, rcoder quote author=Gabor Grothendieck rollapply along an index: library(zoo) z -

Re: [R] rollapply() opertation on time series

2008-07-29 Thread Gabor Grothendieck
methods(rollapply) shows which classes have rollapply methods. On Tue, Jul 29, 2008 at 5:48 PM, rcoder [EMAIL PROTECTED] wrote: Hi Gabor, Thanks for your reply. Assuming I have a time series that is ready made (i.e. not constructed it using a zoo function) will the procedure below still

[R] rollapply() opertation on ts matrix

2008-07-28 Thread rcoder
Hi everyone, Is there a way to perform a rollapply operation on a time series data matrix and preserve the time frame? Currently, when I apply rollapply in its standart form, the date column is no longer present in the o/p matrix. Thanks, rcoder -- View this message in context:

[R] rollapply() opertation on time series

2008-07-28 Thread rcoder
rcoder wrote: Hi everyone, Is there a way to perform a rollapply operation on a time series data matrix and preserve the time frame? Currently, when I apply rollapply in its standart form, the date column is no longer present in the o/p matrix. Thanks, rcoder -- View this

Re: [R] rollapply() opertation on time series

2008-07-28 Thread Gabor Grothendieck
rollapply along an index: library(zoo) z - zoo(matrix(101:110, 5), 201:205) tt - time(z) zz - zoo(seq_along(tt), tt) out - rollapply(zz, 3, function(ix) list(z[ix,])) str(out) # list of zoo objects On Mon, Jul 28, 2008 at 5:03 PM, rcoder [EMAIL PROTECTED] wrote: rcoder wrote: Hi everyone,

Re: [R] rollapply() opertation on time series

2008-07-28 Thread Gabor Grothendieck
And then lapply over out. On Mon, Jul 28, 2008 at 6:41 PM, Gabor Grothendieck [EMAIL PROTECTED] wrote: rollapply along an index: library(zoo) z - zoo(matrix(101:110, 5), 201:205) tt - time(z) zz - zoo(seq_along(tt), tt) out - rollapply(zz, 3, function(ix) list(z[ix,])) str(out) # list of

Re: [R] rollapply on zoo object

2007-11-30 Thread Gabor Grothendieck
1. rollapply is for creating zoo objects from zoo objects -- not for creating lists from zoo objects. 2. The subscripting is wrong. 3. Its possible that you need a different representation for out but that depends on what you want to do with it. At any rate try this and note that there is no zoo

[R] rollapply on zoo object

2007-11-30 Thread κΉ€μƒν™˜
Dear R users. I have zoo object size_june containing market-capital values: dim(size_june) # market-cap data of 625 firms for 20 years [1] 20 625 class(size_june) [1] zoo size_june # colnames = size.firmcode size.34020 size.4710 size.11050 size.10660 size.9540 size.8060