[R-SIG-Finance] ranking xts objects
Jeffrey Ryan
jeffrey.ryan at lemnica.com
Sat Mar 10 09:04:53 CET 2012
I don't see exactly why you are doing this (been a long day), but I
think you want something like after reading your question (ignoring
your example):
t(apply(data,1,rank)) # t() just makes it look more like
the original xts
GE.Close XOM.Close GOOG.Close XLU.Close
2005-01-31 2 3 4 1
2005-02-28 2 3 4 1
2005-03-31 2 3 4 1
2005-04-30 2 3 4 1
2005-05-31 2 3 4 1
2005-06-30 2 3 4 1
2005-07-31 2 3 4 1
2005-08-31 2 3 4 1
2005-09-30 2 3 4 1
2005-10-31 2 3 4 1
2005-11-30 2 3 4 1
2005-12-31 2 3 4 1
2006-01-31 2 3 4 1
2006-02-28 2 3 4 1
2006-03-31 2 3 4 1
2006-04-30 2 3 4 1
2006-05-31 2 3 4 1
2006-06-30 2 3 4 1
2006-07-31 1 3 4 2
2006-08-31 1 3 4 2
2006-09-30 2 3 4 1
2006-10-31 1 3 4 2
2006-11-30 1 3 4 2
2006-12-31 2 3 4 1
2007-01-31 1 3 4 2
2007-02-28 1 3 4 2
2007-03-31 1 3 4 2
2007-04-30 1 3 4 2
2007-05-31 1 3 4 2
2007-06-30 1 3 4 2
2007-07-31 2 3 4 1
2007-08-31 2 3 4 1
2007-09-30 2 3 4 1
2007-10-31 1 3 4 2
2007-11-30 1 3 4 2
2007-12-31 1 3 4 2
2008-01-31 1 3 4 2
2008-02-29 1 3 4 2
2008-03-31 1 3 4 2
2008-04-30 1 3 4 2
2008-05-31 1 3 4 2
2008-06-30 1 3 4 2
2008-07-31 1 3 4 2
2008-08-31 1 3 4 2
2008-09-30 1 3 4 2
2008-10-31 1 3 4 2
2008-11-30 1 3 4 2
2008-12-31 1 3 4 2
2009-01-31 1 3 4 2
2009-02-28 1 3 4 2
2009-03-31 1 3 4 2
2009-04-30 1 3 4 2
2009-05-31 1 3 4 2
2009-06-30 1 3 4 2
2009-07-31 1 3 4 2
2009-08-31 1 3 4 2
2009-09-30 1 3 4 2
2009-10-31 1 3 4 2
2009-11-30 1 3 4 2
2009-12-31 1 3 4 2
2010-01-31 1 3 4 2
2010-02-28 1 3 4 2
2010-03-31 1 3 4 2
2010-04-30 1 3 4 2
2010-05-31 1 3 4 2
2010-06-30 1 3 4 2
2010-07-31 1 3 4 2
2010-08-31 1 3 4 2
2010-09-30 1 3 4 2
2010-10-31 1 3 4 2
2010-11-30 1 3 4 2
2010-12-31 1 3 4 2
2011-01-31 1 3 4 2
2011-02-28 1 3 4 2
2011-03-31 1 3 4 2
2011-04-30 1 3 4 2
2011-05-31 1 3 4 2
2011-06-30 1 3 4 2
2011-07-31 1 3 4 2
2011-08-31 1 3 4 2
2011-09-30 1 3 4 2
2011-10-31 1 3 4 2
2011-11-30 1 3 4 2
2011-12-31 1 3 4 2
2012-01-31 1 3 4 2
2012-02-29 1 3 4 2
2012-03-31 1 3 4 2
>
Hopefully I am close, and that this helps in some way,
Jeff
On Fri, Mar 9, 2012 at 9:49 PM, Gaurav Malhotra <gaurav_m_159 at yahoo.com> wrote:
> Hi,
>
> I've been trying to rank stocks by month/time period. The code I have below is ranking each stock over its range, instead of going across and ranking row by row
>
>
>
> symbols= c("GE","XOM","GOOG","XLU")
> getSymbols(symbols, src='yahoo', index.class=c("POSIXt","POSIXct"), from='2005-01-01')
>
> for(symbolinsymbols) {
> x<-get(symbol)
> x<-to.monthly(x,indexAt='lastof',drop.time=TRUE)
> indexFormat(x)<-'%Y-%m-%d'
> colnames(x)<-gsub("x",symbol,colnames(x))
> assign(symbol,x)
> }
>
> data<-cbind(Cl(GE),Cl(XOM),Cl(GOOG),Cl(XLU))
>
> NewVar<-cut(x,quantile(x,(0:10)/10),include.lowest=TRUE)
>
>
>
> How do I modify this so that I get the ranks for each time stamp?
>
> Thanks!
>
> Gaurav M
> [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
--
Jeffrey Ryan
jeffrey.ryan at lemnica.com
www.lemnica.com
www.esotericR.com
R/Finance 2012: Applied Finance with R
www.RinFinance.com
See you in Chicago!!!!
More information about the R-SIG-Finance
mailing list