[Blotter-commits] r387 - pkg/quantstrat/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Sep 8 19:47:19 CEST 2010


Author: braverock
Date: 2010-09-08 19:47:19 +0200 (Wed, 08 Sep 2010)
New Revision: 387

Modified:
   pkg/quantstrat/R/signals.R
Log:
- apply patches from Mstislav Elagin (m_elagin), fix bg, ad ==, >=, <= to sigComparison
  - R-Forge patches 1062, 1064 


Modified: pkg/quantstrat/R/signals.R
===================================================================
--- pkg/quantstrat/R/signals.R	2010-09-08 14:41:28 UTC (rev 386)
+++ pkg/quantstrat/R/signals.R	2010-09-08 17:47:19 UTC (rev 387)
@@ -137,7 +137,7 @@
 #' @export
 sigComparison <- function(label,data=mktdata, columns, relationship=c("gt","lt","eq","gte","lte")) {
     relationship=relationship[1] #only use the first one
-    if (length(columns==2)){
+    if (length(columns)==2){
         ret_sig=NULL
         if (relationship=='op'){
             # (How) can this support "Close"? --jmu
@@ -153,20 +153,19 @@
                     ask = {relationship = 'gt'}
             )
         }
+		
         colNums <- match.names(columns,colnames(data))
-        switch(relationship,
-                '>'   =,
-                'gt'  = {ret_sig = data[,colNums[1]] > data[,colNums[2]]},
-                '<'   ,
-                'lt'  = {ret_sig = data[,colNums[1]] < data[,colNums[2]]},
-                'eq'  = {ret_sig = data[,colNums[1]] == data[,colNums[2]]}, #FIXME any way to specify '='?
-                'gte' =,
-                'gteq'=,
-                'ge'  = {ret_sig = data[,colNums[1]] >= data[,colNums[2]]}, #FIXME these fail with an 'unexpected =' error if you use '>=' 
-                'lte' =,
-                'lteq'=,
-                'le'  = {ret_sig = data[,colNums[1]] <= data[,colNums[2]]}
-        )
+		
+		opr <- switch( relationship,
+					 gt = , '>'='>', 
+					 lt =, '<'='<', 
+					 eq =, "=="=, "=" = "==",
+					 gte=, gteq=, ge=, ">=" = ">=",
+					 lte=, lteq=, le=, "<=" = "<="
+					)
+					
+		ret_sig <- do.call( opr, list(data[,colNums[1]], data[,colNums[2]]))
+
     } else {
         stop("comparison of more than two columns not supported yet, patches welcome")
     }



More information about the Blotter-commits mailing list