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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Dec 9 14:45:19 CET 2010


Author: braverock
Date: 2010-12-09 14:45:19 +0100 (Thu, 09 Dec 2010)
New Revision: 485

Modified:
   pkg/FinancialInstrument/R/load.instruments.R
   pkg/FinancialInstrument/R/synthetic.R
Log:
- add handling for guaranteed_spread type as a special class of synthetic instrument
- use named argument passing in all synthetic instrument constructors to fix subtle order of arguments bug

Modified: pkg/FinancialInstrument/R/load.instruments.R
===================================================================
--- pkg/FinancialInstrument/R/load.instruments.R	2010-12-04 21:25:49 UTC (rev 484)
+++ pkg/FinancialInstrument/R/load.instruments.R	2010-12-09 13:45:19 UTC (rev 485)
@@ -69,7 +69,8 @@
     for(rn in 1:nrow(filedata)){
         if(!isTRUE(is.instrument(getInstrument(as.character(filedata[rn,id_col]))))){
             type=as.character(filedata[rn,'type'])
-			if(type=='spread' || type=='guaranteed_spread'){
+            arg<-as.list(filedata[rn,])
+            if(type=='spread' || type=='guaranteed_spread'){
 				if(!is.null(arg$members)){
 					arg$members<-unlist(strsplit(arg$members,','))
 				}
@@ -80,7 +81,6 @@
 					arg$memberratio<-unlist(strsplit(arg$ratio,','))
 				}
 			}
-			arg<-as.list(filedata[rn,])
             arg$type<-NULL
             arg<-arg[!is.na(arg)]
             arg<-arg[!arg==""]

Modified: pkg/FinancialInstrument/R/synthetic.R
===================================================================
--- pkg/FinancialInstrument/R/synthetic.R	2010-12-04 21:25:49 UTC (rev 484)
+++ pkg/FinancialInstrument/R/synthetic.R	2010-12-09 13:45:19 UTC (rev 485)
@@ -14,7 +14,7 @@
 #' @export
 synthetic <- function(primary_id , currency , multiplier=1, identifiers = NULL, ..., members=NULL, type=c("synthetic", "instrument"))
 {
-    synthetic_temp = instrument(primary_id , currency , multiplier , identifiers = identifiers, ..., type=type, members=members, assign_i=TRUE )    
+    synthetic_temp = instrument(primary_id=primary_id , currency=currency , multiplier=multiplier , identifiers = identifiers, ...=..., type=type, members=members, assign_i=TRUE )    
 }
 
 #' constructors for synthetic instruments
@@ -44,7 +44,7 @@
 #' synthetic.ratio
 #' guaranteed_spread
 #' @export
-synthetic.ratio <- function(primary_id , currency , multiplier=1, identifiers = NULL, ..., type=c("synthetic.ratio","synthetic","instrument"), members, memberratio)
+synthetic.ratio <- function(primary_id , currency ,  members, memberratio, ..., multiplier=1, identifiers = NULL, type=c("synthetic.ratio","synthetic","instrument"))
 {
     #TODO make sure that with options/futures or other  instruments that we have you use the base contract
     if(!is.list(members)){
@@ -71,17 +71,28 @@
         warning("passing in members as a list not fully tested")
         memberlist=members
     }
-    synthetic_temp = synthetic(primary_id , currency , multiplier=multiplier , identifiers = identifiers, members=memberlist , memberratio=memberratio, ... ,type=type, assign_i=TRUE )
+    synthetic(primary_id=primary_id , currency=currency , multiplier=multiplier , identifiers = identifiers, members=memberlist , memberratio=memberratio, ...=... ,type=type)
 }
 
 #' @export
-spread <- function(primary_id , currency , members, memberratio, ..., multiplier=1, identifiers = NULL)
+spread <- function(primary_id , currency , members=NULL, memberratio, ..., multiplier=1, identifiers = NULL)
 {
-    synthetic.ratio(primary_id , currency , multiplier=multiplier, identifiers = NULL, type=c("spread","synthetic.ratio","synthetic","instrument"), members=members, memberratio=memberratio, ...=..., assign_i=TRUE)
+    synthetic.ratio(primary_id , currency , members=members, memberratio=memberratio, multiplier=multiplier, identifiers = identifiers, ...=..., type=c("spread","synthetic.ratio","synthetic","instrument"))
 }
 
 #' @export
-guaranteed_spread <- function(primary_id , currency , members, memberratio=c(1,1), ..., multiplier=1, identifiers = NULL)
+guaranteed_spread <- function(primary_id , currency , members=NULL, memberratio=c(1,1), ..., multiplier=1, identifiers = NULL)
 {
-	synthetic.ratio(primary_id , currency , multiplier=multiplier, identifiers = NULL, type=c("guaranteed_spread","spread","synthetic.ratio","synthetic","instrument"), members=members, memberratio=memberratio, ...=..., assign_i=TRUE)
+    if (hasArg(suffix_id)){
+        suffix_id<-match.call(expand.dots=TRUE)$suffix_id  
+        id<-paste(primary_id, suffix_id,sep="_")
+    } else id<-primary_id 
+
+    
+    if(is.null(members) && hasArg(suffix_id)){
+        #make.names uses a dot to replace illegal chars like the '-', 
+        members<-unlist(strsplit(suffix_id,"[-;:_,\\.]")) # clean up the list to something we can use  
+        members<-paste(primary_id,members,sep='_') # construct a member vector appropriate for a guaranteed spread
+    }
+    synthetic.ratio(primary_id=id , currency=currency , members=members, memberratio=memberratio, multiplier=multiplier, identifiers = NULL, ...=..., type=c("guaranteed_spread","spread","synthetic.ratio","synthetic","instrument"))
 }



More information about the Blotter-commits mailing list