An xts
object extends the S3 class zoo
from the package of the
same name.
The first difference in this extension provides for a requirement
that the index values not only be unique and ordered, but also must be of
a time-based class. Currently acceptable classes include: ‘Date’,
‘POSIXct’, ‘timeDate’, as well as ‘yearmon’ and
‘yearqtr’ where the index values remain unique.
This last uniqueness requirement has been relaxed as of version 0.5-0.
By setting unique=FALSE, only a check that the index is
not decreasing is carried out via the isOrdered
function.
The second difference is that the object may now carry additional
attributes that may be desired in individual time-series handling.
This includes the ability to augment the objects data with
meta-data otherwise not cleanly attachable to a standard zoo object.
Examples of usage from finance may include the addition of data
for keeping track of sources, last-update times, financial
instrument descriptions or details, etc.
The idea behind xts
is to offer the user the ability to utilize
a standard zoo object, while providing an mechanism to customize
the object's meta-data, as well as create custom methods to handle
the object in a manner required by the user.
Many xts-sepcific methods have been written to better handle the
unique aspects of xts. These include, ‘"["’, merge, cbind,
rbind, c, Ops, lag, diff, coredata, head and tail. Additionally
there are xts specific methods for converting amongst R's different
time-series classes.
Subsetting via "[" methods offers the ability to specify dates by
range, if they are enclosed in quotes. The style borrows from
python by creating ranges with a double colon “"::"” or “"/"” operator. Each side of
the operator may be left blank, which would then default to the beginning
and end of the data, respectively. To specify a subset of times,
it is only required that the time specified be in standard ISO format, with
some form of separation between the elements. The time must be ‘left-filled’,
that is to specify a full year one needs only to provide the year, a month would require
the full year and the integer of the month requested - e.g. '1999-01'.
This format would extend all the way down to seconds - e.g. '1999-01-01 08:35:23'.
Leading zeros are not necessary. See the examples for more detail.
Users may also extend the xts
class to new classes to
allow for method overloading.
Additional benefits derive from the use of as.xts
and
reclass
, which allow for lossless two-way conversion
between common R time-series classes and the xts
object
structure. See those functions for more detail.