Thomas Pujol
2007-Sep-27 18:07 UTC
[R] converting numbers in "YYYYMM" format to last calendar day and last exchange trading day of the month
I have a vector that contains month and year in the format YYYYMM (e.g.“200701”,
“200702”)
I wish to do to things:
1. I need to convert to a date that is the last calendar day of each month.
2. I need to convert this to a date that is the last U.S. stock-exchange
trading day of each month.
Any advice is appreciated,
mymonths <- c(200701, 200702)
---------------------------------
[[alternative HTML version deleted]]
Gabor Grothendieck
2007-Sep-28 07:42 UTC
[R] converting numbers in "YYYYMM" format to last calendar day and last exchange trading day of the month
Using as.yearmon and as.Date.yearmon with frac=1 (both from
the zoo package), the last calendar day of the month is:
library(zoo)
d <- c("200701", "200702")
lastday <- as.Date(as.yearmon(d, "%Y%m"), frac = 1)
and the zoo quickref
vignette("zoo-quickref")
has a nextfri function that you can modify to be lastfri. See
the help desk article in R News 4/1 for more on dates and times.
Now make a vector of holidays, h, and for each last friday
decrement it by 1 until its no longer in h.
On 9/27/07, Thomas Pujol <thomas.pujol at yahoo.com>
wrote:> I have a vector that contains month and year in the format YYYYMM
(e.g."200701", "200702")
>
> I wish to do to things:
> 1. I need to convert to a date that is the last calendar day of each
month.
>
> 2. I need to convert this to a date that is the last U.S.
stock-exchange trading day of each month.
> Any advice is appreciated,
> mymonths <- c(200701, 200702)
>
> ---------------------------------
>
> [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>