tis-package: Time Indices and Time Indexed Series

Description Details Author(s)

Description

Functions and S3 classes for time indices and time indexed series, a flexible kind of time series compatible with series and frequencies understood by the FAME DBMS.

Details

For a complete list of functions provided by this package, use library(help="tis").

The ti (Time Index) and tis (Time Indexed Series) classes provide date arithmetic facilities and an alternative to the somewhat inflexible ts class in the standard R stats package.

Time Indexes (ti class)

A time index has two parts: a tif (Time Index Frequency) code and a period. tif codes all lie in the open interval (1000..5000) and the period is a nonnegative number less than 1e10. The ti encodes both, as for any ti z

unclass(z) == (tif(z) * 1e10) + period(z)

Each tif has a particular base period (the time period where period(z) == 0). For example, the base period for an "anndecember" (annual December) ti is the year ending December 31, 1599. Periods before the base period cannot be represented by instances of the ti class.

If x and y are ti objects with the same tif, then

x - y == period(x) - period(y)

and

x + (period(y) - period(x)) == y

are both TRUE, so you can use ti's for various calendrical calculations.

A jul class is also provided for Julian date-time objects. The jul() constructor can create a jul from an ssDate (spreadsheet date), a POSIXct or POSIXlt object, a ti object, a decimal time (like 2007.5), a yyyymmdd number, a Date, or anything that can be coerced to a Date by as.Date. The ymd() function and its derivatives (year(), month(), day(), etc.) work on anything that jul() can handle.

Time Indexed Series (tis class)

The tis class maps very closely to the FAME (http://www.sungard.com/Fame/) database notion of what a time series is. A tis (Time Indexed Series) is vector or matrix indexed by a ti. If x is a tis, then start(x) gives the ti for the first observation, and [start(x) + k] is the ti for the k'th observation, while end(x) gives the ti for the last observation.

You can replace, say, the 5'th observation in a tis x by

x[start(x) + 4] <- 42

and of course the [ operator also works with a ti. So if you want the value of the daily series x from July 3, 1998, you can get it with

x[ti(19980703, "daily")]

provided, of course, that ymd(start(x)) <= 19980703 <= ymd(end(x)).

Numerous methods for tis objects are provided:

1
2
3
4
5
6
7
8
9

as well as tisMerge and tisPlot functions. The convert function creates series of different frequencies from a given series in ways both more powerful and more flexible than aggregate can.

Setting Default Frequencies:

Like the FAME DBMS, the ti class has seven weekly frequencies for weeks ending on Sunday, Monday, and it has 12 annual frequencies, for years ending on the last day of each of the 12 months. There are also multiple biweekly, bimonthly and semiannual frequencies.

At any time you can use the function setDefaultFrequencies to change which actual frequencies the strings "weekly", "biweekly", "bimonthly", "quarterly", "semiannual" and "annual" refer to. Note (as shown by args(setDefaultFrequencies)) that if you don't specify some other frequencies to setDefaultFrequencies, you'll get default weeks ending on Monday and default biweeks ending on the first Wednesday. I chose these because they are the weeks and biweeks used most often (for money and reserves data) in my section at the Federal Reserve Board. You might want to use something like

setHook(packageEvent("tis", "onLoad"), tis::setDefaultFrequencies(yourArgsGoHere))

in your .First() to automatically set the defaults up the way you want them whenever this package is loaded.

LAGS:

The stats::lag(x, k) function says that a series lagged by a positive k starts earlier. The opposite is true for the Lag function in this package, to maintain consistency with the common usage of 'first lag, second lag' and so on in econometrics.

tisFilter:

The stats::filter function coerces it's argument to a ts time series and returns a ts. For tis and zoo series, this is not right. Both I and the author of the zoo package have requested that stats::filter be made an S3 generic with the current version renamed as filter.default. This would allow zoo and tis to define filter.zoo and filter.tis such that filter(aZooOrTis) would do the right thing. We are hopeful that this will happen soon. Meanwhile, tisFilter should be used to filter a tis.

Author(s)

Jeff Hallman jhallman@frb.gov

Maintainer: ditto


tis documentation built on Sept. 29, 2021, 1:06 a.m.