fin-align: Align a 'timeSeries' object to equidistant time stamps

align-methodsR Documentation

Align a 'timeSeries' object to equidistant time stamps

Description

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.

Usage

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

Arguments

x

an object of class "timeSeries".

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 "before", use the data from the row whose position is just before the unmatched position, or "after", use the data from the row whose position is just after the unmatched position, or "linear", interpolate linearly between "before" and "after".

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 timeSeries object. By default NULL which means that the column names are selected automatically.

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 "continent/city".

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 startOn.

init

a logical value, if set to TRUE then the time series will be indexed to 1 for its first value. By default init is set to FALSE.

...

further arguments to be passed to the interpolating function.

Details

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".

Value

a "timeSeries" object,

for alignDailySeries, a weekly aligned daily "timeSeries" object from a daily time series with missing holidays.

See Also

aggregate, apply

Examples

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

timeSeries documentation built on Jan. 13, 2024, 8:16 p.m.