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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Dec 4 22:02:20 CET 2010


Author: braverock
Date: 2010-12-04 22:02:20 +0100 (Sat, 04 Dec 2010)
New Revision: 483

Modified:
   pkg/FinancialInstrument/R/instrument.R
   pkg/FinancialInstrument/R/load.instruments.R
Log:
- make load.instruments more robust to extra (duplicated) columns
- additional data quality fixes in instrument constructor 

Modified: pkg/FinancialInstrument/R/instrument.R
===================================================================
--- pkg/FinancialInstrument/R/instrument.R	2010-12-03 21:01:27 UTC (rev 482)
+++ pkg/FinancialInstrument/R/instrument.R	2010-12-04 21:02:20 UTC (rev 483)
@@ -87,20 +87,29 @@
   if(!hasArg(identifiers) || is.null(identifiers)) identifiers = list()
   if(!is.list(identifiers)) {
       warning("identifiers",identifiers,"do not appear to be a named list")
-  } else {
-      arg<-list(...)
-      #check for identifiers we recognize 
+  } 
+
+  arg<-list(...)
+  if(is.list(arg[['...']])){
+      if(length(arg)==1) arg <- arg[['...']]
+      else {
+          targ<-arg[['...']]
+          arg[['...']]<-NULL
+          arg<-c(arg,targ)
+      }
+  } 
+  #check for identifiers we recognize 
   ident_str<-c("X.RIC","RIC","CUSIP","SEDOL","OSI","Bloomberg","Reuters","ISIN","CQG","TT","Yahoo","Google")
-      for(i_s in ident_str ){
-          if(any(grepl(i_s,names(arg),ignore.case=TRUE))) {
-              pos<-first(grep(i_s,names(arg),ignore.case=TRUE))
-              identifiers<-c(identifiers,arg[[pos]])
-              names(identifiers)[length(identifiers)]<-names(arg)[pos]
-              arg[[pos]]<-NULL
-          }
+  for(i_s in ident_str ){
+      if(any(grepl(i_s,names(arg),ignore.case=TRUE))) {
+          pos<-first(grep(i_s,names(arg),ignore.case=TRUE))
+          identifiers<-c(identifiers,arg[[pos]])
+          names(identifiers)[length(identifiers)]<-names(arg)[pos]
+          arg[[pos]]<-NULL
       }
   }
   
+  
   ## TODO note that multiplier could be a time series, probably add code here to check
   if(!is.numeric(multiplier) | length(multiplier) > 1) stop("multiplier must be a single number")
   if(!is.numeric(tick_size) | length(tick_size) > 1) stop("tick_size must be a single number")
@@ -114,7 +123,9 @@
                    identifiers = identifiers,
                    type = type
                    )
-  if(length(arg)>=1) tmpinstr <- c(tmpinstr,arg)   
+  if(length(arg)>=1) {
+      tmpinstr <- c(tmpinstr,arg)   
+  }
   class(tmpinstr)<-tclass
   
   if(assign_i)  assign(primary_id, tmpinstr, envir=as.environment(.instrument) )

Modified: pkg/FinancialInstrument/R/load.instruments.R
===================================================================
--- pkg/FinancialInstrument/R/load.instruments.R	2010-12-03 21:01:27 UTC (rev 482)
+++ pkg/FinancialInstrument/R/load.instruments.R	2010-12-04 21:02:20 UTC (rev 483)
@@ -88,6 +88,10 @@
                 arg$primary_id<-filedata[rn,id_col]
             }
             
+            #do some name cleanup to make up for Reuters silliness
+            if(substr(arg$primary_id,1,1)==1) arg$primary_id <- substr(arg$primary_id,2,nchar(arg$primary_id))
+            arg$primary_id<-make.names(arg$primary_id)
+            
             if(is.function(try(match.fun(type)))){
                 out <- try(do.call(type,arg))
             } 



More information about the Blotter-commits mailing list