Try

write.zoo function. works out of the box.

write.zoo(head(tab))
## "Index" "AdjClose"
## 2008-12-02 0.0377656920201943
## 2008-12-03 0.0237206482126213
## 2008-12-04 -0.0234569003540432
## 2008-12-05 0.0303880024180421
## 2008-12-08 0.0343235654549394
## 2008-12-09 -0.0165746208209656


On Fri, May 2, 2014 at 12:34 AM, aschmid1 <aschmid1@stevens.edu> wrote:

> 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
>
> _______________________________________________
> R-SIG-Finance@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.
>

	[[alternative HTML version deleted]]

