[R-SIG-Finance] data handling with timeSeries

J Konnonen jkonn2001 at yahoo.com
Wed Dec 3 15:45:45 CET 2008


Dear All,

I met some problems with data handling when using the timeSeries library

I have some csv files, each containing two columns, first column are the series of dates, second are the series prices 

I read in all files using, and create a matrix with the dates in the first column, and the calculated returns in the remaining columns

> library(timeSeries)

> returnsdata <- read.csv("foo1.csv",header=T,sep=",")
> attach(returnsdata)
> foo1 = as.timeSeries(returnsdata)
> foo1bind <- returns(window(foo1, start=2007-01-01, end=2007-12-31))

> returnsdata <- read.csv("foo2.csv",header=T,sep=",")
> attach(returnsdata)
> foo2 = as.timeSeries(returnsdata)
> foo2bind <- returns(window(foo2, start=2007-01-01, end=2007-12-31))

> ralls <- cbind(foo1bind,foo2bind)
> colnames(ralls) <- c("FOO1","FOO2")  

And then I would like to have the last 1000 lines of this matrix for some computations

> index <- ... #some value
> past1000 <- ralls[(index-1000):(index-1)]
           
But 
> print(past1000) 
shows that past1000 doesn't contain either the column of dates, nor the header line, only the columns of returns  

Also 
> print(is.timeSeries(past1000))
returns FALSE, and although I attempted several conversions on past1000, which resulted this check to be TRUE, the effective content of past1000 didn't seem to be changed, still no dates were printed

And despite
> print(is.timeSeries(ralls))
returns TRUE, and printing the whole ralls object contains the dates column and the header
> print(ralls at .Data[,1])           
returns only the second column of ralls (that is, the first column of returns) and no date column is displayed. This seems to indicate that perhaps there is already some problem with ralls, rooted possibly in the datafile reading and binding?           

The expectation would be to have past1000 an object where the first column contains the dates, and the remaining columns contain the returns, but I couldn't figure it out so far.

Any suggestion is very much appreciated.

Best regards,
/Johan



More information about the R-SIG-Finance mailing list