Hi, I have daily 6 stocks prices data. start from Jan 2019 to Dec 2022. I want to split the data set to multiple training sets. if I want to do it manually I will have the following
log.return<-na.omit(Return.calculate(data, method = "log")*100) #daily log return , this is equal to : r.log <- (log(data) - log(lag(data, k = 1)) ) *100
# generate 1000 random weights
return.1=window(log.return[1:230])
return.2=window(log.return[21:251])
return.3=window(log.return[40:271])
return.4=window(log.return[61:291])
return.5=window(log.return[82:312])
return.6=window(log.return[104:334])
return.7=window(log.return[124:354])
return.8=window(log.return[146:376])
return.9=window(log.return[168:398])
return.10=window(log.return[188:419])
return.11=window(log.return[211:440])
return.12=window(log.return[231:462])
return.13=window(log.return[252:482])
return.14=window(log.return[273:504])
return.15=window(log.return[292:523])
return.16=window(log.return[314:542])
return.17=window(log.return[335:564])
return.18=window(log.return[355:586])
return.19=window(log.return[377:606])
return.20=window(log.return[399:628])
return.21=window(log.return[420:649])
return.22=window(log.return[441:671])
return.23=window(log.return[463:692])
return.24=window(log.return[483:713])
return.25=window(log.return[505:734])
return.26=window(log.return[524:756])
return.27=window(log.return[543:776])
return.28=window(log.return[566:795])
return.29=window(log.return[587:818])
return.30=window(log.return[607:838])
return.31=window(log.return[629:859])
return.32=window(log.return[650:880])
return.33=window(log.return[672:900])
return.34=window(log.return[693:923])
return.35=window(log.return[714:944])
return.36=window(log.return[735:965])
return.37=window(log.return[757:986])
I want to split the data using some rolling window function. I have been advised to use the following code
library(dplyr)
library(RccpRoll)
# 'daily_sessions' is the dataset
log.return.df%>%
mutate(
# Weekly length is the rolling mean of 7 'lengths'
daily_length = roll_mean(length, 230, fill = NA, align = "right")
however I received the following error
Error in `mutate()`:
! Problem while computing `daily_length = roll_mean(log.return.df, 230,
fill = NA, align = "right")`.
Caused by error in `roll_mean_impl()`:
! Not compatible with requested type: [type=list; target=double].
Run `rlang::last_error()` to see where the error occurred.
Any advice how to solve the problem