I am working with xts or data.frame objects and require a simple means to roll up data that is of 1 minute intervals into 15 minute, hourly, etc...
I realize that there are the to.period
methods but my issue is that my columns are non OHLC columns so they are getting dropped when calling to.period.
My data has three columns: POSIXct, SomeVar, AnotherVar.
I need the ability to convert up this data and while doing so either sum up my data columns or take then max. Very similar to how to.period
works, but with columns that are named differently. Also, my column data is sometimes factor rather than numeric so it would be ideal if this could handle the conversion as well (when calculating).
Use period.apply
(or apply.daily
, apply.weekly
, etc.) with your own custom function. Something like:
library(quantmod)
getSymbols("SPY")
myFun <- function(x) c(Low=min(Lo(x)),Vol=sum(Vo(x)))
out <- period.apply(SPY, endpoints(SPY,"years"), myFun)
# Low Vol
# 2007-12-31 136.75 39313707500
# 2008-12-31 74.34 75960174800
# 2009-12-31 67.10 62061939800
# 2010-12-31 101.13 52842325500
# 2011-10-10 107.43 42314587300
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With