rollapply

Faster alternative to function 'rollapply'

霸气de小男生 提交于 2021-02-05 04:50:18
问题 I need to run rolling window function on a xts data which contains about 7,000 rows and 11,000 columns. I did the following: require(PerformanceAnalytics) ssd60<-rollapply(wddxts,width=60,FUN=function(x) SemiDeviation(x),by.column=TRUE) I waited till 12 hours but the computation did not finish. However, when I tried with small dataset as follows: sample<-wddxts[,1:5] ssd60<-rollapply(sample,width=60,FUN=function(x) SemiDeviation(x),by.column=TRUE) the computation was done within 60 seconds. I

Faster alternative to function 'rollapply'

房东的猫 提交于 2021-02-05 04:49:54
问题 I need to run rolling window function on a xts data which contains about 7,000 rows and 11,000 columns. I did the following: require(PerformanceAnalytics) ssd60<-rollapply(wddxts,width=60,FUN=function(x) SemiDeviation(x),by.column=TRUE) I waited till 12 hours but the computation did not finish. However, when I tried with small dataset as follows: sample<-wddxts[,1:5] ssd60<-rollapply(sample,width=60,FUN=function(x) SemiDeviation(x),by.column=TRUE) the computation was done within 60 seconds. I

R - Rolling sum of two columns in data.table

故事扮演 提交于 2021-01-25 07:31:16
问题 I have a data.table as follows - dt = data.table( date = seq(as.Date("2015-12-01"), as.Date("2015-12-10"), by="days"), v1 = c(seq(1, 9), 20), v2 = c(5, rep(NA, 9)) ) dt date v1 v2 1: 2015-12-01 1 5 2: 2015-12-02 2 NA 3: 2015-12-03 3 NA 4: 2015-12-04 4 NA 5: 2015-12-05 5 NA 6: 2015-12-06 6 NA 7: 2015-12-07 7 NA 8: 2015-12-08 8 NA 9: 2015-12-09 9 NA 10: 2015-12-10 20 NA Question 1: I want to add the current row value of v1 with the previous row value of v2 so the output looks like the following

Rolling Standard Deviation in a Matrix in R

人盡茶涼 提交于 2020-03-17 09:24:39
问题 Bellow is a stock daily returns matrix example ( ret_matriz ) IBOV PETR4 VALE5 ITUB4 BBDC4 PETR3 [1,] -0.040630825 -0.027795652 -0.052643733 -0.053488685 -0.048455772 -0.061668282 [2,] -0.030463489 -0.031010237 -0.047439725 -0.040229625 -0.030552275 -0.010409016 [3,] -0.022668170 -0.027012078 -0.022668170 -0.050372843 -0.080732363 0.005218051 [4,] -0.057468428 -0.074922051 -0.068414670 -0.044130126 -0.069032911 -0.057468428 [5,] 0.011897277 -0.004705891 0.035489885 -0.005934736 -0.006024115

Rolling Standard Deviation in a Matrix in R

别说谁变了你拦得住时间么 提交于 2020-03-17 09:24:11
问题 Bellow is a stock daily returns matrix example ( ret_matriz ) IBOV PETR4 VALE5 ITUB4 BBDC4 PETR3 [1,] -0.040630825 -0.027795652 -0.052643733 -0.053488685 -0.048455772 -0.061668282 [2,] -0.030463489 -0.031010237 -0.047439725 -0.040229625 -0.030552275 -0.010409016 [3,] -0.022668170 -0.027012078 -0.022668170 -0.050372843 -0.080732363 0.005218051 [4,] -0.057468428 -0.074922051 -0.068414670 -0.044130126 -0.069032911 -0.057468428 [5,] 0.011897277 -0.004705891 0.035489885 -0.005934736 -0.006024115

How to sum every nth (200) observation in a data frame using R [duplicate]

别来无恙 提交于 2020-01-14 06:24:10
问题 This question already has answers here : calculating mean for every n values from a vector (3 answers) Closed 2 years ago . I am new to R so any help is greatly appreciated! I have a data frame of 278800 observations for each of my 10 variables, I am trying to create an 11th variable that sums every 200 observations (or rows) of a specific variable/column (sum(1:200, 201:399, 400:599 etc.) Similar to the offset function in excel. I have tried subsetting my data to just the variable of

Clueless about this error: wrong sign in 'by' argument

余生颓废 提交于 2020-01-14 03:43:08
问题 I have the following dataset: >k1[1:10,] id web_name first_name second_name position date team1 team2 game_week points home_away team_scored team_conceded minutes goals assists 1 1 Fabianski Lukasz Fabianski Goalkeeper 17/08/13 ARS AVL 1 0 H 1 3 0 0 0 2 1 Fabianski Lukasz Fabianski Goalkeeper 24/08/13 ARS FUL 2 0 A 3 1 0 0 0 3 1 Fabianski Lukasz Fabianski Goalkeeper 01/09/13 ARS TOT 3 0 H 1 0 0 0 0 4 1 Fabianski Lukasz Fabianski Goalkeeper 14/09/13 ARS SUN 4 0 A 3 1 0 0 0 5 1 Fabianski Lukasz

Using rollapply to output to lists of lists

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-05 07:21:31
问题 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 modwt function in the waveslim package takes a time series and decomposes it into J levels, for my particular problem J = 4 which means I will have 4 sets of coefficients from my single time series stored in a list of 5. Of this list I am only

alignment and offsets in rollapply

不打扰是莪最后的温柔 提交于 2020-01-03 13:10:28
问题 I am trying to calculate some statistics for a moving window and am using rollapply in the zoo package. My question is how do I get rollapply to apply that function to the previous n observations instead of the current observation and the previous n-1 observations as align right seems to do. require(zoo) z <- data.frame(x1=11:111, x2=111:211, x3=as.Date(31:131))#generate data output<-data.frame(dates=z$x3, rollapply(z[,1:2],by.column=TRUE, 5, max, fill=NA, align='right')) I have a hunch this

Using rollapply function for VaR calculation using R

僤鯓⒐⒋嵵緔 提交于 2019-12-31 02:34:09
问题 I did the following for calculating Value at Risk (VaR) over 20 period rolling window: require(PerformanceAnalytics); require(zoo) data(edhec) class(edhec) # [1] "xts" "zoo" class(edhec$CTAGlobal) # "NULL" var1<-rollapply(edhec,width=20,FUN=function(edhec) VaR(R=edhec,p=.95,method="modified"),by.column=TRUE) It produces the desired output, and then I tried the same on another data: data(managers) class(managers) # [1] "xts" "zoo" class(managers$HAM4) # [1] "xts" "zoo" var2<-rollapply(managers