monthly | R Documentation |
Functions and methods dealing with special monthly
"timeSeries"
objects.
rollMonthlyWindows(x, period = "12m", by = "1m")
rollMonthlySeries(x, period = "12m", by = "1m", FUN, ...)
countMonthlyRecords(x)
x |
a |
period , by |
character strings specifying the rollling period composed by the
length of the period and its unit. Examples: |
FUN |
the function for the statistic to be applied. For example,
|
... |
arguments passed to the function |
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:
from |
an object from class |
to |
an object from class |
isMonthly
,
isRegular
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.