[Blotter-commits] r863 - pkg/FinancialInstrument/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Dec 7 15:46:52 CET 2011


Author: gsee
Date: 2011-12-07 15:46:51 +0100 (Wed, 07 Dec 2011)
New Revision: 863

Modified:
   pkg/FinancialInstrument/R/parse_id.R
   pkg/FinancialInstrument/R/synthetic.R
Log:
parse_id: support guaranteeed_spreads that have no underscore

Modified: pkg/FinancialInstrument/R/parse_id.R
===================================================================
--- pkg/FinancialInstrument/R/parse_id.R	2011-12-06 00:25:06 UTC (rev 862)
+++ pkg/FinancialInstrument/R/parse_id.R	2011-12-07 14:46:51 UTC (rev 863)
@@ -72,7 +72,7 @@
         }
     } else if (identical(x, gsub('_','',x))) { #no underscore; have to guess what is root and what is suffix       
         hasdot <- !identical(integer(0),grep("\\.",x))        
-        if (!silent) 
+        if (!silent && !hasdot) 
             warning("id of future_series should have an underscore in it. Trying to parse anyway.")
         if (nchar(x) < 9 && !hasdot) { #assume it's a future like ESU1 or ESU11
             if (suppressWarnings(!is.null(parse_suffix(substr(x,3,nchar(x)))) && 
@@ -95,9 +95,20 @@
                 suffix <- substr(x,5,nchar(x))
             }
         } else {
-            root <- gsub("[0-9.-]","",x) #now it looks like SPYC or TP
-            root <- substr(root, 1,nchar(root)-1)
-            suffix <- gsub(root,"",x) #whatever isn't the root         
+            # Look for spread (e.g. CLF2.F3). Split by the dot, then try to extract suffix_id from the part before
+            # the dot. If that suffix is the same length as the part after the dot, we'll assume it's a spread
+            # (it could also be a fly or condor, but only the first 2 parts are checked)
+            #x <- "CLF2.G2"
+            pidhalf <- parse_id(strsplit(x, "\\.")[[1]][1]) #parse_id on part before dot (looking for spread)
+            if (nchar(pidhalf$suffix) == nchar(strsplit(x, "\\.")[[1]][2])) {
+                root <- pidhalf$root
+                suffix <- gsub(root, "", x)
+            } else {
+                #x <- "DIA111230P139.75"
+                root <- gsub("[0-9.-]","",x) #now it looks like DIAP, SPYC or TP
+                root <- substr(root, 1,nchar(root)-1)
+                suffix <- gsub(root,"",x) #whatever isn't the root
+            }
         }
     } else { #there _is_ an underscore and at least 1 number.     
         #if there are dots then maybe it is a spread of futures?

Modified: pkg/FinancialInstrument/R/synthetic.R
===================================================================
--- pkg/FinancialInstrument/R/synthetic.R	2011-12-06 00:25:06 UTC (rev 862)
+++ pkg/FinancialInstrument/R/synthetic.R	2011-12-07 14:46:51 UTC (rev 863)
@@ -204,8 +204,8 @@
     multiplier = NULL, identifiers = NULL, tick_size=NULL)
 {
 
-	if (hasArg(suffix_id)) {
-		if(hasArg(root_id)) {
+	if (!is.null(suffix_id)) {
+		if(!is.null(root_id)) {
 			id<- paste(root_id,suffix_id,sep="_")
 		} else {
 			id <- paste(primary_id, suffix_id, sep = "_")



More information about the Blotter-commits mailing list