fin-monthly: Special monthly series

monthlyR Documentation

Special monthly series


Functions and methods dealing with special monthly "timeSeries" objects.


rollMonthlyWindows(x, period = "12m", by = "1m") 

rollMonthlySeries(x, period = "12m", by = "1m", FUN, ...)



a "timeSeries" object.


character strings specifying the rollling period composed by the length of the period and its unit. Examples: "3m" "6m", "12m", and "24m" represent quarterly, semi-annual, annual and bi-annual shifts, respectively. It is the responsibility of the user to determine proper start of the series.


the function for the statistic to be applied. For example, colMean in the case of aggregation.


arguments passed to the function FUN.


rollMonthlySeries computes the statistics defined by the function FUN over rolling windows, internally computed by the function rollMonthlyWindows. Note, the periods may be overlapping, may be dense, or even may have gaps.

countMonthlyRecords computes a "timeSeries" that holds the number of records for each month, see examples. The dates are set to the end of the month.

rollMonthlyWindows computes start and end dates for rolling time windows. Argument period specifies the length of the periods over which FUN is applied, while by gives the amount by which the window is shifted. Non-overlapping windows correspond to by >= period.


for countMonthlyRecords and rollMonthlySeries, a "timeSeries" object.

for rollMonthlyWindows, a list with attribute "control" keeping the start and end dates of the series. The components of the list are:


an object from class "timeDate".


an object from class "timeDate".


## Load Microsoft Daily Data Set
x <- MSFT 

## count monthly records
head(x)   # 3 obs. for Sep 2000
counts <- countMonthlyRecords(x)

## 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") 
## 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)

timeSeries documentation built on Aug. 26, 2023, 5:08 p.m.