[R-SIG-Finance] data handling with timeSeries

Gabor Grothendieck ggrothendieck at gmail.com
Wed Dec 3 16:33:43 CET 2008


Also tail(z, 1000) gives the last 1000 points of zoo object z.

On Wed, Dec 3, 2008 at 10:21 AM, Jeff Ryan <jeff.a.ryan at gmail.com> wrote:
> Try:
>
> past1000 <- ralls[(index-1000):(index-1),   ]   # the comma is critical
>
>> z <- zoo(1:10, Sys.Date()+1:10)
>> as.timeSeries(z)
> GMT
>            x
> 2008-12-04  1
> 2008-12-05  2
> 2008-12-06  3
> 2008-12-07  4
> 2008-12-08  5
> 2008-12-09  6
> 2008-12-10  7
> 2008-12-11  8
> 2008-12-12  9
> 2008-12-13 10
>> as.timeSeries(z)[1:3]
> [1] 1 2 3
>> as.timeSeries(z)[1:3,]
> GMT
>           x
> 2008-12-04 1
> 2008-12-05 2
> 2008-12-06 3
>
> HTH
> Jeff
>
>
> On Wed, Dec 3, 2008 at 8:45 AM, J Konnonen <jkonn2001 at yahoo.com> wrote:
>> 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
>>
>> _______________________________________________
>> R-SIG-Finance at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only.
>> -- If you want to post, subscribe first.
>>
>
>
>
> --
> Jeffrey Ryan
> jeffrey.ryan at insightalgo.com
>
> ia: insight algorithmics
> www.insightalgo.com
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>



More information about the R-SIG-Finance mailing list