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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Nov 22 19:30:46 CET 2010


Author: braverock
Date: 2010-11-22 19:30:44 +0100 (Mon, 22 Nov 2010)
New Revision: 463

Modified:
   pkg/FinancialInstrument/R/load.instruments.R
Log:
- add handling of spread and guaranteed_spread types in load.instrument fn

Modified: pkg/FinancialInstrument/R/load.instruments.R
===================================================================
--- pkg/FinancialInstrument/R/load.instruments.R	2010-11-22 18:13:26 UTC (rev 462)
+++ pkg/FinancialInstrument/R/load.instruments.R	2010-11-22 18:30:44 UTC (rev 463)
@@ -68,12 +68,29 @@
     #now process the data
     for(rn in 1:nrow(filedata)){
         if(!isTRUE(is.instrument(getInstrument(as.character(filedata[rn,id_col]))))){
-            arg<-as.list(filedata[rn,])
+            type=as.character(filedata[rn,'type'])
+			if(type=='spread' || type=='guaranteed_spread'){
+				if(!is.null(arg$members)){
+					arg$members<-unlist(strsplit(arg$members,','))
+				}
+				if(!is.null(arg$memberratio)){
+					arg$memberratio<-unlist(strsplit(arg$memberratio,','))
+				}
+				if(!is.null(arg$ratio)){
+					arg$memberratio<-unlist(strsplit(arg$ratio,','))
+				}
+			}
+			arg<-as.list(filedata[rn,])
             arg$type<-NULL
             arg<-arg[!is.na(arg)]
             arg<-arg[!arg==""]
             if (set_primary) arg$primary_id<-filedata[rn,id_col]
-            try(do.call(as.character(filedata[rn,'type']),arg))
+            out<-try(do.call(type,arg))
+			if(inherits(out,"try-error")){
+				type=c(type,"instrument")
+				arg$type<-type
+				try(do.call("instrument",args))
+			}
         } else {
             warning(filedata[rn,id_col],"already exists in the .instrument environment")
         }
@@ -116,7 +133,7 @@
                             env,
                             dir="",
                             return.class="xts",
-                            extension="rda",
+                            extension="rda"
                          ) 
 {
     importDefaults("getSymbols.FI")



More information about the Blotter-commits mailing list