Skip to content
Prev 2676 / 15274 Next

XTS - endpoints omits price changes

Hi James,

period.apply works *within* the given interval, so it will not use the
previous month's values in any calculation.  The diff function omits
the first value for each month by default, which are your missing
days' returns.

To achieve your desired result you could calculate daily returns
before calling period.apply:
period.apply(diff(log(x$Close),na.pad=TRUE), INDEX=endpoints(x,
'months'), FUN=sum)
# returns a 'zoo' series

Or you can calculate returns on the end-of-month values only:
diff(log(x[endpoints(x,'months'),'Close']))

But you need the Close for the last day of 2006-12 in order to
calculate the return for the first day of 2007 and therefore calculate
the year's return by your definition.

Best,
Josh

--
http://quantemplation.blogspot.com
On Wed, Jul 16, 2008 at 4:30 PM, James <j at jtoll.com> wrote: