[R-sig-finance] How and when to USE ts and its objects?

Gabor Grothendieck ggrothendieck at myway.com
Fri Oct 1 19:16:26 CEST 2004



ts is for regularly spaced time series and works best with
monthly or coarser time series since there is no explicit
date support for finer granularity in ts.  If such date
support is not important then ts is fine for finer
granularity series as well.  ts is defined in the stats
package which comes out-of-the-box with R so its normally
always available and is therefore the most likely to be
supported.

If you need irregularly spaced time series such as those
that are defined for weekdays but not holidays or weekends then
you can choose from a number of options:

1. The irts class in the tseries package changes the
frequency of the time scale to simulate a irregular time
series with a regular one in such a way that its reversable.

2. The its class in the its package uses S4 constructs to
define a time series object with a POSIXct time scale.

3. The zoo class has _not_ hard coded in the datetime class
so it can use just about any datetime class (e.g. Date,
chron, POSIXct).  In most cases zoo implements methods which
simply extend base generics to achieve interface
compatibility with ts and the base.  This also means that in
most cases the user does not have to learn a whole new set
of commands making it easier to use. A major new version of
zoo is in development so it is being actively maintained and
enhanced.  The current version of zoo on CRAN will import ts
and irts objects (as well as matrices and vectors) and the
upcoming version will also import its objects.  Its also
easy to extract the data and datetime.   

I personally use ts for my regular time series and zoo for
my irregular time series and have contributed to the
development of the latter.

Hope that helps.

---

Creating specialized objects for use within a single R package was for me
the easy part
(the previous question on this list). My questions are:

1. How portable is the object to other R packages?
Which packages will accept the object as is?
Will the object work in LM or other linear model packages?

2. If another R package won't accept the object as is, is there a function
available to
coerce the object and/or the objects values to the appropriate type?

Is there documentation that deals with object compatibility within R?

As far as I can tell, Factors are accepted in almost every package in R,
but times series objects
(ts or its) are restricted to a few specialized packages.

3. Can the time series objects be stored in and retrieved from a
relational database (perhaps via RODBC)?

Before I can recommend R to my coworkers, I will have to build either a
compelling demo or a GUI,
that performs useful work. Before I can even begin to DESIGN the demo or
GUI I need to know
which parts of R are compatible. If I build a GUI that creates time series
objects, will it crash and
burn if I try to incorporate parts of John Fox's RCommander GUI?
http://socserv.socsci.mcmaster.ca/jfox/Misc/Rcmdr/

If different parts of a GUI require different objects, can I make the
transition transparent to the user of the GUI?

The upcoming RMetrics modules particularly fBonds and fPorfolios look
useful:
http://www.itp.phys.ethz.ch/econophysics/R/pdf/DocFactsheet.pdf

Does RMetrics use ITS objects or does it have its own time series objects
(timeDate / timeSeries Classes)?

It might be neat to combine an RMetrics backend with EPRI's new RPad GUI
fontend:
http://tolstoy.newcastle.edu.au/R/packages/04/0051.html
http://www.rpad.org/Rpad/

Look at the RPad screenshot and imagine Yield Curves and Efficiency
Frontiers.

Even without RMetrics, Patrick Burns (Burns Statistics) seems to be making
some progress in this area.
http://www.burns-stat.com/

The City I work for has a variety portfolios ranging from long term
defined benefit pension plans
to short term cash funds each with its own investment policy and benchmark
portfolios.

Do our investment policies achieve their intended purposes? Do they
overconstrain the portfolio?
Do they provide a false sense of confidence in meeting risk management
objectives?

These are not just theoretical concerns, as a Budget Analyst, I am
painfully aware of the fact
that when our defined benefit pension funds fall short of their
actuarially defined investment targets
-- the City's General Fund has to make up the difference. It could be
worse, absent vigilance,
we could have an LA-style (Orange County, CA) derivative meltdown.

Orange County (November 1994): Orange County, California has an investment
pool
that supports various pension liabilities. The pool lost USD 1700 MM from
structured notes
and leveraged repo positions.
http://www.riskglossary.com/articles/risk_management.htm

A quick check of Yahoo shows that the Dow Jones Industrial Average is
almost exactly where it was 5 years ago.
http://finance.yahoo.com/q/bc?s=^DJI&t=5y
Interest rates are near zero and oil is nearly $50 a barrel.

So my real concern is, in a tight budget environment, can the City of
Orlando use open source software
to assist its development and monitoring of investment policies? or would
the City get bogged down in
issues of times series object compatibility?

In my own area, Budget, assuming I can get the data out of our financial
system into a convenient relational data base,
and into R via RODBC -- what sort of time series objects should I build
for time series and econometric modeling?
-- or should I just use GRETL? or MS Excel? or RGnumeric?
http://gretl.sourceforge.net/
http://www.omegahat.org/RGnumeric/

Jim Callahan, MBA
Budget Analyst
Management, Budget & Accounting
City of Orlando
(407) 246-3039 office
(407) 234-3744 cell phone
     [[alternative HTML version deleted]]



More information about the R-sig-finance mailing list