timeSeries (version 4032.109)

monthly: Special monthly series

Description

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

Usage

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

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

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

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.

See Also

isMonthly, isRegular

Examples

Run this code
## 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