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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri May 4 22:03:53 CEST 2012


Author: braverock
Date: 2012-05-04 22:03:53 +0200 (Fri, 04 May 2012)
New Revision: 1015

Modified:
   pkg/quantstrat/R/ruleSignal.R
   pkg/quantstrat/R/rules.R
Log:
- add patch from Jan Humme to fix some broken exit rule order entry logic

Modified: pkg/quantstrat/R/ruleSignal.R
===================================================================
--- pkg/quantstrat/R/ruleSignal.R	2012-05-04 19:56:52 UTC (rev 1014)
+++ pkg/quantstrat/R/ruleSignal.R	2012-05-04 20:03:53 UTC (rev 1015)
@@ -143,15 +143,11 @@
         
         ## now size the order
         #TODO add fancy formals matching for osFUN
-        if(!(ruletype=='risk') && (orderqty=='all')){
-            # Joe Dunn suggested if((ruletype != 'risk') && (orderqty !='all'))
-            # but that didn't work either.  needs more investigation
-            
+        if(orderqty=='all' && (ordertype=='market' || (ruletype!='risk' && ruletype!='exit')))
+	{
             orderqty <- osFUN(strategy=strategy, data=data, timestamp=timestamp, orderqty=orderqty, ordertype=ordertype, orderside=orderside, portfolio=portfolio, symbol=symbol,...=...,ruletype=ruletype, orderprice=as.numeric(orderprice))
-            
         }
         
-        
         if(!is.null(orderqty) && !orderqty == 0 && !is.null(orderprice)){ #orderqty could have length > 1
             addOrder(portfolio=portfolio, symbol=symbol, timestamp=timestamp, qty=orderqty, price=as.numeric(orderprice), ordertype=ordertype, side=orderside, orderset=orderset, threshold=threshold, status="open", replace=replace , delay=delay, tmult=tmult, ...=..., TxnFees=TxnFees,label=label)
         }

Modified: pkg/quantstrat/R/rules.R
===================================================================
--- pkg/quantstrat/R/rules.R	2012-05-04 19:56:52 UTC (rev 1014)
+++ pkg/quantstrat/R/rules.R	2012-05-04 20:03:53 UTC (rev 1015)
@@ -639,13 +639,13 @@
                     },
                     rebalance =, exit = , enter = , entry = {
                         if(isTRUE(hold)) next()
-                        if(type=='exit'){
-                            if(length(strategy$rules$exit)==length(grep('market',strategy$rules$exit))){
-                                # all exit orders are of type 'market'
-                                # so we must have a position for exit rules to fire / be evaluated
-                                if (getPosQty(Portfolio=portfolio,Symbol=symbol,Date=timestamp)==0) next()
-                            }
-                        }
+#                        if(type=='exit'){
+#                            if(length(strategy$rules$exit)==length(grep('market',strategy$rules$exit))){
+#                                # all exit orders are of type 'market'
+#                                # so we must have a position for exit rules to fire / be evaluated
+#                                if (getPosQty(Portfolio=portfolio,Symbol=symbol,Date=timestamp)==0) next()
+#                            }
+#                        }
                         if(length(strategy$rules[[type]])>=1) {
                             ruleProc(strategy$rules[[type]],timestamp=timestamp, path.dep=path.dep, mktdata=mktdata,portfolio=portfolio, symbol=symbol, ruletype=type, mktinstr=mktinstr, ...)
                         }



More information about the Blotter-commits mailing list