[R-SIG-Finance] timeSeries

jeff.a.ryan at gmail.com jeff.a.ryan at gmail.com
Tue Feb 12 15:34:34 CET 2008

A simple solution to making all common R time series classes into a more 'data.frame/matrix/zoo' style object is available in the new 'xts' package on CRAN with the most recent source and windows builds at http://R-forge.r-project.org/projects/xts

'as.xts' converts the original class into an 'xts' object that contains information about the original objects structure that is usually lost during standard 'as' operations.

A quick example using the quantmod package:

library(quantmod) #load the quantmod package-this loads xts

DJI.timeSeries <- getSymbols('^DJI', src='yahoo', ret='timeSeries', auto.assign=FALSE)

DJI.ts <- getSymbols('^DJI', src='yahoo', ret='ts', auto.assign=FALSE)

class(DJI.timeSeries). # a 'timeSeries' object.
class(DJI.ts) # a 'ts' object


# converting both to 'xts' yields
# objects that are nearly identical
# apart from the xtsAttributes - these hold
# non-time-series attributes belonging to the original
# class, or ones added by the user.


At this point 'xts' objects behave much like any standard data.frame, matrix or, most closely, zoo object.  They have some unique user 'xts' methods but all standard 'zoo' methods will work (it just extends 'zoo')

The notable differences:

* The rownames are a character string of the time-index, created automatically.

* The index is a true time based one - meaning it is of class 'Date', 'POSIXct', 'chron', 'timeDate', 'yearmon', or 'yearqtr'.  You can view/change this with 'indexClass' and 'convertIndex'

* the original data to allow for conversion back to the original class is preserved internally.  A call to 'reclass' is all that is needed.  This is handly to allow for temporary use of 'xts'-style subsetting while letting the user continue using his preferred data object.  This is also very useful inside functions to allow for automatic handling of a variety of input objects.  chartSeries in quantmod and to.period in xts use this approach.


An additional benefit to using 'xts' includes explicit time-based subsetting, as well as some additional functionality that utilizes the time-based index.

To get the first 3 months of the series:

The rest of the series:

The package is under active development - but the purpose of simplifying the workflow regardless of the user's data object choice is the overall goal.  To that end, the r-forge version could be exactly what you need - soon to be pushed to CRAN.


PS. I apologize if some of the above syntax is mis-typed. I am unable to get to a computer to double check.
Sent via BlackBerry from T-Mobile

-----Original Message-----
From: "Vorlow Constantinos" <CVorlow at eurobank.gr>

Date: Mon, 11 Feb 2008 17:22:17 
To:<r-sig-finance at stat.math.ethz.ch>
Subject: [R-SIG-Finance] timeSeries

Dear all,
I am experimenting with Rmetrics and the fImport library...
DJret<-(yahooSeries(symbols = c("^DJI"), from = NULL, to = NULL, 
    nDaysBack = 408, quote = c("Close"), 
    aggregation = c("d"), returnClass = c("timeSeries"), getReturns =

My question is:
Can you run stats, regressions etc. on a "timeSeries" object?   
If you choose to download the data as a "ts" object
DJret<-(yahooSeries(symbols = c("^DJI"), from = NULL, to = NULL, 
    nDaysBack = 408, quote = c("Close"), 
    aggregation = c("d"), returnClass = c("ts"), getReturns = TRUE))
everythings works fine though I can't gate the dates to display on a ts
Any clues?
I found out that trying to plot some timeSeries objects and calling a
barplot funcion, causes R (eventually) to crash...
Has anybody else experienced this problem?
Thanks in advance for your time,
platform       i386-pc-mingw32             
arch           i386                        
os             mingw32                     
system         i386, mingw32               
major          2                           
minor          6.1                         
year           2007                        
month          11                          
day            26                          
svn rev        43537                       
language       R                           
version.string R version 2.6.1 (2007-11-26)

P Think before you print.

This e-mail is confidential. If you are not the intended recipient, you should not copy it, re-transmit it, use it or disclose its contents, but should return it to the sender immediately and delete the copy from your system.
EFG Eurobank Ergasias S.A. is not responsible for, nor endorses, any opinion, recommendation, conclusion, solicitation, offer or agreement or any information contained in this communication.
EFG Eurobank Ergasias S.A. cannot accept any responsibility for the accuracy or completeness of this message as it has been transmitted over a public network. If you suspect that the message may have been intercepted or amended, please call the sender.

	[[alternative HTML version deleted]]

R-SIG-Finance at stat.math.ethz.ch mailing list
-- Subscriber-posting only. 
-- If you want to post, subscribe first.

More information about the R-SIG-Finance mailing list