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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Nov 11 22:12:12 CET 2011


Author: bodanker
Date: 2011-11-11 22:12:12 +0100 (Fri, 11 Nov 2011)
New Revision: 847

Modified:
   pkg/quantstrat/R/rules.R
Log:
- fix applyRules and ruleProc to honor timespan


Modified: pkg/quantstrat/R/rules.R
===================================================================
--- pkg/quantstrat/R/rules.R	2011-11-11 17:22:13 UTC (rev 846)
+++ pkg/quantstrat/R/rules.R	2011-11-11 21:12:12 UTC (rev 847)
@@ -249,9 +249,9 @@
             
             if(!isTRUE(rule$enabled)) next()
             
-			# check to see if we should run in this timespan
-			if(!is.null(rule$timespan) & nrow(mktdata[rule$timespan]==0)) next()
-			
+            # check to see if we should run in this timespan
+            if(!is.null(rule$timespan) && nrow(mktdata[rule$timespan][timestamp]==0)) next()
+
             # see 'S Programming' p. 67 for this matching
             if(is.function(rule$name)) fun <- rule$name
             else fun<-match.fun(rule$name)
@@ -315,7 +315,11 @@
                         if(is.null(rule$arguments$sigcol) | is.null(rule$arguments$sigval) ){
                             assign.dindex(1:length(Dates))
                         } else {
-                            assign.dindex(c(get.dindex(),which(mktdata[,rule$arguments$sigcol] == rule$arguments$sigval)))   
+                            if(is.null(rule$timespan)) {
+                                assign.dindex(c(get.dindex(),which(mktdata[,rule$arguments$sigcol] == rule$arguments$sigval)))
+                            } else {
+                                assign.dindex(c(get.dindex(),which(merge(.xts(,.index(mktdata)),mktdata[rule$timespan,rule$arguments$sigcol]) == rule$arguments$sigval)))
+                            }
                         }
                     }
                 }



More information about the Blotter-commits mailing list