align-methods | R Documentation |
Aligns a "timeSeries"
object to equidistant time stamps. There
are also functions for the common cases of changing daily to weekly
and daily to monthly.
## S4 method for signature 'timeSeries'
align(x, by = "1d", offset = "0s",
method = c("before", "after", "interp", "fillNA",
"fmm", "periodic", "natural", "monoH.FC"),
include.weekends = FALSE, ...)
alignDailySeries(x, method = c("before", "after", "interp", "fillNA",
"fmm", "periodic", "natural", "monoH.FC"),
include.weekends = FALSE, units = NULL, zone = "",
FinCenter = "", ...)
daily2monthly(x, init = FALSE)
daily2weekly(x, startOn = "Tue", init = FALSE)
x |
an object of class |
by |
a character string denoting the period. |
offset |
a character string denoting the offset. |
method |
the method to be used for the alignment. A character string, one of
|
include.weekends |
a logical value. Should weekend dates be included or removed from the series? |
units |
an optional character string, which allows to overwrite the current
column names of a |
zone |
the time zone or financial center where the data were recorded. |
FinCenter |
a character with the the location of the financial center named
as |
startOn |
a character string, specifying the day of week as a three letter
abbreviation. Weekly aggregated data records are then fixed to the
weekdays given by the argument |
init |
a logical value, if set to |
... |
further arguments to be passed to the interpolating function. |
TODO: complete.
alignDailySeries
aligns a daily 'timeSeries' to new positions,
Effectively, it is a frontend to the "timeSeries"
method for
align
with by = "1d"
, and offset = "0s"
.
In addition, there are two tailored functions for common cases:
daily2monthly
and daily2weekly
which aggregate
"timeSeries"
objects from daily to monthly or weekly levels,
respectively.
In the case of the function daily2weekly
one can explicitly set
the starting day of the week, the default value is Tuesday,
startOn = "Tue"
.
a "timeSeries"
object,
for alignDailySeries
, a weekly aligned daily "timeSeries"
object
from a daily time series with missing holidays.
aggregate
,
apply
## Use Microsofts' OHLCV Price Series -
head(MSFT)
end(MSFT)
## Use MSFT and Compute Sample Size -
dim(MSFT)
## Align the Series -
MSFT.AL <- align(MSFT)
## Show the Size of the Aligned Series -
dim(MSFT.AL)
## alignDailySeries
## Cut out April Data from 2001 -
Close <- MSFT[, "Close"]
tsApril01 <- window(Close, start="2001-04-01", end="2001-04-30")
tsApril01
## Align Daily Series with NA -
tsRet <- returns(tsApril01, trim = TRUE)
GoodFriday(2001)
EasterMonday(2001)
alignDailySeries(tsRet, method = "fillNA", include.weekends = FALSE)
alignDailySeries(tsRet, method = "fillNA", include.weekends = TRUE)
## Align Daily Series by Interpolated Values -
alignDailySeries(tsRet, method = "interp", include.weekend = FALSE)
alignDailySeries(tsRet, method = "interp", include.weekend = TRUE)
## Load Microsoft Data Set -
x <- MSFT
## Aggregate daily records to end of month records -
X <- daily2monthly(x)
X
isMonthly(X)
## Aggregate daily records to end of week records -
X <- daily2weekly(x, startOn="Fri")
X
dayOfWeek(time(X))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.