[R-SIG-Finance] trouble with timeSequence
Mercurio Danilo 1850 SPI
Danilo.Mercurio at Sparinvest.com
Tue Sep 21 17:55:45 CEST 2010
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" ".
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
More information about the R-SIG-Finance
mailing list