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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Dec 22 20:50:13 CET 2011


Author: gsee
Date: 2011-12-22 20:50:12 +0100 (Thu, 22 Dec 2011)
New Revision: 886

Modified:
   pkg/FinancialInstrument/DESCRIPTION
   pkg/FinancialInstrument/R/format_id.R
   pkg/FinancialInstrument/man/month_cycle2numeric.Rd
Log:
 MC2N is more flexible. See updated examples

Modified: pkg/FinancialInstrument/DESCRIPTION
===================================================================
--- pkg/FinancialInstrument/DESCRIPTION	2011-12-22 17:55:21 UTC (rev 885)
+++ pkg/FinancialInstrument/DESCRIPTION	2011-12-22 19:50:12 UTC (rev 886)
@@ -11,7 +11,7 @@
     meta-data and relationships. Provides support for
     multi-asset class and multi-currency portfolios. Still
     in heavy development.
-Version: 0.9.15
+Version: 0.9.16
 URL: https://r-forge.r-project.org/projects/blotter/
 Date: $Date$
 Depends:

Modified: pkg/FinancialInstrument/R/format_id.R
===================================================================
--- pkg/FinancialInstrument/R/format_id.R	2011-12-22 17:55:21 UTC (rev 885)
+++ pkg/FinancialInstrument/R/format_id.R	2011-12-22 19:50:12 UTC (rev 886)
@@ -72,25 +72,34 @@
 #'
 #' This will convert month codes or month names to numeric months.
 #'
-#' Input can be a vector or a comma-delimited string. All elements of \code{month_cycle} should be similar.
+#' Input can be a vector, comma-delimited string, or multiple strings. 
+#' All inputs should be similar.
 #' Do not mix month names, codes and numbers in the same call.
+#'
+#' \code{MC2N} is an alias
 #' @return numeric vector
-#' @param month_cycle the expiration months of a \code{\link{future}}. See examples.
+#' @param ... the expiration months of a \code{\link{future}}. See examples.
 #' @author Garrett See
 #' @seealso \code{\link{M2C}}, \code{\link{C2M}}, \code{\link{next.future_id}}
 #' \code{\link{future}}
 #' @examples
-#' month_cycle2numeric("H,M,U,Z")
-#' month_cycle2numeric(c("H","M","U","Z"))
-#' month_cycle2numeric("Mar,jun,SEP,dEc")
-#' month_cycle2numeric("March,june,sep,decem")
+#' MC2N("H,M,U,Z") # from single string
+#' MC2N(c("H","M","U","Z")) # from single vector
+#' MC2N("h", "M", "u", "Z") # from multiple strings
+#' MC2N(c("F","G"), "H", c("X","Z")) # from multiple vectors
+#' month_cycle2numeric("Mar,jun,SEP,dEc") 
+#' month_cycle2numeric("Mar", "jun", "SEP", "dEc")
+#' MC2N("March,june,sep,decem")
+#' MC2N("March, june, sep, decem") #spaces between commas are ok
 #' month_cycle2numeric("3,6,9,12")
 #' month_cycle2numeric(seq(3,12,3))
 #' @rdname month_cycle2numeric
 #' @export
-month_cycle2numeric <- function(month_cycle) {
+month_cycle2numeric <- function(...) {
+    month_cycle <- unlist(list(...))
     if (is.character(month_cycle)) {
         cycle.chr <- toupper(strsplit(paste(month_cycle, collapse=","), ",")[[1]])
+        cycle.chr <- gsub(" ", "", cycle.chr)
         if (!any(suppressWarnings(is.na(as.numeric(cycle.chr))))) {
             month_cycle <- as.numeric(cycle.chr)
         } else {

Modified: pkg/FinancialInstrument/man/month_cycle2numeric.Rd
===================================================================
--- pkg/FinancialInstrument/man/month_cycle2numeric.Rd	2011-12-22 17:55:21 UTC (rev 885)
+++ pkg/FinancialInstrument/man/month_cycle2numeric.Rd	2011-12-22 19:50:12 UTC (rev 886)
@@ -3,12 +3,12 @@
 \alias{month_cycle2numeric}
 \title{coerce month_cycle to a numeric vector}
 \usage{
-  month_cycle2numeric(month_cycle)
+  month_cycle2numeric(...)
 
-  MC2N(month_cycle)
+  MC2N(...)
 }
 \arguments{
-  \item{month_cycle}{the expiration months of a
+  \item{...}{the expiration months of a
   \code{\link{future}}. See examples.}
 }
 \value{
@@ -19,15 +19,21 @@
   months.
 }
 \details{
-  Input can be a vector or a comma-delimited string. All
-  elements of \code{month_cycle} should be similar. Do not
+  Input can be a vector, comma-delimited string, or
+  multiple strings. All inputs should be similar. Do not
   mix month names, codes and numbers in the same call.
+
+  \code{MC2N} is an alias
 }
 \examples{
-month_cycle2numeric("H,M,U,Z")
-month_cycle2numeric(c("H","M","U","Z"))
+MC2N("H,M,U,Z") # from single string
+MC2N(c("H","M","U","Z")) # from single vector
+MC2N("h", "M", "u", "Z") # from multiple strings
+MC2N(c("F","G"), "H", c("X","Z")) # from multiple vectors
 month_cycle2numeric("Mar,jun,SEP,dEc")
-month_cycle2numeric("March,june,sep,decem")
+month_cycle2numeric("Mar", "jun", "SEP", "dEc")
+MC2N("March,june,sep,decem")
+MC2N("March, june, sep, decem") #spaces between commas are ok
 month_cycle2numeric("3,6,9,12")
 month_cycle2numeric(seq(3,12,3))
 }



More information about the Blotter-commits mailing list