0

I have the following problem. I have a XTS containing a date column and several valuations, which should be ranked (biggest = best rank). So my original XTS is test:

> str(index(Test))
Date[1:235], format: "1995-01-31" "1995-02-28" "1995-03-31" "1995-04-28" "1995-05-31" "1995-06-30" "1995-07-31" ...

Now, my rankValuations function:

rankValuations<-function(ValuationXTS){
  #Ranks the xts object asset valuations 
  #ValuationXTS is a xts time series with asset valuations
  #Returns an xts object with ranks (asset with the greatest valuation receives 1)
  #The ties parameter results in an ascending ranking. If two share the same rank, the first in the matrix gets the first rank
  ranked<-as.xts(t(apply(-ValuationXTS,1,rank, ties.method="first",na.last=TRUE)))
}

After running this my index format has changed to POSIX:

> Test<-rankValuations(Test)
> str(index(Test))
 POSIXct[1:235], format: "1995-01-31" "1995-02-28" "1995-03-31" "1995-04-28" "1995-05-31" "1995-06-30" "1995-07-31" ...

And this is a big problem because in the POSIX I have now a timezone. If using later on merge.xts it never matches since the POSIX dates are 1 day prior than in the to be merged with XTS which has a Date index. So how can I stop the rank method of changing Date to POSIX?

Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
MichiZH
  • 5,587
  • 12
  • 41
  • 81
  • You haven't provided a reproducible example so I can't try it but try converting the xts object to zoo, perform the ranking and convert back to see if that fixes it. – G. Grothendieck Sep 09 '14 at 13:54
  • 1
    Don't have `xts` installed, but from what I have read from the doc, the coerce method `as.xts` has a `dateFormat` argument set by default to `POSIXct`. Maybe you can try with `dateFormat="Date"` in your call to `as.xts`. – nicola Sep 09 '14 at 13:58

0 Answers0