Learn R Programming

timeSeries (version 4030.106)

monthly: Special monthly series

Description

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

Usage

countMonthlyRecords(x)

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

Value

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:

from

an object from class "timeDate".

to

an object from class "timeDate".

Arguments

x

a "timeSeries" object.

period,by

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

FUN

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

...

arguments passed to the function FUN.

Details

countMonthlyRecords computes a "timeSeries" that holds the number of monthly counts of the records.

rollMonthlyWindows computes start and end dates for rolling time windows.

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

Examples

Run this code
## Load Microsoft Daily Data Set:
   x <- MSFT 
   
## Count Monthly Records -
   counts <- countMonthlyRecords(x)
   counts
   
## Quaterly Non-Overlapping Time Periods -
   windows <- rollMonthlyWindows(counts[-1, ], period = "3m", by = "3m") 
   windows
   
## Nicely Reprint Results as a data.frame -
   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