[R-SIG-Finance] (no subject)
sprohl at na.uni-tuebingen.de
sprohl at na.uni-tuebingen.de
Fri Dec 5 12:10:44 CET 2008
Dear All,
I have some problems with downloading and matching daily data
of irregular frequency. I tried to apply zoo-codes to read file
data<-read.zoo("C://data.txt",sep="",format="%Y %b %d")
and get the following message:
Fehler in scan(file, what, nmax, sep, dec, quote, skip, nlines,
na.strings, : Zeile 31 hatte keine 2 Elemente
The data has missing values. How could I properly download them as
time series and match different datasets by "Date". Unfrtunately,
conventional procedures do not work properly.
Thanks in advance,
Soeren
>>>>> "JK" == J Konnonen <jkonn2001 at yahoo.com>
>>>>> on Wed, 3 Dec 2008 06:45:45 -0800 (PST)
>
> JK> Dear All,
> JK>
> JK> I met some problems with data handling when using the timeSeries
> library
> JK>
> JK> I have some csv files, each containing two columns, first column
> are the series of dates, second are the series prices
> JK>
> JK> 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
> JK>
> JK> > library(timeSeries)
> JK>
> JK> > returnsdata <- read.csv("foo1.csv",header=T,sep=",")
> JK> > attach(returnsdata)
> JK> > foo1 = as.timeSeries(returnsdata)
> JK> > foo1bind <- returns(window(foo1, start=2007-01-01,
> end=2007-12-31))
> JK>
> JK> > returnsdata <- read.csv("foo2.csv",header=T,sep=",")
> JK> > attach(returnsdata)
> JK> > foo2 = as.timeSeries(returnsdata)
> JK> > foo2bind <- returns(window(foo2, start=2007-01-01,
> end=2007-12-31))
> JK>
> JK> > ralls <- cbind(foo1bind,foo2bind)
> JK> > colnames(ralls) <- c("FOO1","FOO2")
> JK>
> JK> And then I would like to have the last 1000 lines of this matrix
> for some computations
> JK>
> JK> > index <- ... #some value
> JK> > past1000 <- ralls[(index-1000):(index-1)]
>
> you are missing the comma ! This is why you get back a vector. This is
> the same behaviour as with a matrix. Without a comma you do not know if
> you subset in the rows and columns.
>
> I suppose you wanted to use
>
> ralls[(index-1000):(index-1),]
>
> Note you could use the function tail()
>
> JK>
> JK> But
> JK> > print(past1000)
> JK> shows that past1000 doesn't contain either the column of dates, nor
> the header line, only the columns of returns
> JK>
> JK> Also
> JK> > print(is.timeSeries(past1000))
> JK> 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
> JK>
> JK> And despite
> JK> > print(is.timeSeries(ralls))
> JK> returns TRUE, and printing the whole ralls object contains the
> dates column and the header
> JK> > print(ralls at .Data[,1])
> JK> 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?
> JK>
> JK> 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.
> JK>
> JK> Any suggestion is very much appreciated.
> JK>
> JK> Best regards,
> JK> /Johan
> JK>
> JK> _______________________________________________
> JK> R-SIG-Finance at stat.math.ethz.ch mailing list
> JK> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> JK> -- Subscriber-posting only.
> JK> -- If you want to post, subscribe first.
>
>
> --
> PhD student
> Swiss Federal Institute of Technology
> Zurich
>
> www.ethz.ch
>
> _______________________________________________
> 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