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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Oct 27 23:08:50 CEST 2010


Author: llevenson
Date: 2010-10-27 23:08:50 +0200 (Wed, 27 Oct 2010)
New Revision: 432

Modified:
   pkg/quantstrat/R/orders.R
   pkg/quantstrat/R/rules.R
   pkg/quantstrat/R/strategy.R
Log:
- commented out timespan line since it is not being used yet (orders.R)
- added "pre" and "post" types (rules.R)
- added a check for path.dep to only run applyRules when needed (strategy.R)

Modified: pkg/quantstrat/R/orders.R
===================================================================
--- pkg/quantstrat/R/orders.R	2010-10-25 14:40:35 UTC (rev 431)
+++ pkg/quantstrat/R/orders.R	2010-10-27 21:08:50 UTC (rev 432)
@@ -71,7 +71,7 @@
 #' @export
 getOrders <- function(portfolio,symbol,status="open",timespan=NULL,ordertype=NULL, side=NULL, which.i=FALSE)
 {
-    if(is.null(timespan)) stop("timespan must be an xts style timestring")
+    #if(is.null(timespan)) stop("timespan must be an xts style timestring")
     # get order book
     orderbook <- getOrderBook(portfolio)
     if(!length(grep(symbol,names(orderbook[[portfolio]])))==1) stop(paste("symbol",symbol,"does not exist in portfolio",portfolio,"having symbols",names(orderbook)))

Modified: pkg/quantstrat/R/rules.R
===================================================================
--- pkg/quantstrat/R/rules.R	2010-10-25 14:40:35 UTC (rev 431)
+++ pkg/quantstrat/R/rules.R	2010-10-27 21:08:50 UTC (rev 432)
@@ -65,7 +65,7 @@
     if(!is.strategy(strategy)) stop("You must pass in a strategy object to manipulate")
     type=type[1]
     if(is.null(type)) stop("You must specify a type")
-	if(is.na(charmatch(type,c("risk","order","rebalance","exit","enter")))) stop(paste("type:",type,' must be one of "risk", "order", "rebalance", "exit", or "enter"'))
+	if(is.na(charmatch(type,c("risk","order","rebalance","exit","enter","pre","post")))) stop(paste("type:",type,' must be one of "risk", "order", "rebalance", "exit", "enter", "pre", or "post"'))
     tmp_rule<-list()
     if(!is.function(name)) {
         if(!is.function(get(name))){

Modified: pkg/quantstrat/R/strategy.R
===================================================================
--- pkg/quantstrat/R/strategy.R	2010-10-25 14:40:35 UTC (rev 431)
+++ pkg/quantstrat/R/strategy.R	2010-10-27 21:08:50 UTC (rev 432)
@@ -110,10 +110,19 @@
             }
             
             #loop over rules  
-            # non-path-dep first
             sret$rules<-list()
+			
+			## only fire nonpath/pathdep when true 
+			## TODO make this more elegant
+			pd <- FALSE
+			for(i in 1:length(strategy$rules)){	if(length(strategy$rules[[i]])!=0){z <- strategy$rules[[i]]; if(z[[1]]$path.dep==TRUE){pd <- TRUE}}}
+				
             sret$rules$nonpath<-applyRules(portfolio=portfolio, symbol=symbol, strategy=strategy, mktdata=mktdata, Dates=NULL, indicators=sret$indicators, signals=sret$signals, parameters=parameters,  ..., path.dep=FALSE)
-            sret$rules$pathdep<-applyRules(portfolio=portfolio, symbol=symbol, strategy=strategy, mktdata=mktdata, Dates=NULL, indicators=sret$indicators, signals=sret$signals, parameters=parameters,  ..., path.dep=TRUE)
+			
+			## Check for open orders
+			rem.orders <- getOrders(portfolio=portfolio, symbol=symbol, status="open") #, timespan=timespan, ordertype=ordertype,which.i=TRUE)
+			if(nrow(rem.orders)>0){pd <- TRUE}
+            if(pd==TRUE){sret$rules$pathdep<-applyRules(portfolio=portfolio, symbol=symbol, strategy=strategy, mktdata=mktdata, Dates=NULL, indicators=sret$indicators, signals=sret$signals, parameters=parameters,  ..., path.dep=TRUE)}
 
 			ret[[portfolio]][[symbol]]<-sret
 		}



More information about the Blotter-commits mailing list