James Picerno
James Picerno

Reputation: 490

How to extract the dates in a separate file from a zoo file of security prices?

I'm trying to extract the dates in a separate file from a zoo file--specifically, the trading-day dates rather than standard calendar day dates. I download a series from Yahoo Finance as such:

vti <-get.hist.quote(instrument="vti",start="2012-12-31",quote="AdjClose")

And the resulting file:

> head(vti)
           AdjClose
2012-12-31    72.95
2013-01-02    74.80
2013-01-03    74.69
2013-01-04    75.07
2013-01-07    74.87
2013-01-08    74.67

This seems to work:

> dates <-(vti[,0])

But the resulting file isn't easy to work with. Here's the structure of the resulting "dates" file:

> str(dates)
‘zoo’ series from 2012-12-31 to 2013-04-26
  Data: num[1:81, 0 ] 
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : NULL
  Index:  Date[1:81], format: "2012-12-31" "2013-01-02" "2013-01-03" ...

Is there a superior method for extracting trading-day dates for, say, using elsewhere in creating graphs? Thanks much!

Upvotes: 0

Views: 183

Answers (1)

Matthew Lundberg
Matthew Lundberg

Reputation: 42649

zoo has a function to get the index:

dates <- index(vti)
> class(dates)
[1] "Date"

Upvotes: 1

Related Questions