[R-SIG-Finance] half-hourly staggered data into daily

murali.menon at fortisinvestments.com murali.menon at fortisinvestments.com
Mon Nov 24 18:16:31 CET 2008


Folks,
 
For some reason, this email to the mailing list doesn't seem to have 
reached, hence resending.
 
Using the period.apply() function in the xts package, I'm able to convert 
half-hourly data points into daily aggregates. Like so:
 
library(chron)
library(xts)
dts <- dates(c("04/03/1996", "05/03/1996", "06/03/1996", "07/03/1996", 
"08/03/1996", "11/03/1996", "12/03/1996", "13/03/1996", "14/03/1996", 
"15/03/1996"), format="d/m/y")
tms <- times(seq(from = 0, to = 60 * 60 * 23 + 30 * 60, by = 30 * 60) / 
(24 * 60 * 60))
# clumsy way to obtain a vector of date-times
series <- chron(as.vector(matrix(outer(dts, tms, chron), byrow = TRUE)))
# Now create some dummy data
library(xts)
set.seed(123)
fxdata <- xts(runif(length(series)), order.by = series)
# Returns
fxret <- diff(log(fxdata))
sqrd_ret <- fxret ^ 2
 
> period.apply(sqrd_ret, endpoints(sqrd_ret, "days"), FUN = function(x) 
sqrt(sum(x)))
(03/04/96 23:30:00) (03/05/96 23:30:00) (03/06/96 23:30:00) (03/07/96 
23:30:00) (03/08/96 23:30:00) (03/11/96 23:30:00) (03/12/96 23:30:00) 
           6.342830            9.622646            8.718305           
12.006788            8.526932            7.659233            7.506814 
(03/13/96 23:30:00) (03/14/96 23:30:00) (03/15/96 23:30:00) 
          12.436300            9.879991            7.790180
 


---------------------------------------------------------------------------
This e-mail is confidential and may be privileged. If you have received it by mistake, please notify the sender by return e-mail and delete it from your system. You should not disclose, copy or use it for any purpose. The information in this e-mail is not contractual. Fortis Investments provides no guarantee as to the correctness of this information and accepts no responsibility for any action taken on the basis of it. Fortis Investments is the trade name for all entities within the Fortis Investment Management group.



More information about the R-SIG-Finance mailing list