[R-SIG-Finance] trouble with timeSequence

Mercurio Danilo 1850 SPI Danilo.Mercurio at Sparinvest.com
Wed Sep 22 17:55:43 CEST 2010


 Hi !

thank you! this was very helpful!

-----Ursprüngliche Nachricht-----
Von: Yohan Chalabi [mailto:chalabi at phys.ethz.ch] 
Gesendet: Dienstag, 21. September 2010 18:30
An: Mercurio Danilo 1850 SPI
Cc: r-sig-finance at stat.math.ethz.ch
Betreff: Re: [R-SIG-Finance] trouble with timeSequence [bayes]


On Sep 21, 2010, at 5:55 PM, Mercurio Danilo 1850 SPI wrote:

> Hi!
> 
> I was trying to use the function "timeSequence" in order to generate a sequence of dates at 6 months frequency but I could not.
> 
> In order to obtain 3 month frequency I wrote this:
> 
> ----------------
> timeSequence(from = "1999-12-31", to = "2000-12-31", by = "quarter")
> ------------
> 
> which delivers the exact output:
> 
> ----------
> GMT
> [1] [1999-12-31] [2000-03-31] [2000-07-01] [2000-10-01] [2000-12-31]
> ------------
> 
> If I try to obtain the 6 month frequency, I write the following (after having read the help file):
> 
> ---------------------------------
> timeSequence(from = "1999-12-31", to = "2000-12-31", by = "6 months")
> -----------------------------
> 
> which returns:
> ----------------------
> error in match.arg(by) :
>  'arg' should be one of "day", "year", "quarter", "month", "week", "hour", "min", "sec"
> ---------------------
> 
> so I took a look to the code behind the function 'timeSequence' (see below).
> The function "match.arg(by)" checks that  "by" equals one of:
> "day", "year", "quarter", "month", "week", "hour", "min", "sec"
> 
> however the computation (as far as I understood) is made by another function (?): "seq.timeDate" which apparently accepts
> the value " by = "3 months" ".


Hi,

try fhe following

td1 <- timeDate("1999-12-31")
td2 <- timeDate("2000-12-31")
seq(td1, td2, by = "6 months")

HTH
Yohan


> 
> What puzzles me is that whe I try to call the function "seq.timeDate"  R answers me that it cannot find it.
> 
> Of course I could be able to construct a time sequence with 6 month frequency with some workaround, however I would like
> to understand the problem a little more.
> 
> Thank you for any help!
> 
> Kind regards
> 
> Danilo
> 
> -------------------------------------------------------------------------------------------------------------------
>> timeSequence
> function (from, to = Sys.timeDate(), by = c("day", "year", "quarter",
>    "month", "week", "hour", "min", "sec"), length.out = NULL,
>    format = NULL, zone = "", FinCenter = "")
> {
>    if (zone == "")
>        zone <- getRmetricsOptions("myFinCenter")
>    if (FinCenter == "")
>        FinCenter <- getRmetricsOptions("myFinCenter")
>    if (missing(from))
>        from = timeDate(to, format = format, zone = zone, FinCenter = FinCenter) -
>            24 * 29 * 3600
>    if (!is.null(length.out))
>        to = from
>    by = match.arg(by)
>    if (by == "quarter")
>        by = "3 months"
>    format.from = format.to = format
>    if (is.null(format)) {
>        format.from = whichFormat(as.character(from))
>        format.to = whichFormat(as.character(to))
>        from <- timeDate(from, format = format.from, zone = zone,
>            FinCenter = FinCenter)
>        to <- timeDate(to, format = format.to, zone = zone, FinCenter = FinCenter)
>    }
>    else {
>        from <- timeDate(from, format = format, zone = zone,
>            FinCenter = FinCenter)
>        to <- timeDate(to, format = format, zone = zone, FinCenter = FinCenter)
>    }
>    tseq <- if (length(length.out))
>        seq.timeDate(from = from, by = by, length.out = length.out)
>    else seq.timeDate(from = from, to = to, by = by)
>    tseq
> }
> 
> Dr. Danilo Mercurio
> Quantitative Analyst
> Erste Sparinvest
> Global Strategies and Research
> Habsburgergasse 2
> A-1010 Wien
> Tel.:   +43 (0) 50100 - 19957
> Fax.:  +43 (0) 50100 9 - 19957
> Mob.: +43 (0) 50100 6 - 19957
> 
> _______________________________________________
> 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.
> -- Also note that this is not the r-help list where general R questions should go.
> 

--
PhD candidate
Swiss Federal Institute of Technology
Zurich

www.ethz.ch



More information about the R-SIG-Finance mailing list