[R-SIG-Finance] Relative Date Question
Jeff Ryan
jeff.a.ryan at gmail.com
Thu Aug 28 16:05:46 CEST 2008
using xts:
> library(xts)
> timeBasedSeq('2000-02/2001-01',"Date")-1
[1] "2000-01-31" "2000-02-29" "2000-03-31" "2000-04-30" "2000-05-31"
[6] "2000-06-30" "2000-07-31" "2000-08-31" "2000-09-30" "2000-10-31"
[11] "2000-11-30" "2000-12-31"
timeBasedSeq uses the maximal resolution you specify to build the
sequence, so by including only the CCYY-MM you get months.
The trick is that months always start on the first, and are always
preceded by the last of the previous month.
?timeBasedSeq
?endpoints
also:
> Sys.setenv(TZ='GMT') # watch for TZ issues...
> as.Date(lastof(2000,1:12))
[1] "2000-01-31" "2000-02-28" "2000-03-31" "2000-04-30" "2000-05-31"
[6] "2000-06-30" "2000-07-31" "2000-08-31" "2000-09-30" "2000-10-31"
[11] "2000-11-30" "2000-12-31"
> as.Date(lastof(rep(2000:2001,each=12),1:12))
[1] "2000-01-31" "2000-02-28" "2000-03-31" "2000-04-30" "2000-05-31"
[6] "2000-06-30" "2000-07-31" "2000-08-31" "2000-09-30" "2000-10-31"
[11] "2000-11-30" "2000-12-31" "2001-01-31" "2001-02-28" "2001-03-31"
[16] "2001-04-30" "2001-05-31" "2001-06-30" "2001-07-31" "2001-08-31"
[21] "2001-09-30" "2001-10-31" "2001-11-30" "2001-12-31"
HTH,
Jeff
On Thu, Aug 28, 2008 at 4:14 AM, Ruvashen Padayachee
<RPadayachee at investec.co.za> wrote:
> Hi there. I have a quick query. What is the best way in R to find out a
> date relative to another date?
>
> For example, how can I find the date one month after "2008/09/30" ?
>
> If there is a method, would it take into account different days in the
> month?
>
> Thank you for your help.
>
>
>
> http://www.investec.com/EmailDisclaimer/emaildisclaimer.htm
>
> The disclaimer also provides our corporate information and names of our directors as required by law.
>
> The disclaimer is deemed to form part of this message in terms of Section 11 of the Electronic Communications and Transactions Act 25 of 2002.
> If you cannot access the disclaimer, please obtain a copy thereof from us by sending an email to: disclaimer at investec.co.za
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>
--
Jeffrey Ryan
jeffrey.ryan at insightalgo.com
ia: insight algorithmics
www.insightalgo.com
More information about the R-SIG-Finance
mailing list