[R-SIG-Finance] R-Finance Tutorial

Gabor Grothendieck ggrothendieck at gmail.com
Thu Jul 1 16:57:20 CEST 2010

On Thu, Jul 1, 2010 at 8:59 AM, Ben Nachtrieb <ben.nachtrieb at gmail.com> wrote:
> Patrick,
> Yes, I am a programmer; however, R is set up quite a bit different. It seems
> like there are lots of redundancy in the community/resources. For example
> there seem to be 3 or 4 time series packages. Also, the responses I have
> received regarding my original question suggested 5 or 6 different packages
> and only 1 of those packages was mentioned more than once by the
> respondents. (Thank you!) From this perspective (finding and locating what
> to 'dive into'), I have found R very difficult. Also, R is very different
> from most languages I have used so that transition is quite challenging as
> well.
> That said I am committed to becoming an expert in R and see its
> wonderful efficiencies once it is understood by the user.
> Thanks!
> Ben

There are typically multiple ways to do something in R and there are
often multiple packages to do the same thing.  Sometimes there is a
preferred package but in other cases it just boils down to personal

Regarding your comment on time series frameworks, these:

- "zoo" and "xts" packages (these two packages are closely related),
- the rmetrics group of packages and
- "fts" (and also an older package "its" by the same author as "fts")

all have facilities to represent irregularly spaced series such as you
would need in finance.  There is also "rts" in the "tseries" package.

"ts" class in the core of R and the "tis" package can represent
regularly spaced series and, of course, since regularly spaces series
are a subset of irregularly spaced you can also use irregularly spaced
series package for regularly spaced series.

Each of the frameworks has its own characteristics and and since many
are under continual development they are moving targets so comments
can get quickly outdated; however, being a "zoo" developer I can at
least speak to that one.  In terms of learning, the interface to "zoo"
is very similar to that of "ts" in the core of R so if you know "ts"
then its relatively easy to pick up "zoo" and visa versa - if you know
"zoo" its easy to pick up "ts".  Particular attention was paid to
making it compatible with and to work the same as  the rest of R. Also
"zoo" is particularly general with the ability to represent an
unlimited number of time classes and all the series from any of the
other frameworks can be represented as zoo objects.  Mixtures are
possible so that, for example, you can have a "zoo" object which uses
the "timeDate" class of rmetrics as its time class.  The various "as"
functions in "zoo" can be used to translate among the representations
in many of the other packages.  It also has a long history yet is
still under active development, has quite a bit of documentation and
has spawned an ecosystem of over 50 other packages  that depend on or
are used with it.  Thus its easy to move back and forth among "zoo"
and "ts" and "xts" providing additional flexibility.

Some elements of the "zoo" package can be used without using "zoo"
objects at all including certain lattice graphics which have since
migrated to the "lattice" package (which is distributed as part of the
R download), "yearmon" and "yearqtr" time classes and the "na.locf"

To learn more, see this page:


and read the three vignettes (pdf documents) linked there.  Also at
the bottom of the same web page in the reverse dependencies portion of
that page are links to the 50 or so other packages that depend on or
use ".  (The "zoo" FAQ also has such a list.) You can click on each of
those and find out more info on each of those packages.  You can also
access the "zoo" vignettes mentioned above like this from within R:

vignette(package = "zoo")

and can also list the help information from that web page or from
within R like this:

help(package = zoo)

and get individual help page like this, e.g. to get the help page on
the zoo command:


That will bring up a local web page which you can read.  Also at the
bottom of that page click on "Index" to get a detailed list of links
to help pages of other commands which you can click on in turn.

Then try the same thing with the related "xts" package ("xts" is a
subclass of "zoo") and also the "FinTS" package (which has no vignette
but does have a book associated with it which you may wish to read).
"FinTS" has a GUI to run its scripts that you start like this:

More information about the R-SIG-Finance mailing list