## data -
# Percentual Returns of Swiss Bond Index and Performance Index
LPP = 100 * as.timeSeries(data(LPP2005REC))[,c("SBI", "SPI")]
head(LPP, 20)
## Aggregate Quarterly Returns
applySeries(LPP, by = "quarterly", FUN = colSums)
## Aggregate Quarterly every last Friday in Quarter
oneDay = 24*3600
from = unique(timeFirstDayInQuarter(time(LPP))) - oneDay
from = timeLastNdayInMonth(from, nday = 5)
to = unique(timeLastDayInQuarter(time(LPP)))
to = timeLastNdayInMonth(to, nday = 5)
data.frame(from = as.character(from), to = as.character(to))
applySeries(LPP, from, to, FUN = colSums)
## Alternative use
fapply(LPP, from, to, FUN = colSums)
## Count Trading Days per Month
colCounts = function(x) rep(NROW(x), times = NCOL(x))
applySeries(LPP, FUN = colCounts, by = "monthly")
Run the code above in your browser using DataLab