Skip to content

Basic Help with Zoo objects and trading days

2 messages · John Nicholas, Gabor Grothendieck

#
On Sat, Jan 29, 2011 at 2:03 PM, john nicholas <jbnichola at sbcglobal.net> wrote:
Here are a few ways:

1. In get.hist.quote call use compression = "w" rather than compression = "d" .

2. use apply.weekly in xts where s is from your post:

   library(xts)
   apply.weekly(s, tail, 1)

3. Use the following where nextfri is a function that appears in
vignette("zoo-quickref") and s is from your post:

   nextfri <- function(x) 7 * ceiling(as.numeric(x - 5 + 4)/7) + as.Date(5 - 4)

   # and this
   aggregate(s, nextfri, tail, 1)

   # or this
   s[!duplicated(nextfri(time(s)), fromLast = TRUE)]

Note that the compression = "w" solution labels each week by using the
Monday of that week.  The apply.weekly and duplicated solutions label
each week by the date of the last present data point in that week.
The aggregate solution labels each point by the Friday of that week.

You also might want to look at getSymbols in the quantmod package.