width: numeric vector or list. And similar to zoo’s rollapply function I will be specifying function and window. Googling around soon brought me to ‘rollapply’, which when I tested it seems to be a very versatile function. I have no solution other than to look for something different that may achieve your goals (not sure what they are) and is sensible. Alternatively, width can be a list regarded as offsets compared to the current time, see below for details. To the best of my knowledge the R base package does not have a function to calculate moving averages. Meaning I'd like to share it with the world so hopefully if someone is looking for the same answers in the future, they can find it more easily than I did. If it's simple statistics you're interested in, you could check out some of the functions in the zoo package. I know that you can use xts::rollapply function inside of data.table, however, xts::rollapply is still slow. $\begingroup$ I think the reason that you have a problem is that this rollapply idea doesn't make sense. In the second part in a series on Tidy Time Series Analysis, we’ll again use tidyquant to investigate CRAN downloads this time focusing on Rolling Functions. > 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. In the second part in a series on Tidy Time Series Analysis, we’ll again use tidyquant to investigate CRAN downloads this time focusing on Rolling Functions.If you haven’t checked out the previous post on period apply functions, you may want to review it to get up to speed.Both zoo and TTR have a number of “roll” and “run” functions, respectively, that are integrated with tidyquant. Googling around soon brought me to 'rollapply', which when I tested it seems to be a very versatile function. However, I wanted to code my own … Both zoo and TTR have a number of “roll” and “run” functions, respectively, that are integrated with tidyquant. $\endgroup$ – Michael R. Chernick Aug 15 '12 at 20:38 For some cryptic reason I needed a function that calculates function values on sliding windows of a vector. data: the data to be used (representing a series of observations). The function I am working on should assig exponentially decreasing weights to the K most recent returns and then order the returns in an ascending order. I have found examples using rollapply to calculate rolling window linear regressions, but I have the added complication that I would like to apply these linear regressions to groups within the data set. If you haven’t checked out the previous post on period apply functions, you may want to review it to get up to speed. .before and .after are how left/right alignment are specified and a combination of both … The key differences here are in how “alignment”, completeness, and steps are assigned. In the simplest case this is an integer specifying the window width (in numbers of observations) which is aligned to the original sample according to the align argument. For some cryptic reason I needed a function that calculates function values on sliding windows of a vector. Hi everyone, I'm making this post because I have spent the last 2-3 hours trying to find or figure out how the heck to do this, and I finally figured it out! rollify uses purrr under the hood, so I can't imagine it's going to be super performant. It has rollapply(), which takes an analogous approach to rollify but uses apply instead (so maybe not a big performance increase), and rollmean(), which is a performance-optimised rolling mean. My basic VAR looks like this: VAR(dat.bv.1, p = 2, type = "const", season = NULL, exog = NULL) While dat.bv.1 is a time series object containing my endogeneous variables. I get the feeling that if a data.table::rollapply function was written utilizing data.table's radix sorting, it could be much faster than anything that is available right now. I want to use rollapply() to get the rolling window coefficients of my vector autoregression VAR() with two variables. Didier Ruedin’s blog has an elegant solution using the f ilter() function, but for this piece we will look at the rollapply() function in the zoo package. Anyway let’s see an example. However, I wanted to code my own …

2020 could not find function "rollapply"