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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Dec 13 20:24:49 CET 2010


Author: braverock
Date: 2010-12-13 20:24:49 +0100 (Mon, 13 Dec 2010)
New Revision: 493

Modified:
   pkg/FinancialInstrument/NAMESPACE
   pkg/FinancialInstrument/R/load.instruments.R
Log:
- export fund type
- changes to load.instruments to better support new types

Modified: pkg/FinancialInstrument/NAMESPACE
===================================================================
--- pkg/FinancialInstrument/NAMESPACE	2010-12-12 02:19:19 UTC (rev 492)
+++ pkg/FinancialInstrument/NAMESPACE	2010-12-13 19:24:49 UTC (rev 493)
@@ -9,6 +9,7 @@
 export(currency)
 export(is.currency)
 export(exchange_rate)
+export(fund)
 export(bond)
 export(getInstrument)
 export(load.instruments)

Modified: pkg/FinancialInstrument/R/load.instruments.R
===================================================================
--- pkg/FinancialInstrument/R/load.instruments.R	2010-12-12 02:19:19 UTC (rev 492)
+++ pkg/FinancialInstrument/R/load.instruments.R	2010-12-13 19:24:49 UTC (rev 493)
@@ -64,6 +64,7 @@
         warning("metadata does not appear to contain instrument type, using",default_type,". This may produce incorrect valuations.")
         filedata$type<-rep(default_type,nrow(filedata))
     }
+    dotargs<-list('...')
     
     #now process the data
     for(rn in 1:nrow(filedata)){
@@ -97,21 +98,22 @@
             if(!is.null(arg$RIC)){
                 if(substr(arg$RIC,1,1)==1) arg$RIC <- substr(arg$RIC,2,nchar(arg$RIC))
             }            
+            if(length(dotargs)) args<-c(args,dotargs)
             
-            if(is.function(try(match.fun(type)))){
+            if(is.function(try(match.fun(type),silent=TRUE))){
                 out <- try(do.call(type,arg))
-            } 
-			if(inherits(out,"try-error")){
+                #TODO recover gracefully?
+            } else {
                 # the call for a function named for type didn't work, so we'll try calling instrument as a generic
 				type=c(type,"instrument")
 				arg$type<-type # set the type
                 arg$assign_i<-TRUE # assign to the environment
 				try(do.call("instrument",arg))
 			}
-        } else {
+        } else {   
             warning(filedata[rn,id_col],"already exists in the .instrument environment")
-        }
-    } 
+        } # end instrument check
+    } # end loop on rows
 }
 
 #' set quantmod-style SymbolLookup for instruments



More information about the Blotter-commits mailing list