[Blotter-commits] r1274 - in pkg/FinancialInstrument: . R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Dec 5 19:08:46 CET 2012


Author: gsee
Date: 2012-12-05 19:08:45 +0100 (Wed, 05 Dec 2012)
New Revision: 1274

Modified:
   pkg/FinancialInstrument/DESCRIPTION
   pkg/FinancialInstrument/NEWS
   pkg/FinancialInstrument/R/format_id.R
Log:
 sort_id() recognizes partial dates in "expires" attribute

Modified: pkg/FinancialInstrument/DESCRIPTION
===================================================================
--- pkg/FinancialInstrument/DESCRIPTION	2012-12-04 18:48:35 UTC (rev 1273)
+++ pkg/FinancialInstrument/DESCRIPTION	2012-12-05 18:08:45 UTC (rev 1274)
@@ -9,7 +9,7 @@
     Ulrich, Brian G. Peterson, Garrett See
 Description: Infrastructure for defining meta-data and
     relationships for financial instruments.
-Version: 1.0.3
+Version: 1.0.4
 URL: https://r-forge.r-project.org/projects/blotter/
 Date: $Date$
 Depends:

Modified: pkg/FinancialInstrument/NEWS
===================================================================
--- pkg/FinancialInstrument/NEWS	2012-12-04 18:48:35 UTC (rev 1273)
+++ pkg/FinancialInstrument/NEWS	2012-12-05 18:08:45 UTC (rev 1274)
@@ -9,6 +9,10 @@
 * CompareInstrumentFiles() allows passing it only 1 argument in which case it
   will compare the currently loaded instrument environment against it.
 
+* If an instrument has a string like "2012-09", "2012/09", or "201209" in the
+  "expires" attribute, sort_id() will treat that instrument as expiring on the
+  first day of that month (2012-09-01).  Thanks to Jan Humme for reporting.
+
 BUG FIXES
 ---------
 

Modified: pkg/FinancialInstrument/R/format_id.R
===================================================================
--- pkg/FinancialInstrument/R/format_id.R	2012-12-04 18:48:35 UTC (rev 1273)
+++ pkg/FinancialInstrument/R/format_id.R	2012-12-05 18:08:45 UTC (rev 1274)
@@ -265,6 +265,14 @@
                                   "Only the first will be used."))
                     tmpexp <- tmpexp[[1L]]
                 }
+                # if there's a partial date in the "expires" attribute that indicates
+                # year and month, use the first day of that month as the expiration date
+                # Could use the expires() generic, but parsing it here seems safer.
+                if (nchar(tmpexp) == 6 && grepl("^[0-9]+$", tmpexp)) { #201209
+                    tmpexp <- paste(substr(tmpexp, 1, 4), substr(tmpexp, 5, 6), "01", sep="-")
+                } else if (grepl("^[0-9]{4}-|/[0-9]{2}$", tmpexp)) { #2012-09 or 2012/09
+                    tmpexp <- paste(substr(tmpexp, 1, 4), substr(tmpexp, 6, 7), "01", sep="-")
+                }
                 dtmpexp <- suppressWarnings(try(as.Date(tmpexp), silent=TRUE))
                 if (inherits(dtmpexp, "try-error") || is.na(dtmpexp) || !is.timeBased(dtmpexp)) {
                     dtmpexp <- suppressWarnings(try(as.Date(tmpexp, format='%Y%m%d'), silent=TRUE))



More information about the Blotter-commits mailing list