## load Microsoft daily dataset
x <- MSFT
## count monthly records
head(x) # 3 obs. for Sep 2000
counts <- countMonthlyRecords(x)
counts
## diy computation of the counts
diy <- rollMonthlySeries(x[ , 1], period = "1m", by = "1m", FUN = NROW)
## difference is only in some attributes (e.g. column names)
all.equal(diy, counts)
## quaterly non-overlapping time periods
windows <- rollMonthlyWindows(counts[-1, ], period = "3m", by = "3m")
windows
## nicely print results as a data.frame, each row is a time window
data.frame(cbind(FROM = format(windows$from), TO = format(windows$to)))
## compute the average number of monthly trading days per quarter
rollMonthlySeries(counts[-1, ], period = "3m", by = "3m", FUN = mean)
Run the code above in your browser using DataLab