An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20060322/242defd9/attachment.pl
Date calculations
6 messages · P. Hénaff, Diethelm Wuertz, David Kane +3 more
P. H?naff wrote:
I'm a rank beginner in R and R-metrics, but experienced in matlab and other languages. I'm strugling with date arithmetics in R. I'm doing statistical analysis on financial time series, using its, which uses POSIXct objects to measure time. What is the best way to perform simple date arithmetic with these objects? I do not care about h/m/s, nor do I care about daylight saving time. Example of a problem I faced: Add one day to 3-apr-2005. (daylight saving starts on 4-apr-2005). If I do
as.POSIXct("2005-04-03") + 86400
in Rmetrics use:
myFinCenter = "GMT" # for daily dates
timeDate("2005-04-03")
[1] "GMT"
[1] [2005-04-03]
timeDate("2005-04-03") + 3*24*3600
[1] "GMT"
[1] [2005-04-06]
# Living in Zurich
myFinCenter = "Zurich"
timeDate("2005-04-03")
[1] "Zurich"
[1] [2005-04-03 02:00:00]
timeDate("2005-04-03") + 3*24*3600
[1] "Zurich"
[1] [2005-04-06 02:00:00]
# Use for Daily dates:
timeDate("2005-04-03", zone = "Zurich")
[1] "Zurich"
[1] [2005-04-03]
timeDate("2005-04-03", zone = "Zurich") + 3*24*3600
[1] "Zurich"
[1] [2005-04-06]
I get 1 a.m. on the 4th of april. So, I do something like
dt1 <- as.POSIXct("2005-04-03")
x1 <- timeDate(dt1)
x2 <- timeNdayOnOrAfter(x1, n=2)
dt2 <- as.POSIXct(as.POSIXlt(x2))
There has to be something simpler! Another problem. The tseries and timeDate packages seem to require that one changes his timezone environment variable to GMT. This is not really possible in a corporate environment. Is there a work-around?
It is no longer necessary to specify the timezone. This holds since the latest version 221.10065 (download it from CRAN). For daily dates just be sure that the time zone where you recorded the data (zone=...) and the time zone where you use your data (FinCenter=..) are specified as the same. both GMT, or the financial Center where you are living and your operating system's time zone environment variable is set. (Note, this is not necessarily the same timezone your clock works on your windows box, which doesn't make use of the Windows time zone environment variable TZ). Please let me know if you have further questions (or problems) with timeDate() Diethelm
Any help will be much appreciated. Patrick Henaff [[alternative HTML version deleted]]
_______________________________________________ R-sig-finance at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance
I'm a rank beginner in R and R-metrics, but experienced in matlab and other languages. I'm strugling with date arithmetics in R. I'm doing statistical analysis on financial time series, using its, which uses POSIXct objects to measure time. What is the best way to perform simple date arithmetic with these objects? I do not care about h/m/s, nor do I care about daylight saving time. Example of a problem I faced:
Perhaps date() is what you want. That's what we use for financial applications in which h/m/s does not matter. Dave Kane
On Wed, 22 Mar 2006 00:38:20 -0600 P. H?naff wrote:
I'm a rank beginner in R and R-metrics, but experienced in matlab and other languages. I'm strugling with date arithmetics in R. I'm doing statistical analysis on financial time series, using its, which uses POSIXct objects to measure time. What is the best way to perform simple date arithmetic with these objects? I do not care about h/m/s, nor do I care about daylight saving time.
In that case I would recommend to go with the "Date" class available in
base R, e.g.
as.Date("2005-04-03") + 0:10
which should be rather self-explanatory.
The package zoo provides time series infrastructure where the time
information can be stored in "Date" (or virtually any other class).
library("zoo")
z <- zoo(rnorm(11), as.Date("2005-04-03") + 0:10)
plot(z)
hth,
Z
An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20060322/5ee189c2/attachment.pl
If you use the date or survival libraries, you can do something like:
as.date("01/10/2001", "mdy"), as well as as.date(14985) -- a julian
argument. You can also go back and forth between julians and numeric vectors
with mdy.date and date.mdy.
Steve Miller
-----Original Message-----
From: r-sig-finance-bounces at stat.math.ethz.ch
[mailto:r-sig-finance-bounces at stat.math.ethz.ch] On Behalf Of Mahesh
Krishnan
Sent: Wednesday, March 22, 2006 10:31 AM
To: r-sig-finance at stat.math.ethz.ch
Subject: Re: [R-sig-finance] Date calculations
Henaff,
I have found the following to be of use when using Date manipulations.
Example:
tDate <- as.Date("03/22/2006", "%m/%d/%Y") ;
tDate +1 ## will give the update 03/23/2006 and so on..
Best regards,
Mahesh.
ps: fyi: the capital Y in as.Date refers to a 4 digit year representation
On 3/21/06, P. Hinaff <patrick.henaff at kermatheano.com> wrote:
I'm a rank beginner in R and R-metrics, but experienced in matlab and other languages. I'm strugling with date arithmetics in R. I'm doing statistical analysis on financial time series, using its, which uses
POSIXct
objects to measure time. What is the best way to perform simple date arithmetic with these objects? I do not care about h/m/s, nor do I care about daylight saving time. Example of a problem I faced: Add one day to 3-apr-2005. (daylight saving starts on 4-apr-2005). If I do
as.POSIXct("2005-04-03") + 86400
I get 1 a.m. on the 4th of april. So, I do something like
dt1 <- as.POSIXct("2005-04-03")
x1 <- timeDate(dt1)
x2 <- timeNdayOnOrAfter(x1, n=2)
dt2 <- as.POSIXct(as.POSIXlt(x2))
There has to be something simpler!
Another problem. The tseries and timeDate packages seem to require that
one changes his timezone environment variable to GMT. This is not really
possible in a corporate environment. Is there a work-around?
Any help will be much appreciated.
Patrick Henaff
[[alternative HTML version deleted]]
_______________________________________________ R-sig-finance at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance