[Blotter-commits] r420 - in pkg/quantstrat: R demo

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Oct 12 19:33:09 CEST 2010


Author: braverock
Date: 2010-10-12 19:33:09 +0200 (Tue, 12 Oct 2010)
New Revision: 420

Modified:
   pkg/quantstrat/R/orders.R
   pkg/quantstrat/demo/macd.R
Log:
- explicitly pass tmult as argument to ruleSignal
- change macd demo to demonstrate stoplimit order at threshold multiplier

Modified: pkg/quantstrat/R/orders.R
===================================================================
--- pkg/quantstrat/R/orders.R	2010-10-12 15:56:29 UTC (rev 419)
+++ pkg/quantstrat/R/orders.R	2010-10-12 17:33:09 UTC (rev 420)
@@ -372,14 +372,13 @@
                 # next process daily
                 for (ii in procorders ){
                     txnprice=NULL
-					#txntime=as.character(index(ordersubset[ii,])) #wrong if order time and txn time are different
-					txntime=as.character(timestamp)
 					txnfees=ordersubset[ii, ]$Txn.Fees
 					if(is.null(txnfees)) txnfees=0
                     switch(ordersubset[ii,]$Order.Type,
                         market = {
-                                txnprice=as.numeric(getPrice(last(mktdata[timestamp]), prefer='close'))
-                                #if(!is.null(ncol(txnprice)) & ncol(txnprice)>1) txnprice = as.numeric(getPrice(mktdata[timestamp], symbol=symbol, prefer='close'))
+								txntime=as.character(index(ordersubset[ii,])) # transacts on this bar, e.g. in the intraday cross, or leading into the end of month, quarter, etc.
+								# txntime=as.character(timestamp) # use this if you wanted to transact on the close of the next bar
+								txnprice=as.numeric(getPrice(last(mktdata[txntime]), prefer='close'))
                         },
                         limit = ,
 						stoplimit = {
@@ -409,14 +408,12 @@
                 # now do higher frequencies
 				neworders<-NULL
                 for (ii in procorders ){
-                    #browser()
                     txnprice=NULL
                     txnfees=ordersubset[ii, ]$Txn.Fees
                     switch(ordersubset[ii,]$Order.Type,
                             market = {
                                 txnprice = as.numeric(getPrice(mktdata[timestamp]))
                                 #TODO extend this to figure out which side to prefer
-                                #if(!is.null(ncol(txnprice)) & ncol(txnprice)>1) txnprice = as.numeric(getPrice(mktdata[timestamp], symbol=symbol))
                                 txntime  = as.character(timestamp)
                             },
                             limit= ,

Modified: pkg/quantstrat/demo/macd.R
===================================================================
--- pkg/quantstrat/demo/macd.R	2010-10-12 15:56:29 UTC (rev 419)
+++ pkg/quantstrat/demo/macd.R	2010-10-12 17:33:09 UTC (rev 420)
@@ -44,7 +44,7 @@
 stratMACD <- add.signal(strategy = stratMACD,name="sigThreshold",arguments = list(column="signal",relationship="lt",threshold=0,cross=TRUE),label="signal.lt.zero")
 
 stratMACD <- add.rule(strategy = stratMACD,name='ruleSignal', arguments = list(sigcol="signal.gt.zero",sigval=TRUE, orderqty=100, ordertype='market', orderside='long', threshold=NULL),type='enter')
-stratMACD <- add.rule(strategy = stratMACD,name='ruleSignal', arguments = list(sigcol="signal.gt.zero",sigval=TRUE, orderqty=-100, ordertype='stoplimit', orderside='long', threshold=.95,tmult=TRUE),type='risk')
+stratMACD <- add.rule(strategy = stratMACD,name='ruleSignal', arguments = list(sigcol="signal.gt.zero",sigval=TRUE, orderqty=-100, ordertype='stoplimit', orderside='long', threshold=.85,tmult=TRUE),type='risk')
 stratMACD <- add.rule(strategy = stratMACD,name='ruleSignal', arguments = list(sigcol="signal.lt.zero",sigval=TRUE, orderqty='all', ordertype='market', orderside='long', threshold=NULL),type='exit')
 
 getSymbols(stock.str,from=initDate)



More information about the Blotter-commits mailing list