Questions tagged [rollapply]

rollapply is a function in the zoo package used to perform rolling operations on an object.

rollapply is a function in the zoo package used to apply operations sequentially over elements of an object. Examples are returning a rolling mean for a vector or performing a regression on each of several partially-overlapping subsets, or rolling subsets, of a data set.

256 questions
1
vote
0 answers

stddev pct contrib / rollapply / performanceanalytics / R / subscript out of bounds

I am trying to construct rolling risk contributions by each security using the PerformanceAnalytics package. Once I can get past this error I would like to plot the results over time. I keep receiving the error that the subscript is out of bounds…
John
  • 11
  • 1
1
vote
1 answer

dplyr rolling change multiple columns based on multiple columns

I am trying to bring multiple things together using dplyr: Given I have a time series of multiple returns, I want to calculate the average correlation (I simplified my real task to give the easiest possible example) of all returns with all of the…
Diffform
  • 88
  • 7
1
vote
1 answer

How to calculate the running mean starting from the 4th column of "datamean" (given the width=4) and have first three columns as "NA"?

How to calculate the running mean starting from the 4th column of "datamean" (since the width=4) and have first and last three columns as "NA" or empty? require(zoo) data <- zoo(seq(1:10)) datamean <- rollapply(data, width=4, by=1,…
Rupesh
  • 41
  • 8
1
vote
1 answer

Beta estimation over panel data by group

I found some previous questions on this topic especially this R: Grouped rolling window linear regression with rollapply and ddply and R: Rolling / moving avg by group , however, both questions did not provide an exact solution for the problem that…
ruki ami
  • 73
  • 6
1
vote
1 answer

Wavelet correlation using rolling window

I have 3 time series which I can apply the wavelet transform to using a rolling window. The rolling window takes a single time series of length 200 and applies the waveslim::modwt function to it over the first 30 samples. This outputs 5 lists of…
TheGoat
  • 2,587
  • 3
  • 25
  • 58
1
vote
1 answer

Using rollapply to output to lists of lists

I would like to use rollapply or rollapplyr to apply the modwt function to my time series data. I'm familiar with how rollapply/r works but I need some help setting up the output so that I can correctly store my results when using rollapply. The…
TheGoat
  • 2,587
  • 3
  • 25
  • 58
1
vote
1 answer

Using lapply and the lm function together in R

I have a df as follows: t r 1 0 100.00000 2 1 135.86780 3 2 149.97868 4 3 133.77316 5 4 97.08129 6 5 62.15988 7 6 50.19177 and so on... I want to apply a rolling regression using lm(r~t). However, I want to estimate one…
user7375046
1
vote
2 answers

How to increase efficiency of double rolling window operation?

Does anyone have an idea or suggestion on how to increase the efficiency of the following example of code eating up all my ram using a "kind-of" double rolling window? First, I go through a simple example defining the problem, with a full MWE…
Jonas
  • 308
  • 1
  • 11
1
vote
1 answer

Compute exponential moving average using roll apply function in R

I am aware of the normal way of computing exponential moving average using inbuilt function EMA(). Want to compute the EMA using rollapply function.
1
vote
4 answers

Consecutive Sum of a Vector

This is a question following a previous one. In that question, it is suggested to use rollapply to calculate sum of the 1st, 2nd, 3rd entry of a vector; then 2nd, 3rd, 4th; and so on. My question is how calculate sum of the 1st, 2nd and 3rd; then…
LaTeXFan
  • 1,136
  • 4
  • 14
  • 36
1
vote
1 answer

How to feed in the arguments of a function used in rollapplyr FUN

Let's say I have the following data: input <- data.frame(id=rep(c('A', 'B'), c(10, 10)),year=rep(1:10, 2), y=c(rnorm(10), rnorm(10)),x1 = c(rnorm(10),rnorm(10))) I want to use rollapplyr to do a rolling regression. First I define…
1
vote
1 answer

Why rollapply is much slower with fill=NA and function return multiple values?

If a function return 2 or more values, and using fill = NA, rollapply become much slower. Is there any ways to avoid it? f1= function(v)c(mean(v)+ median(v)) #return vector of length 1 f2= function(v)c(mean(v), median(v)) #return vector of…
user3226167
  • 3,131
  • 2
  • 30
  • 34
1
vote
1 answer

Backwards in time rollapply

I have a time series dataset with 2 columns : x is "hourly" continuous temperature data and y is periodically sampled response data (periodic samples taken at 5am , 2pm, 8pm every day) over a couple weeks. I would like to do 2 lag approaches to…
Kyle B.
  • 13
  • 4
1
vote
0 answers

Moving average with dynamic window

I'm trying to add a new column to my data table that contains the average of some of the following rows. How many rows to be selected for the average however depends on the time stamp of the rows. Here is some test…
1
vote
2 answers

Calculate cumulative product over 1 year time windows in R

I have problem requiring me to calculate the rolling product of a series of 1 period returns. The length of the rolling window is variable. The purpose is to obtain the rolling product of the 1 period returns that covers as closely as possible a 12…
Abdd
  • 13
  • 3