Skip to content

Offset a vector by 1 to k months

3 messages · Joshua Ulrich, Ira Sharenow

3 days later
#
On Tue, Jun 21, 2011 at 12:03 AM, Ira Sharenow <irasharenow100 at yahoo.com> wrote:
Adding a certain number of months isn't necessarily that easy.  You
need to choose a calendar convention.  For example, see
RQuantLib::advance().
Are you sure this is fine?  Are you comfortable with the assumptions
being made?  For example:
mDate <- timeBasedSeq("201101/20110203")
tail(mDate + months(1))
# [1] "2011-03-01" "2011-03-02" "2011-03-03" "2011-03-01"
# [5] "2011-03-02" "2011-03-03"
You can add a month to each index value via:
ISOdate(year(index(z1)),month(index(z1))+1,day(index(z1)))
# [1] "2011-02-01 12:00:00 GMT" "2011-03-01 12:00:00 GMT"

But you can't have Date class objects inside xts/zoo objects.  xts/zoo
objects are just matrix objects with an index attribute and matrix
objects can only contain atomic types (or list or expression).

Perhaps if you provide a bit more detail about your actual problem,
someone can show you a more "R-like" solution.
Hope that helps,
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com