[R-SIG-Finance] preserving dates in output of tseries

aschmid1 aschmid1 at stevens.edu
Thu May 1 18:34:38 CEST 2014


I've been stuck for a while with seemingly simple task. I calculate 
returns using data from yahoo:
etf = "SPY"
startDate = "2008-12-01"
endDate = "2014-04-04"
prc <- get.hist.quote(instrument = etf, startDate, endDate, quote = 
"AdjClose", provider = "yahoo" )
tt<-as.zoo(prc)
dates<-index(tt)
r<-diff(log(tt))
tab<-r
> head(tab)
               AdjClose
2008-12-02  0.03776569
2008-12-03  0.02372065
2008-12-04 -0.02345690
2008-12-05  0.03038800
2008-12-08  0.03432357
2008-12-09 -0.01657462

But when I save results to a file, dates are replaced:

write.table(tab, file=filename, quote=F)

Here is the contents of the output file:
AdjClose
1 0.0377656920201943
2 0.0237206482126213
3 -0.0234569003540432
4 0.0303880024180421
5 0.0343235654549394
6 -0.0165746208209656

What can be done about this?
Thanks! Alec



More information about the R-SIG-Finance mailing list