jeudi 30 juillet 2015

xts indexing lag error

I have a question about indexing with xts. I understand that when I use SPY['2002-10-17/'], I can get all of the data in my xts object from 2002-10-17 to the last date. This however is not true if I write an ifelse statement and do the same call. Below is code:

library(quantmod)
getSymbols('SPY',from='2002-01-01') 
SPY=Cl(SPY) #pull only the closes
returns=(SPY-lag(SPY,1))/(lag(SPY,1)) #returns calculation
head(SPY['2002-10-17/']) #This works and starts at 2002-10-17
head(ifelse(returns>0,1,0)['2002-10-17/']) #this for some odd reason starts at 2002-10-18

Can anyone tell me why this is the case. I am truly befuddled.

Aucun commentaire:

Enregistrer un commentaire