[R] help on timeseries

cameron raymond.fu at invesco.com
Tue Dec 7 18:42:00 CET 2010


i have time series of momentum signal.  I want to get the date of each of the
"-1"  signal period.  for example , the first period of -1 signal begins on
2005-9-21 and ends on 2005-9-28.  2nd period of -1 signal begins on
2005-09-30 and ends on 2005-10-28.


Thx
Cameron

     date        Px       200MA     Signals
2005-09-15   26.27  25.83865    1
2005-09-16   26.07  25.83275    1
2005-09-19   26.00  25.82730    1
2005-09-20   25.84  25.82035    1
2005-09-21   25.49  25.81115   -1
2005-09-22   25.34  25.80250   -1
2005-09-23   25.27  25.79205   -1
2005-09-26   25.27  25.78225   -1
2005-09-27   25.34  25.77355   -1
2005-09-28   25.67  25.76565   -1
2005-09-29   25.94  25.75920    1
2005-09-30   25.73  25.75230   -1
2005-10-03   25.50  25.74400   -1
2005-10-04   24.98  25.73410   -1
2005-10-05   24.67  25.72270   -1
2005-10-06   24.73  25.71100   -1
2005-10-07   24.59  25.69910   -1
2005-10-10   24.46  25.68635   -1
2005-10-11   24.41  25.67415   -1
2005-10-12   24.30  25.66090   -1
2005-10-13   24.59  25.64935   -1
2005-10-14   24.67  25.63890   -1
2005-10-17   24.53  25.62795   -1
2005-10-18   24.57  25.61710   -1
2005-10-19   25.09  25.60835   -1
2005-10-20   24.79  25.59840   -1
2005-10-21   24.78  25.58855   -1
2005-10-24   25.10  25.58070   -1
2005-10-25   25.03  25.57185   -1
2005-10-26   25.11  25.56375   -1
2005-10-27   24.85  25.55410   -1
2005-10-28   25.53  25.55040   -1
2005-10-31   25.70  25.54830    1
2005-11-01   25.96  25.54650    1
2005-11-02   26.46  25.54890    1
2005-11-03   26.44  25.55180    1
2005-11-04   26.66  25.55685    1

-code

	library(tseries) 
	library(timeSeries)
	
	msft <- as.timeSeries(get.hist.quote(instrument="MSFT", start="1986-03-31",
end="2008-09-10", quote=c("C"), provider="yahoo", retclass="zoo")) 
	msft <- cbind(msft,as.timeSeries(rollapply(as.zoo(msft
),width=200,mean,align="right")))
	msft <- cbind(msft,NA)
	msft[,3] <- (ifelse(msft[,1]>msft[,2],1,-1))

	print(msft)

-- 
View this message in context: http://r.789695.n4.nabble.com/help-on-timeseries-tp3076866p3076866.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list